-- -- --- --- --- --- --- --- ------- ------- ------- |
from click.testing import CliRunner
-- -- --- --- --- --- --- --- ------- ------- ------- |
from git.repo.base import Repo
-- -- --- --- --- --- --- --- ------- ------- ------- |
from git.util import Actor
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import wily.__main__ as main
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_rank_no_cache(tmpdir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with no cache"""
-- -- 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, "rank", "src/test.py"])
-- -- 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_rank_single_file_default_metric(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with default (AimLow) metric on a single 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 |
result = runner.invoke(main.cli, ["--path", builddir, "rank", "src/test.py"])
-- -- 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_rank_single_file_default_metric_wrapped(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with default metric and wrapping"""
-- -- 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", builddir, "rank", "--wrap", "src/test.py"]
-- -- 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_rank_directory_default_metric(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with default (AimLow) metric on a directory"""
-- -- 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", builddir, "rank", "src/"])
-- -- 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_rank_directory_default_metric_no_path(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with no 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 |
result = runner.invoke(main.cli, ["--path", builddir, "rank"])
-- -- 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_rank_directory_default_metric_master(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with a specific revision."""
-- -- 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", builddir, "rank", "-r", "master"])
-- -- 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_rank_directory_default_invalid_revision(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with an invalid revision."""
-- -- 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", builddir, "rank", "-r", "xyz"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 1, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
def test_rank_directory_default_unindexed_revision(builddir):
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
"""Test the rank feature with an unindexed revision."""
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
repo = Repo(builddir)
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
with open(builddir / "test.py", "w") as test_txt:
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
test_txt.write("import abc")
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
index = repo.index
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
index.add([str(builddir / "test.py")])
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
author = Actor("An author", "author@example.com")
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
committer = Actor("A committer", "committer@example.com")
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
commit = index.commit(
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
"unindexed commit",
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
author=author,
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
committer=committer,
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
author_date="Thu, 28 Apr 2019 22:13:13 +0200",
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
commit_date="Thu, 28 Apr 2019 22:13:13 +0200",
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
)
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
runner = CliRunner()
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
result = runner.invoke(main.cli, ["--path", builddir, "rank", "-r", commit.hexsha])
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
assert result.exit_code == 1, result.stdout
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_rank_single_file_informational(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with Informational 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 |
result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
main.cli, ["--path", builddir, "rank", "src/test.py", "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_rank_directory_custom_metric(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with AimHigh 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 |
result = runner.invoke(
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
main.cli, ["--path", builddir, "rank", "src/", "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_rank_directory_no_path_target(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with no path target"""
-- -- 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, ["rank", "src/", "raw.comments"])
-- -- 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_rank_directory_limit(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with limit"""
-- -- 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", builddir, "rank", "src/", "raw.comments", "-l 2"]
-- -- 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_rank_directory_desc(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature descending order"""
-- -- 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", builddir, "rank", "src/", "raw.comments", "--desc"]
-- -- 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_rank_directory_invalid_key(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature descending order with an invalid key"""
-- -- 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", builddir, "rank", "invalid/", "raw.comments", "--desc"]
-- -- 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_rank_directory_asc(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature ascending order"""
-- -- 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", builddir, "rank", "src/", "raw.comments", "--asc"]
-- -- 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_rank_total_above_threshold(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with total above threshold"""
-- -- 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", builddir, "rank", "--threshold=20"])
-- -- 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_rank_total_below_threshold(builddir):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""Test the rank feature with total below threshold"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
runner = CliRunner()
-- -- --- --- --- --- --- --- ------- ------- ------- |
result = runner.invoke(main.cli, ["--path", builddir, "rank", "--threshold=100"])
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert result.exit_code == 1, result.stdout