test\integration\test_graph.py
-- -- --- --- --- --- --- --- ------- ------- ------- | import sys
-- -- --- --- --- --- --- --- ------- ------- ------- | import tempfile
-- -- --- --- --- --- --- --- ------- ------- ------- | from unittest.mock import patch
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | from click.testing import CliRunner
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.__main__ as main
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | _path = "src\\test.py" if sys.platform == "win32" else "src/test.py"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | PATCHED_ENV = {
-- -- --- --- --- --- --- --- ------- ------- ------- | "BROWSER": "echo %s",
-- -- --- --- --- --- --- --- ------- ------- ------- | "LC_ALL": "C.UTF-8",
-- -- --- --- --- --- --- --- ------- ------- ------- | "LANG": "C.UTF-8",
-- -- --- --- --- --- --- --- ------- ------- ------- | "HOME": tempfile.gettempdir(),
-- -- --- --- --- --- --- --- ------- ------- ------- | }
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_no_cache(tmpdir, cache_path):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | ["--path", tmpdir, "--cache", cache_path, "graph", _path, "raw.loc"],
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 1, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_all(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "--all"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_all_with_shorthand_metric(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with shorthand metric"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "loc", "--all"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_changes(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature comparing changes"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "--changes"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_custom_x(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with a custom x-axis"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "-x", "raw.sloc"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_aggregate(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the aggregate graphs"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "--aggregate"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_individual(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test individual graphs"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "--individual"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_path(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", "src/", "raw.loc"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_multiple(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with multiple metrics"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", _path, "raw.loc", "raw.comments"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_multiple_custom_x(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with multiple metrics"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | [
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "--path",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | builddir,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "graph",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | _path,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "raw.loc",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "raw.comments",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "-x",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "raw.sloc",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | ],
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_multiple_path(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with multiple metrics"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", builddir, "graph", "src/", "raw.loc", "raw.comments"]
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_output(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with target output file"""
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | [
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "--debug",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "--path",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | builddir,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "graph",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | _path,
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "raw.loc",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "-o",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "test.html",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | ],
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_graph_output_granular(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """Test the graph feature with target output file"""
-- -- --- --- --- --- --- --- ------- ------- ------- | runner = CliRunner()
-- -- --- --- --- --- --- --- ------- ------- ------- | with patch.dict("os.environ", values=PATCHED_ENV, clear=True):
-- -- --- --- --- --- --- --- ------- ------- ------- | result = runner.invoke(
-- -- --- --- --- --- --- --- ------- ------- ------- | main.cli,
-- -- --- --- --- --- --- --- ------- ------- ------- | [
-- -- --- --- --- --- --- --- ------- ------- ------- | "--debug",
-- -- --- --- --- --- --- --- ------- ------- ------- | "--path",
-- -- --- --- --- --- --- --- ------- ------- ------- | builddir,
-- -- --- --- --- --- --- --- ------- ------- ------- | "graph",
-- -- --- --- --- --- --- --- ------- ------- ------- | "src/test.py:function1",
-- -- --- --- --- --- --- --- ------- ------- ------- | "cyclomatic.complexity",
-- -- --- --- --- --- --- --- ------- ------- ------- | "-o",
-- -- --- --- --- --- --- --- ------- ------- ------- | "test_granular.html",
-- -- --- --- --- --- --- --- ------- ------- ------- | ],
-- -- --- --- --- --- --- --- ------- ------- ------- | )
-- -- --- --- --- --- --- --- ------- ------- ------- | assert result.exit_code == 0, result.stdout