Esempio n. 1
0
def test_create(
    result,
    is_dir,
    should_generate,
    expected_fixture,
    mocker,
    monkeypatch,
    tmpdir,
):
    """Status badges are created according to interrogation results."""
    monkeypatch.setattr(badge_gen.os.path, "isdir", lambda x: is_dir)
    output = tmpdir.mkdir("output")
    if not is_dir:
        output = output.join("badge.svg")

    if not should_generate:
        # pre-generate the badge
        mock_result = mocker.Mock(perc_covered=result)
        actual = badge_gen.create(str(output), mock_result)

    mock_result = mocker.Mock(perc_covered=result)
    actual = badge_gen.create(str(output), mock_result)

    with open(actual, "r") as f:
        actual_contents = f.read()
        actual_contents = actual_contents.replace("\n", "")

    expected_fixture = os.path.join(FIXTURES, expected_fixture)
    with open(expected_fixture, "r") as f:
        expected_contents = f.read()
        expected_contents = expected_contents.replace("\n", "")

    assert expected_contents == actual_contents
Esempio n. 2
0
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)
Esempio n. 3
0
def test_create(result, expected_fixture, mocker, monkeypatch, tmpdir):
    """Status badges are created according to interrogation results."""
    mock_result = mocker.Mock(perc_covered=result)
    actual = badge_gen.create(str(tmpdir), mock_result)

    with open(actual, "r") as f:
        actual_contents = f.read()

    expected_fixture = os.path.join(FIXTURES, expected_fixture)
    with open(expected_fixture, "r") as f:
        expected_contents = f.read()

    assert expected_contents == actual_contents