Skip to content

Commit

Permalink
CLI: be more explicit in "no traces found" error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jan 28, 2018
1 parent 394f9e5 commit a00c4b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions monkeytype/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def module_path_with_qualname(path: str) -> Tuple[str, str]:
return module, qualname


def complain_about_no_traces(args, stderr):
module, qualname = args.module_path
if qualname:
print(f'No traces found for specifier {module}:{qualname}', file=stderr)
else:
print(f'No traces found for module {module}', file=stderr)


def monkeytype_config(path: str) -> Config:
"""Imports the config instance specified by path.
Expand Down Expand Up @@ -115,7 +123,7 @@ def apply_stub_handler(args: argparse.Namespace, stdout: IO, stderr: IO) -> None
args.ignore_existing_annotations = False
stub = get_stub(args, stdout, stderr)
if stub is None:
print(f'No traces found', file=stderr)
complain_about_no_traces(args, stderr)
return
module = args.module_path[0]
mod = importlib.import_module(module)
Expand Down Expand Up @@ -164,7 +172,8 @@ def print_stub_handler(args: argparse.Namespace, stdout: IO, stderr: IO) -> None
if stub is not None:
output = stub.render()
if output is None:
output, file = 'No traces found', stderr
complain_about_no_traces(args, stderr)
return
print(output, file=file)


Expand Down
10 changes: 7 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ def super_long_function_with_long_params(
assert ret == 0


def test_no_traces(store_data, stdout, stderr):
@pytest.mark.parametrize('arg, error', [
(func.__module__, f"No traces found for module {func.__module__}\n"),
(func.__module__ + ':foo', f"No traces found for specifier {func.__module__}:foo\n"),
])
def test_no_traces(store_data, stdout, stderr, arg, error):
store, db_file = store_data
with mock.patch.dict(os.environ, {DefaultConfig.DB_PATH_VAR: db_file.name}):
ret = cli.main(['stub', func.__module__], stdout, stderr)
assert stderr.getvalue() == "No traces found\n"
ret = cli.main(['stub', arg], stdout, stderr)
assert stderr.getvalue() == error
assert stdout.getvalue() == ''
assert ret == 0

Expand Down

0 comments on commit a00c4b5

Please sign in to comment.