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()
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
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
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
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
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"
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)
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
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."
def test_configuration_unknown_keys(self) -> None: with pytest.raises(Exception): config = Configuration.get_configuration_from_path( "tests/test_configuration/pydoctest_unknown_keys.json")