Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_loglevel(mocker, runner, devnull):
from covimerage import cli
logger = cli.logger
m = mocker.patch.object(logger, 'setLevel')
def assert_output(result):
if click.__version__ < '7.0':
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
else:
assert result.output.splitlines() == [
'Usage: main report [OPTIONS] [PROFILE_FILE]...',
'Try "main report -h" for help.',
'',
'Error: no such option: --nonexistingoption']
for level in ['error', 'warning', 'info', 'debug']:
result = runner.invoke(cli.main, [
m = mocker.patch.object(logger, 'setLevel')
def assert_output(result):
if click.__version__ < '7.0':
assert result.output.splitlines() == [
'Error: no such option: --nonexistingoption']
else:
assert result.output.splitlines() == [
'Usage: main report [OPTIONS] [PROFILE_FILE]...',
'Try "main report -h" for help.',
'',
'Error: no such option: --nonexistingoption']
for level in ['error', 'warning', 'info', 'debug']:
result = runner.invoke(cli.main, [
'--loglevel', level,
'report', '--nonexistingoption'])
assert_output(result)
assert result.exit_code == 2
level_name = level.upper()
assert m.call_args_list[-1] == mocker.call(level_name)
# -v should not override -l.
m.reset_mock()
result = runner.invoke(cli.main, [
'-l', 'warning', '-vvv',
'report', '--nonexistingoption'])
assert_output(result)
assert result.exit_code == 2
assert m.call_args_list == [mocker.call('WARNING')]
tmpdir.join("foo/bar/test2.vim").ensure().write("echom 2")
result = runner.invoke(cli.main, ["report", "--source", ".", devnull.name])
out = result.output.splitlines()
assert any(l.startswith(fname) for l in out) # pragma: no branch
assert out[-1].startswith("TOTAL")
assert out[-1].endswith(" 0%")
assert result.exit_code == 0
result = runner.invoke(cli.main, ["report", devnull.name, "--source", "."])
out = result.output.splitlines()
assert any(fname in l for l in out) # pragma: no branch
assert out[-1].startswith("TOTAL")
assert out[-1].endswith(" 0%")
assert result.exit_code == 0
result = runner.invoke(cli.main, ["report", "--source", "."])
out = result.output.splitlines()
assert out[-1] == "Error: --source can only be used with PROFILE_FILE."
assert result.exit_code == 2
result = runner.invoke(
cli.main,
[
"--rcfile",
devnull.name,
"report",
"--source",
"tests/test_plugin/merged_conditionals.vim",
"tests/fixtures/merged_conditionals-0.profile",
],
)
assert (
def test_cli_write_coverage(runner, tmpdir):
with tmpdir.as_cwd() as old_dir:
with pytest.raises(SystemExit) as excinfo:
cli.write_coverage([os.path.join(
str(old_dir), 'tests/fixtures/conditional_function.profile')])
assert excinfo.value.code == 0
assert os.path.exists(DEFAULT_COVERAGE_DATA_FILE)
result = runner.invoke(cli.main, ['write_coverage', '/does/not/exist'])
if click.__version__ < '7.0':
assert result.output.splitlines()[-1].startswith(
'Error: Invalid value for "profile_file": Could not open file:')
else:
assert result.output.splitlines()[-1].startswith(
'Error: Invalid value for "PROFILE_FILE...": Could not open file:')
assert result.exit_code == 2
result = runner.invoke(cli.main, ['write_coverage'])
if click.__version__ < '7.0':
expected = 'Error: Missing argument "profile_file".'