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_build_not_git_repo(tmpdir):
"""
Test that build defaults to filesystem in a non-git directory
"""
with patch("wily.logger") as logger:
runner = CliRunner()
result = runner.invoke(main.cli, ["--path", tmpdir, "build", "test.py"])
assert result.exit_code == 0, result.stdout
cache_path = tmpdir / ".wily"
assert cache_path.exists()
index_path = tmpdir / ".wily" / "filesystem" / "index.json"
assert index_path.exists()
def test_diff_output(builddir):
""" Test the diff feature with no changes """
runner = CliRunner()
result = runner.invoke(
main.cli, ["--debug", "--path", builddir, "diff", _path], catch_exceptions=False
)
assert result.exit_code == 0, result.stdout
assert "test.py" not in result.stdout
def test_operator(operator, gitdir):
runner = CliRunner()
result = runner.invoke(
main.cli, ["--debug", "--path", gitdir, "build", "src", "-o", operator]
, catch_exceptions=False
)
assert result.exit_code == 0, result.stdout
result = runner.invoke(main.cli, ["--debug", "--path", gitdir, "report", _path], catch_exceptions=False)
assert result.exit_code == 0, result.stdout
result = runner.invoke(
main.cli, ["--debug", "--path", gitdir, "diff", _path, "--all"]
, catch_exceptions=False
)
assert result.exit_code == 0, result.stdout
assert "test.py" in result.stdout
complex_test = """
import abc
foo = 1
def function1():
a = 1 + 1
if a == 2:
print(1)
def test_report_no_cache(tmpdir, cache_path):
runner = CliRunner()
result = runner.invoke(
main.cli, ["--path", tmpdir, "--cache", cache_path, "report", _path]
)
assert result.exit_code == 1, result.stdout
def test_setup():
"""
Test that CLI when called with help options
"""
with patch("wily.__main__.handle_no_cache", return_value=True) as handle_no_cache:
runner = CliRunner()
result = runner.invoke(main.cli, ["setup"])
assert result.exit_code == 0
assert handle_no_cache.called_once
def test_graph_all(builddir):
""" Test the graph feature """
runner = CliRunner()
with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
result = runner.invoke(
main.cli, ["--path", builddir, "graph", "src/test.py", "raw.loc", "--all"]
)
assert result.exit_code == 0, result.stdout
def test_rank_directory_no_path_target(builddir):
""" Test the rank feature with no path target """
runner = CliRunner()
result = runner.invoke(main.cli, ["rank", "src/", "raw.comments"])
assert result.exit_code == 0, result.stdout
def test_report_html_format_target_file(builddir):
"""
Test that report works with HTML as format
"""
runner = CliRunner()
result = runner.invoke(
main.cli,
["--path", builddir, "report", _path, "--format", "HTML", "-o", "foo/bar.html"],
)
path = Path().cwd()
path = path / "foo" / "bar.html"
assert path.exists()
assert "" in path.read_text()
assert result.exit_code == 0, result.stdout
assert "Not found" not in result.stdout
def test_operator(operator, gitdir):
runner = CliRunner()
result = runner.invoke(
main.cli, ["--debug", "--path", gitdir, "build", "src", "-o", operator]
, catch_exceptions=False
)
assert result.exit_code == 0, result.stdout
result = runner.invoke(main.cli, ["--debug", "--path", gitdir, "report", _path], catch_exceptions=False)
assert result.exit_code == 0, result.stdout
result = runner.invoke(
main.cli, ["--debug", "--path", gitdir, "diff", _path, "--all"]
, catch_exceptions=False
)
assert result.exit_code == 0, result.stdout
assert "test.py" in result.stdout
complex_test = """
import abc