Repository: jina-ai/jina
File: tests/unit/test_cli.py (Python)

Code before:
    with open(tmpdir / 'test.yml', 'w', encoding='utf8') as fp:
        JAML.dump(api_to_dict(), fp)
    with open(tmpdir / 'test.json', 'w', encoding='utf8') as fp:
        json.dump(api_to_dict(), fp)


@pytest.mark.parametrize('cli', ac_table['commands'])
def test_help_lookup(cli, capsys):
    nkw2kw, kw2info = _build_lookup_table()
    if cli not in {'--help', '--version', '--version-full'}:
        assert cli in nkw2kw
        lookup_and_print(cli)
        captured = capsys.readouterr()
        assert 'Traceback (most recent call last)' not in captured.out


def test_main_cli():
    subprocess.check_call(['jina'])


def test_cli_help():
    subprocess.check_call(['jina', 'help', 'deployment'])


@pytest.mark.parametrize(
    'uses', ['jinahub://DummyHubExecutor', 'jinaai://jina-ai/DummyHubExecutor']
)
def test_cli_hub(uses):
    subprocess.check_call(['jina', 'hub', '--help'])
    for cmd in ['new', 'status', 'pull', 'push']:
        subprocess.check_call(['jina', 'hub', cmd, '--help'])
    subprocess.check_call(['jina', 'hub', 'pull', uses])


def test_cli_warn_unknown_args():
    subprocess.check_call(['jina', 'help', 'deployment', '--abcdefg'])


@pytest.mark.parametrize('cli', ac_table['commands'])
def test_all_cli(cli):
    subprocess.check_call(['jina', cli, '--help'])


@pytest.mark.parametrize('smethod', ['fork', 'spawn'])
def test_all_start_method(smethod):
    s = subprocess.check_output(
        ['jina', '-v'],
        env=dict(os.environ, JINA_MP_START_METHOD=smethod),
        stderr=subprocess.STDOUT,
    )
    assert 'UserWarning' in s.decode()

Review comment (suggestion):
```suggestion
    'uses', ['jinaai://jina-ai/DummyHubExecutor']
```

Code after:
    with open(tmpdir / 'test.yml', 'w', encoding='utf8') as fp:
        JAML.dump(api_to_dict(), fp)
    with open(tmpdir / 'test.json', 'w', encoding='utf8') as fp:
        json.dump(api_to_dict(), fp)


@pytest.mark.parametrize('cli', ac_table['commands'])
def test_help_lookup(cli, capsys):
    nkw2kw, kw2info = _build_lookup_table()
    if cli not in {'--help', '--version', '--version-full'}:
        assert cli in nkw2kw
        lookup_and_print(cli)
        captured = capsys.readouterr()
        assert 'Traceback (most recent call last)' not in captured.out


def test_main_cli():
    subprocess.check_call(['jina'])


def test_cli_help():
    subprocess.check_call(['jina', 'help', 'deployment'])


@pytest.mark.parametrize(
    'uses', ['jinaai://jina-ai/DummyHubExecutor']
)
def test_cli_hub(uses):
    subprocess.check_call(['jina', 'hub', '--help'])
    for cmd in ['new', 'status', 'pull', 'push']:
        subprocess.check_call(['jina', 'hub', cmd, '--help'])
    subprocess.check_call(['jina', 'hub', 'pull', uses])


def test_cli_warn_unknown_args():
    subprocess.check_call(['jina', 'help', 'deployment', '--abcdefg'])


@pytest.mark.parametrize('cli', ac_table['commands'])
def test_all_cli(cli):
    subprocess.check_call(['jina', cli, '--help'])


@pytest.mark.parametrize('smethod', ['fork', 'spawn'])
def test_all_start_method(smethod):
    s = subprocess.check_output(
        ['jina', '-v'],
        env=dict(os.environ, JINA_MP_START_METHOD=smethod),
        stderr=subprocess.STDOUT,
    )
    assert 'UserWarning' in s.decode()