Exemplo n.º 1
0
    def test_configuration_unknown_parser(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_configuration/pydoctest.json")
        config.parser = "kldfgjndfgnjg"

        with pytest.raises(Exception):
            config.get_parser()
Exemplo n.º 2
0
    def test_correct_class_module(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_class/pydoctest_correct_class.json")

        ds = PyDoctestService(config)
        result = ds.validate()
        assert result.result == ResultType.OK
Exemplo n.º 3
0
    def test_invalid_python_module(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_main/pydoctest.json")

        ds = PyDoctestService(config)
        result = ds.validate()
        assert result.module_results[0].result == ResultType.NOT_RUN
        assert "Failed to load file from location" in result.module_results[
            0].fail_reason
Exemplo n.º 4
0
    def test_configuration_from_path(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_configuration/pydoctest.json")
        assert config.parser == "parsername"

        assert config.include_paths == ["/path/to/module"]
        assert config.exclude_paths == ["/excludes/0", "excludes/1"]

        assert config.fail_on_missing_docstring == True
Exemplo n.º 5
0
    def test_no_include_paths(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_class/test_no_include_paths/pydoctest.json")
        ds = PyDoctestService(config)
        result = ds.validate()
        assert result.result == ResultType.OK

        # Assert that 1 module was found in root. We do not search recursively.
        assert len(result.module_results) == 1
Exemplo n.º 6
0
 def test_enum_in_module(self) -> None:
     # Test that enums are ignored
     config = Configuration.get_configuration_from_path(
         "tests/test_class/pydoctest_enum_in_module.json")
     ds = PyDoctestService(config)
     result = ds.validate()
     assert len(result.module_results[0].class_results) == 1
     assert result.module_results[0].class_results[
         0].class_name == "ExampleClass"
Exemplo n.º 7
0
def get_configuration(root_dir: str,
                      config_path: Optional[str] = None) -> Configuration:
    """Searches for CONFIG_FILE_NAME in root_dir, unless a path is provided.

    Args:
        root_dir (str): The directory to search in.
        config_path (Optional[str], optional): [description]. Defaults to None.

    Returns:
        Configuration: Either a configuration matching the specified/found one, or a default one.
    """
    if config_path:
        return Configuration.get_configuration_from_path(config_path)

    config_paths = [p for p in os.listdir(root_dir) if p == CONFIG_FILE_NAME]
    if len(config_paths) == 0:
        # TODO: Is the interface better by returning Optional[Configuration] (None here)?
        # Then it is clearer that a config was not found.
        return Configuration.get_default_configuration(root_dir)

    path = os.path.join(root_dir, config_paths[0])
    return Configuration.get_configuration_from_path(path)
Exemplo n.º 8
0
    def test_counts_class(self) -> None:
        config = Configuration.get_configuration_from_path(
            "tests/test_class/pydoctest_get_counts.json")
        config.fail_on_missing_docstring = False

        ds = PyDoctestService(config)
        result = ds.validate()
        counts = result.get_counts()

        assert counts.functions_failed == 1
        assert counts.functions_skipped == 1
        assert counts.functions_succeeded == 2
        assert counts.module_count == 1

        assert counts.get_total() == 4
Exemplo n.º 9
0
 def test_pydoctest(self) -> None:
     config = Configuration.get_configuration_from_path("pydoctest.json")
     ds = PyDoctestService(config)
     result = ds.validate()
     counts = result.get_counts()
     assert counts.functions_failed == 0, "Run pydoctest on project and fix docstrings."
Exemplo n.º 10
0
 def test_configuration_unknown_keys(self) -> None:
     with pytest.raises(Exception):
         config = Configuration.get_configuration_from_path(
             "tests/test_configuration/pydoctest_unknown_keys.json")