-- -- --- --- --- --- --- --- ------- ------- ------- |
from pathlib import Path
-- -- --- --- --- --- --- --- ------- ------- ------- |
from unittest.mock import patch
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- |
from click.testing import CliRunner
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import wily.__main__ as main
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.helper.custom_enums import ReportFormat
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def test_init():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with patch.object(main, "cli", return_value=None) as cli:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with patch.object(main, "__name__", "__main__"):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
__import__("wily.__main__")
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert cli.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_help():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that CLI when called with help options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.logger") as logger:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["--help", "--debug"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_setup():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that CLI when called with help options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.handle_no_cache", return_value=True) as handle_no_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["setup"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert handle_no_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def test_handle_no_cache_no():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Test that setup cancels when "n" typed
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with patch("wily.__main__.input", return_value="n") as mock_input:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with pytest.raises(SystemExit):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
main.handle_no_cache(None)
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert mock_input.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def test_handle_no_cache():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Test that setup works
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with patch("wily.__main__.build", return_value="n") as build_command:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
with patch("wily.__main__.input", side_effect=["y", "11", "."]) as mock_input:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
runner = CliRunner()
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
runner.invoke(main.cli, ["setup"])
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert mock_input.called
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert build_command.called_once
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert build_command.called_with("1")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_build():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that build calls the build command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.commands.build.build") as build:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["build", "wily"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert build.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
def test_build_with_opts():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
Test that build calls the build command
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with patch("wily.commands.build.build") as build:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
result = runner.invoke(
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
main.cli, ["build", "wily", "-n 1", "-o raw,maintainability"]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert build.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert build.call_args[1]["config"].max_revisions == 1
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert build.call_args[1]["config"].operators == ["raw", "maintainability"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_index():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that index calls the index command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.commands.index.index") as index:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["index"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert index.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_index_with_opts():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that index calls the index command with options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.commands.index.index") as index:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["index", "--message"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert index.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert check_cache.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert index.call_args[1]["include_message"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
def test_index_with_no_message():
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
"""
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
Test that index calls the index command with options
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
"""
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
with patch("wily.commands.index.index") as index:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
runner = CliRunner()
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
result = runner.invoke(main.cli, ["index", "--no-message"])
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
assert result.exit_code == 0
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
assert index.called_once
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
assert check_cache.called_once
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
assert not index.call_args[1]["include_message"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
def test_report():
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
"""
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
Test that report calls the report command
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
"""
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
with patch(
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
"wily.__main__.get_default_metrics",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
return_value=["maintainability.mi", "raw.loc"],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
) as gdf:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
with patch("wily.commands.report.report") as report:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
runner = CliRunner()
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
result = runner.invoke(main.cli, ["report", "foo.py"])
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert result.exit_code == 0, result.stdout
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert report.called_once
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert check_cache.called_once
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert report.call_args[1]["path"] == "foo.py"
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert "maintainability.mi" in report.call_args[1]["metrics"]
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert gdf.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
def test_report_with_opts():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
Test that report calls the report command with options
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
main.cli, ["report", "foo.py", "example_metric", "-n 101", "--message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
def test_report_html_format():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
Test that report calls the report command with HTML as format
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
main.cli,
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
[
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"report",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"foo.py",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"example_metric",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"-n 101",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"--message",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"--format=HTML",
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
],
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["format"] == ReportFormat.HTML
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
def test_report_console_format():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
Test that report calls the report command with console as format
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"""
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
main.cli,
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
[
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"report",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"foo.py",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"example_metric",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"-n 101",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"--message",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
"--format=CONSOLE",
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
],
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_report_not_existing_format():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that report calls the report command with a non-existing format
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.commands.report.report") as report:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
main.cli,
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
[
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"report",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"foo.py",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"example_metric",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"-n 101",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"--message",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"--format=non-existing",
-- -- 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 == 2, result.stdout
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert report.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
def test_report_html_format_with_output():
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"""
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
Test that report calls the report command with HTML as format and specified output
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"""
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
with patch("wily.commands.report.report") as report:
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
runner = CliRunner()
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
result = runner.invoke(
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
main.cli,
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
[
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"report",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"foo.py",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"example_metric",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"-n 101",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"--message",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"--format=HTML",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"--output=reports/out.html",
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
],
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
)
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert result.exit_code == 0, result.stdout
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.called_once
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert check_cache.called_once
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["path"] == "foo.py"
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["include_message"]
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["n"] == 101
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["format"] == ReportFormat.HTML
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
assert report.call_args[1]["output"] == Path().cwd() / Path(
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
"reports/out.html"
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
def test_graph():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
Test that graph calls the graph command
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with patch("wily.commands.graph.graph") as graph:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
result = runner.invoke(main.cli, ["graph", "foo.py", "example_metric"])
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert check_cache.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.call_args[1]["metrics"] == ("example_metric",)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
def test_graph_multiple_metrics():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
Test that graph calls the graph command with multiple metrics
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with patch("wily.commands.graph.graph") as graph:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
result = runner.invoke(
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
main.cli, ["graph", "foo.py", "example_metric", "another_metric"]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert check_cache.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
assert graph.call_args[1]["metrics"] == ("example_metric", "another_metric")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
def test_graph_with_output():
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
"""
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
Test that graph calls the graph command with output
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
"""
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
with patch("wily.commands.graph.graph") as graph:
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
runner = CliRunner()
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
result = runner.invoke(
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
main.cli, ["graph", "foo.py", "example_metric", "-o", "foo.html"]
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
)
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert result.exit_code == 0
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert graph.called_once
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert check_cache.called_once
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert graph.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 |
assert graph.call_args[1]["output"] == "foo.html"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
def test_diff():
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
"""
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
Test that diff calls the diff command
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
"""
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
with patch(
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
"wily.__main__.get_default_metrics",
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
return_value=["maintainability.mi", "raw.loc"],
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
) as gdf:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
with patch("wily.commands.diff.diff") as diff:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
runner = CliRunner()
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
result = runner.invoke(main.cli, ["diff", "foo.py", "x/b.py"])
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert result.exit_code == 0
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert diff.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert check_cache.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert diff.call_args[1]["files"] == ("foo.py", "x/b.py")
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert gdf.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 |
assert "maintainability.mi" in diff.call_args[1]["metrics"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
def test_diff_with_metrics():
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"""
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
Test that diff calls the diff command with additional metrics
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"""
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
with patch(
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"wily.__main__.get_default_metrics",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
return_value=["maintainability.mi", "raw.loc"],
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
) as gdf:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
with patch("wily.commands.diff.diff") as diff:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
runner = CliRunner()
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
result = runner.invoke(
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
main.cli,
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
[
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"diff",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"foo.py",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"x/b.py",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"--metrics",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
"maintainability.mi,raw.sloc",
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
],
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
)
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert result.exit_code == 0
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert diff.called_once
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert check_cache.called_once
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert diff.call_args[1]["files"] == ("foo.py", "x/b.py")
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert not gdf.called
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert "maintainability.mi" in diff.call_args[1]["metrics"]
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 |
assert "raw.loc" not in diff.call_args[1]["metrics"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_clean():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that graph calls the clean command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.cache.clean") as clean:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["clean", "--yes"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert clean.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_clean_with_prompt():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Test that graph calls the clean command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.cache.clean") as clean:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
with patch("wily.__main__.input", return_value="y") as mock_input:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
result = runner.invoke(main.cli, ["clean"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert clean.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert check_cache.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert mock_input.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
def test_clean_with_prompt_no_value():
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
"""
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
Test that graph calls the clean command and if enter type "n" it doesn't clean index
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
"""
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
with patch("wily.cache.clean") as clean:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
with patch("wily.__main__.input", return_value="n") as mock_input:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
runner = CliRunner()
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
result = runner.invoke(main.cli, ["clean"])
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 |
assert result.exit_code == 0
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert not clean.called
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert mock_input.called_once