test\integration\test_diff.py
-- -- --- --- --- --- --- --- ------- ------- ------- | import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- | import sys
-- -- --- --- --- --- --- --- ------- ------- ------- | from textwrap import dedent
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | from click.testing import CliRunner
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.__main__ as main
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | _path = "src\\test.py" if sys.platform == "win32" else "src/test.py"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_diff_no_cache(tmpdir):
-- -- 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 | result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli, ["--path", tmpdir, "diff", _path], catch_exceptions=False
-- -- 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_diff_no_path(tmpdir):
-- -- 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 | result = runner.invoke(main.cli, ["--path", tmpdir, "diff"], catch_exceptions=False)
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 2, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | def test_diff_output(builddir):
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | """Test the diff feature with no changes"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | runner = CliRunner()
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | result = runner.invoke(
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | main.cli, ["--debug", "--path", builddir, "diff", _path], catch_exceptions=False
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | )
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert "test.py" not in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | def test_diff_output_all(builddir):
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | """Test the diff feature with no changes and the --all flag"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | runner = CliRunner()
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | result = runner.invoke(
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | main.cli,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | ["--debug", "--path", builddir, "diff", _path, "--all"],
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | catch_exceptions=False,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | )
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert "test.py" in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | def test_diff_output_all_wrapped(builddir):
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | """Test the diff feature with wrapping"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | runner = CliRunner()
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | result = runner.invoke(
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | main.cli,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | ["--debug", "--path", builddir, "diff", _path, "--all", "--wrap"],
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | catch_exceptions=False,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | )
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert "test.py" in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 | def test_diff_output_bad_path(builddir):
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | """Test the diff feature with no changes"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | runner = CliRunner()
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | result = runner.invoke(
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | main.cli,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | ["--debug", "--path", builddir, "diff", "src/baz.py"],
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | catch_exceptions=False,
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | )
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 | assert "test.py" not in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | def test_diff_output_remove_all(builddir):
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | """Test the diff feature by removing all functions and classes"""
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | test_py.write("print(1)")
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | runner = CliRunner()
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | result = runner.invoke(
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | main.cli,
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | ["--debug", "--path", builddir, "diff", _path, "--all"],
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | catch_exceptions=False,
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | )
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def test_diff_output_more_complex(builddir):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | """Test the diff feature by making the test file more complicated"""
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | complex_test = """
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | import abc
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | foo = 1
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def function1():
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | a = 1 + 1
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | if a == 2:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | print(1)
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | class Class1(object):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def method(self):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | b = 1 + 5
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | if b == 6:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | if 1==2:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | if 2==3:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | print(1)
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | """
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | test_py.write(dedent(complex_test))
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | runner = CliRunner()
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | result = runner.invoke(
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | main.cli,
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | ["--debug", "--path", builddir, "diff", _path, "--all"],
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | catch_exceptions=False,
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | )
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert result.exit_code == 0, result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "test.py" in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "- -> -" not in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "-> -" not in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "- ->" not in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def test_diff_output_less_complex(builddir):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | """Test the diff feature by making the test file more complicated"""
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | simple_test = """
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | import abc
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | foo = 1
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def function1():
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | pass
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | class Class1(object):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | def method(self):
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | pass
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | """
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | test_py.write(dedent(simple_test))
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 |
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | runner = CliRunner()
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | result = runner.invoke(
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | main.cli,
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | ["--debug", "--path", builddir, "diff", _path, "--all"],
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | catch_exceptions=False,
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | )
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert result.exit_code == 0, result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "test.py" in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "- -> -" not in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "-> -" not in result.stdout
-- -- 004 010 007 014 014 021 0079.95 0223.87 0002.80 | assert "- ->" not in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 003 008 005 010 011 015 0051.89 0097.30 0001.88 | def test_diff_output_loc(builddir):
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | """Test the diff feature by making the test file more complicated"""
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | simple_test = """print("test")"""
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | test_py.write(dedent(simple_test))
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | runner = CliRunner()
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | result = runner.invoke(
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | main.cli,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | ["--debug", "--path", builddir, "diff", _path, "--metrics", "raw.loc"],
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | catch_exceptions=False,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | )
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert result.exit_code == 0, result.stdout
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert "test.py" in result.stdout
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert "10 -> \x1b[33m1\x1b[0m" in result.stdout # 10 -> 1 (in green)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 003 008 005 010 011 015 0051.89 0097.30 0001.88 | def test_diff_output_loc_and_revision(builddir):
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | """Test the diff feature by making the test file more complicated, particular revision"""
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | simple_test = """print("test")"""
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | test_py.write(dedent(simple_test))
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 |
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | runner = CliRunner()
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | result = runner.invoke(
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | main.cli,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | [
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "--debug",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "--path",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | builddir,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "diff",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | _path,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "--metrics",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "raw.loc",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "-r",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | "HEAD^1",
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | ],
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | catch_exceptions=False,
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | )
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert result.exit_code == 0, result.stdout
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert "test.py" in result.stdout
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | assert "9 -> \x1b[33m1\x1b[0m" in result.stdout # 10 -> 1 (in green)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 003 008 005 010 011 015 0051.89 0097.30 0001.88 | def test_diff_output_rank(builddir):
-- -- 003 008 005 010 011 015 0051.89 0097.30 0001.88 | """Test the diff feature by making the test file more complicated"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | simple_test = """print("test")"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py:
-- -- --- --- --- --- --- --- ------- ------- ------- | test_py.write(dedent(simple_test))
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | runner = CliRunner()
-- -- --- --- --- --- --- --- ------- ------- ------- | result = runner.invoke(
-- -- --- --- --- --- --- --- ------- ------- ------- | main.cli,
-- -- --- --- --- --- --- --- ------- ------- ------- | [
-- -- --- --- --- --- --- --- ------- ------- ------- | "--debug",
-- -- --- --- --- --- --- --- ------- ------- ------- | "--path",
-- -- --- --- --- --- --- --- ------- ------- ------- | builddir,
-- -- --- --- --- --- --- --- ------- ------- ------- | "diff",
-- -- --- --- --- --- --- --- ------- ------- ------- | _path,
-- -- --- --- --- --- --- --- ------- ------- ------- | "--all",
-- -- --- --- --- --- --- --- ------- ------- ------- | "--metrics",
-- -- --- --- --- --- --- --- ------- ------- ------- | "maintainability.rank",
-- -- --- --- --- --- --- --- ------- ------- ------- | ],
-- -- --- --- --- --- --- --- ------- ------- ------- | catch_exceptions=False,
-- -- --- --- --- --- --- --- ------- ------- ------- | )
-- -- --- --- --- --- --- --- ------- ------- ------- | assert result.exit_code == 0, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- | assert "test.py" in result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- | assert "A -> A" in result.stdout