def test_should_report_for_multiple_files():
    result = analyze([PARTLY_DOCUMENTED_FILE_PATH, DOCUMENTED_FILE_PATH, EMPTY_FILE_PATH])
    file_results, total_results = result.to_legacy()

    assert file_results == {
        PARTLY_DOCUMENTED_FILE_PATH: {
            "missing": ["FooBar.__init__", "foo", "bar"],
            "module_doc": False,
            "missing_count": 4,
            "needed_count": 5,
            "coverage": 20.0,
            "empty": False,
        },
        DOCUMENTED_FILE_PATH: {
            "missing": [],
            "module_doc": True,
            "missing_count": 0,
            "needed_count": 9,
            "coverage": 100.0,
            "empty": False,
        },
        EMPTY_FILE_PATH: {
            "missing": [],
            "module_doc": False,
            "missing_count": 0,
            "needed_count": 0,
            "coverage": 100.0,
            "empty": True,
        },
    }
    assert total_results == {"missing_count": 4, "needed_count": 14, "coverage": 71.42857142857143}
Esempio n. 2
0
def test_logging_empty_file(caplog, expected):
    with caplog.at_level(logging.DEBUG):
        result = analyze([EMPTY_FILE_PATH])
        LegacyPrinter(verbosity=4).print(result)
        _file_results, _total_results = result.to_legacy()

    if platform.system() == "Windows":
        assert [m.replace("\\", "/") for m in caplog.messages] == expected
    else:
        assert caplog.messages == expected
def test_logging_partially_documented_file(caplog, expected, verbose, ignore_names):
    ignore_config = IgnoreConfig(ignore_names=ignore_names)
    with caplog.at_level(logging.DEBUG):
        result = analyze([PARTLY_DOCUMENTED_FILE_PATH], ignore_config=ignore_config)
        LegacyPrinter(verbosity=verbose, ignore_config=ignore_config).print(result)

    if platform.system() == "Windows":
        assert [m.replace("\\", "/") for m in caplog.messages] == expected
    else:
        assert caplog.messages == expected
Esempio n. 4
0
def test_skip_decorators(ignore_setter, ignore_deleter, ignore_property,
                         coverage):
    """Tests ignoring of property decorators"""
    ignore_config = IgnoreConfig(
        skip_setter=ignore_setter,
        skip_property=ignore_property,
        skip_deleter=ignore_deleter,
    )
    result = analyze([os.path.join(INDIVIDUAL_SAMPLES_DIR, "decorators.py")],
                     ignore_config)
    assert result.count_aggregate().coverage() == coverage * 100
Esempio n. 5
0
def test_long_doc():
    """Regression test on issue 79.

    Multiline docstrings can be a smoke test when checking
    the tokenize tokens (which is based on line numbers)."""
    result = analyze([os.path.join(INDIVIDUAL_SAMPLES_DIR, "long_doc.py")])
    assert result.count_aggregate().coverage() == 75.0
    assert result.count_aggregate().num_files == 1
    # 2 + 1 inline ignore
    assert result.count_aggregate().found == 3
    assert result.count_aggregate().needed == 4
def test_skip_private():
    ignore_config = IgnoreConfig(skip_private=True)
    result = analyze([PRIVATE_NO_DOCS_PATH], ignore_config=ignore_config)
    file_results, total_results = result.to_legacy()
    assert file_results[PRIVATE_NO_DOCS_PATH] == {
        "missing": ["__dunder"],
        "module_doc": True,
        "missing_count": 1,
        "needed_count": 2,
        "coverage": 50.0,
        "empty": False,
    }
    assert total_results == {"missing_count": 1, "needed_count": 2, "coverage": 50.0}
def test_should_report_full_coverage(file_path, needed_count):
    result = analyze([file_path])
    file_results, total_results = result.to_legacy()
    assert file_results == {
        file_path: {
            "missing": [],
            "module_doc": True,
            "missing_count": 0,
            "needed_count": needed_count,
            "coverage": 100.0,
            "empty": False,
        }
    }
    assert total_results == {"missing_count": 0, "needed_count": needed_count, "coverage": 100.0}
def test_should_report_for_an_empty_file():
    result = analyze([EMPTY_FILE_PATH])
    file_results, total_results = result.to_legacy()
    assert file_results == {
        EMPTY_FILE_PATH: {
            "missing": [],
            "module_doc": False,
            "missing_count": 0,
            "needed_count": 0,
            "coverage": 100.0,
            "empty": True,
        }
    }
    assert total_results == {"missing_count": 0, "needed_count": 0, "coverage": 100}
def test_should_report_when_no_docs_in_a_file():
    result = analyze([SOME_CODE_NO_DOCS_FILE_PATH])
    file_results, total_results = result.to_legacy()
    assert file_results == {
        SOME_CODE_NO_DOCS_FILE_PATH: {
            "missing": ["foo"],
            "module_doc": False,
            "missing_count": 2,
            "needed_count": 2,
            "coverage": 0.0,
            "empty": False,
        }
    }
    assert total_results == {"missing_count": 2, "needed_count": 2, "coverage": 0.0}
Esempio n. 10
0
def test_should_report_partial_coverage(file_path, missing, module_doc,
                                        missing_count, needed_count, coverage):
    result = analyze([file_path])
    file_results, total_results = result.to_legacy()
    assert file_results == {
        file_path: {
            "missing": missing,
            "module_doc": module_doc,
            "missing_count": missing_count,
            "needed_count": needed_count,
            "coverage": coverage,
            "empty": False,
        }
    }
    assert total_results == {
        "missing_count": missing_count,
        "needed_count": needed_count,
        "coverage": coverage,
    }