コード例 #1
0
def test_print_results_single_file(capsys, monkeypatch):
    """Results for a single file should still list the filename."""

    monkeypatch.setattr(coverage.utils.OutputFormatter, "TERMINAL_WIDTH", 80)
    single_file = os.path.join(SAMPLE_DIR, "full.py")
    interrogate_coverage = coverage.InterrogateCoverage(paths=[single_file])
    results = interrogate_coverage.get_coverage()
    interrogate_coverage.print_results(results=results,
                                       output=None,
                                       verbosity=2)

    captured = capsys.readouterr()
    expected_fixture = os.path.join(FIXTURES,
                                    "expected_detailed_single_file.txt")

    if IS_WINDOWS:
        expected_fixture = os.path.join(FIXTURES, "windows",
                                        "expected_detailed_single_file.txt")

    with open(expected_fixture, "r") as f:
        expected_out = f.read()

    assert expected_out in captured.out
    # I don't want to deal with path mocking out just to get tests to run
    # everywhere
    if not IS_WINDOWS:
        assert "tests/functional/sample/" in captured.out
        assert "tests/functional/sample/full.py" not in captured.out
    else:
        assert "tests\\functional\\sample\\" in captured.out
        assert "tests\\functional\\sample\\full.py" not in captured.out
コード例 #2
0
def test_print_results_ignore_module(
    ignore_module, level, exp_fixture_file, capsys, monkeypatch
):
    """Do not print module info if ignore_module is True."""
    monkeypatch.setattr(coverage.utils.OutputFormatter, "TERMINAL_WIDTH", 80)

    conf = {"ignore_module": ignore_module}
    conf = config.InterrogateConfig(**conf)

    interrogate_coverage = coverage.InterrogateCoverage(
        paths=[SAMPLE_DIR], conf=conf
    )
    results = interrogate_coverage.get_coverage()
    interrogate_coverage.print_results(
        results=results, output=None, verbosity=level
    )

    captured = capsys.readouterr()
    expected_fixture = os.path.join(FIXTURES, exp_fixture_file)
    if IS_WINDOWS:
        expected_fixture = os.path.join(FIXTURES, "windows", exp_fixture_file)
    with open(expected_fixture, "r") as f:
        expected_out = f.read()

    assert expected_out in captured.out
コード例 #3
0
ファイル: cli.py プロジェクト: admdev8/interrogate
def main(ctx, paths, **kwargs):
    """Measure and report on documentation coverage in Python modules.

    \f
    # below the "\f" is ignored when running ``interrogate --help``

    .. versionchanged:: 1.1.3 ``--ignore-regex`` may now accept multiple
        values.

    .. versionadded:: 1.1.3 ``--whitelist-regex``
    .. versionadded:: 1.2.0 ``--ignore-nested-functions``
    .. versionadded:: 1.2.0 ``--color``/``--no-color``
    .. versionadded:: 1.3.0 ``--ignore-property-decorators``
    .. versionadded:: 1.3.0 config parsing support for setup.cfg
    """
    if not paths:
        paths = (os.path.abspath(os.getcwd()), )

    # NOTE: this will need to be fixed if we want to start supporting
    #       --whitelist-regex on filenames. This otherwise assumes you
    #       want to ignore module-level docs when only white listing
    #       items (visit.py will also need to be addressed since white/
    #       black listing only looks at classes & funcs, not modules).
    if kwargs["whitelist_regex"]:
        kwargs["ignore_module"] = True

    conf = config.InterrogateConfig(
        ignore_init_method=kwargs["ignore_init_method"],
        ignore_init_module=kwargs["ignore_init_module"],
        ignore_magic=kwargs["ignore_magic"],
        ignore_module=kwargs["ignore_module"],
        ignore_nested_functions=kwargs["ignore_nested_functions"],
        ignore_property_decorators=kwargs["ignore_property_decorators"],
        ignore_private=kwargs["ignore_private"],
        ignore_regex=kwargs["ignore_regex"],
        ignore_semiprivate=kwargs["ignore_semiprivate"],
        fail_under=kwargs["fail_under"],
        include_regex=kwargs["whitelist_regex"],
        color=kwargs["color"],
    )
    interrogate_coverage = coverage.InterrogateCoverage(
        paths=paths,
        conf=conf,
        excluded=kwargs["exclude"],
    )
    results = interrogate_coverage.get_coverage()

    is_quiet = kwargs["quiet"]
    if not is_quiet:
        colorama.init()  # needed for Windows
        interrogate_coverage.print_results(results, kwargs["output"],
                                           kwargs["verbose"])

    if kwargs["generate_badge"] is not None:
        output_path = badge_gen.create(kwargs["generate_badge"], results)
        if not is_quiet:
            click.echo("Generated badge to {}".format(output_path))

    sys.exit(results.ret_code)
コード例 #4
0
def test_coverage_errors(capsys):
    """Exit when no Python files are found."""
    path = os.path.join(SAMPLE_DIR, "ignoreme.txt")
    interrogate_coverage = coverage.InterrogateCoverage(paths=[path])

    with pytest.raises(SystemExit, match="1"):
        interrogate_coverage.get_coverage()

    captured = capsys.readouterr()
    assert "E: Invalid file" in captured.err

    interrogate_coverage = coverage.InterrogateCoverage(paths=[FIXTURES])

    with pytest.raises(SystemExit, match="1"):
        interrogate_coverage.get_coverage()

    captured = capsys.readouterr()
    assert "E: No Python files found to interrogate in " in captured.err
コード例 #5
0
def test_coverage_simple(paths, conf, exp_results, mocker):
    """Happy path - get expected results given a file or directory"""
    conf = config.InterrogateConfig(**conf)
    interrogate_coverage = coverage.InterrogateCoverage(paths=paths, conf=conf)

    results = interrogate_coverage.get_coverage()

    assert exp_results[0] == results.total
    assert exp_results[1] == results.covered
    assert exp_results[2] == results.missing
    assert exp_results[3] == "{:.1f}".format(results.perc_covered)
コード例 #6
0
def test_print_results(level, exp_fixture_file, capsys, monkeypatch):
    """Output of test results differ by verbosity."""
    monkeypatch.setattr(coverage.utils, "TERMINAL_WIDTH", 80)

    interrogate_coverage = coverage.InterrogateCoverage(paths=[SAMPLE_DIR])
    results = interrogate_coverage.get_coverage()
    interrogate_coverage.print_results(results=results,
                                       output=None,
                                       verbosity=level)

    captured = capsys.readouterr()
    expected_fixture = os.path.join(FIXTURES, exp_fixture_file)
    with open(expected_fixture, "r") as f:
        expected_out = f.read()
    assert expected_out in captured.out
コード例 #7
0
"""
Discover and run all unit tests.
"""

# Authors: Grzegorz Lato <*****@*****.**>
# License: MIT

import unittest
from interrogate import coverage

# first check all available unit tests
loader = unittest.TestLoader()
start_dir = '.'
suite = loader.discover(start_dir)

runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)

# now check docstring coverage with interrogate
cov = coverage.InterrogateCoverage(paths=["."])
results = cov.get_coverage()
print(f'\nInterrogate docstring coverage: {(results.covered/results.total) * 100 :.2f}%')