generated from jCloud/repository-template
Add PythonDocumentationGenerator method to collect all namespaces
This commit is contained in:
+2
-1
@@ -13,4 +13,5 @@
|
||||
- Add check whether sub-namespaces are not empty in `core.python.namespaces.PythonPackageNamespace.namespace`
|
||||
- Add feature to get the names of all sub-namespaces of a `core.python.namespaces.PythonPackageNamespace`
|
||||
- Add feature to compare `core.python.namespaces.PythonPackageNamespace` instances or `core.python.namespaces.PythonModuleNamespace` instances
|
||||
- Add string representation for python namespace objects
|
||||
- Add string representation for python namespace objects
|
||||
- Add `PythonDocumentationGenerator` method to collect all namespaces
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from ...utils import ExistingDirectory, assert_that_is_instance
|
||||
from .namespaces import PythonModuleNamespace, PythonPackageNamespace, PythonNamespace
|
||||
import pathlib
|
||||
|
||||
__all__ = [
|
||||
'PythonDocumentationGenerator'
|
||||
@@ -34,4 +36,25 @@ class PythonDocumentationGenerator:
|
||||
assert_that_is_instance(docs_directory, ExistingDirectory)
|
||||
|
||||
self.project_directory = project_directory
|
||||
self.docs_directory = docs_directory
|
||||
self.docs_directory = docs_directory
|
||||
|
||||
def _namespace(self, directory: pathlib.Path) -> dict[str, PythonNamespace]:
|
||||
namespaces = dict()
|
||||
|
||||
for entry in directory.iterdir():
|
||||
if entry.is_dir():
|
||||
namespaces[entry.name] = PythonPackageNamespace(entry.name, self._namespace(entry))
|
||||
elif entry.suffix == '.py':
|
||||
namespaces[entry.stem] = PythonModuleNamespace(entry.stem)
|
||||
|
||||
return namespaces
|
||||
|
||||
def namespace(self) -> PythonPackageNamespace:
|
||||
'''
|
||||
Returns the project as a namespace.
|
||||
|
||||
:return: The project as a namespace.
|
||||
:rtype: PythonPackageNamespace
|
||||
'''
|
||||
|
||||
return PythonPackageNamespace('src', self._namespace(pathlib.Path((self.project_directory / 'src').as_posix())))
|
||||
@@ -1,4 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
from src.jcloud_docsgen.core.python import PythonDocumentationGenerator
|
||||
from src.jcloud_docsgen.core.python.namespaces import PythonModuleNamespace, PythonPackageNamespace
|
||||
import pytest
|
||||
from src.jcloud_docsgen.utils import ExistingDirectory
|
||||
|
||||
@@ -14,4 +18,13 @@ from src.jcloud_docsgen.utils import ExistingDirectory
|
||||
])
|
||||
def test_PythonDocumentationGenerator_type_exceptions(project_directory, docs_directory):
|
||||
with pytest.raises(TypeError):
|
||||
PythonDocumentationGenerator(project_directory, docs_directory)
|
||||
PythonDocumentationGenerator(project_directory, docs_directory)
|
||||
|
||||
@pytest.mark.parametrize('python_documentation_generator,expected', [
|
||||
(PythonDocumentationGenerator(ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_1'), ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_1/docs')), PythonPackageNamespace('src', {})),
|
||||
(PythonDocumentationGenerator(ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_2'), ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_2/docs')), PythonPackageNamespace('src', {'module': PythonModuleNamespace('module')})),
|
||||
(PythonDocumentationGenerator(ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_3'), ExistingDirectory('tests/unit/core/python/_core/test_project_dirs/pdir_3/docs')), PythonPackageNamespace('src', {'module': PythonModuleNamespace('module'), 'pkg': PythonPackageNamespace('pkg', {'module2': PythonModuleNamespace('module2')})})),
|
||||
])
|
||||
def test_PythonDocumentationGenerator_collect_modules(python_documentation_generator: PythonDocumentationGenerator, expected):
|
||||
print('MODS:', python_documentation_generator.namespace())
|
||||
assert python_documentation_generator.namespace() == expected
|
||||
Reference in New Issue
Block a user