Skip to content

Commit a7f53d7

Browse files
authored
ProjectBuilder: Generator Creation (#37)
Added additional tests for generator identification and creation
1 parent f8b7a8c commit a7f53d7

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

cppython/project.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def generate_model(self, plugins: list[Type[Plugin]]) -> Type[PyProject]:
7676
__base__=PyProject,
7777
)
7878

79+
def create_generators(self, plugins: list[Type[Generator]], pyproject: PyProject) -> list[Generator]:
80+
"""
81+
TODO
82+
"""
83+
_generators = []
84+
for plugin_type in plugins:
85+
_generators.append(plugin_type(pyproject))
86+
87+
return _generators
88+
7989

8090
class Project(API):
8191
"""
@@ -116,10 +126,7 @@ def __init__(
116126
self.enabled = True
117127

118128
self._interface = interface
119-
120-
self._generators = []
121-
for plugin_type in plugins:
122-
self._generators.append(plugin_type(pyproject))
129+
self._generators = builder.create_generators(plugins, pyproject)
123130

124131
if self.configuration.verbose:
125132
interface.print("CPPython project initialized")

pdm.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/unit/test_project.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test the functions related to the internal interface implementation and the 'Interface' interface itself
33
"""
44

5-
from cppython_core.schema import Generator
5+
from cppython_core.schema import Generator, GeneratorData, PyProject
66
from pytest_mock import MockerFixture
77

88
from cppython.data import default_pyproject
@@ -40,11 +40,38 @@ def test_plugin_gather(self):
4040

4141
assert len(plugins) == 0
4242

43-
def test_generator_data_construction(self):
43+
def test_generator_data_construction(self, mocker: MockerFixture):
4444
"""
4545
TODO
4646
"""
4747

4848
configuration = ProjectConfiguration()
4949
builder = ProjectBuilder(configuration)
5050
Model = builder.generate_model([])
51+
52+
assert Model.__base__ == PyProject
53+
54+
generator = mocker.Mock(spec=Generator)
55+
generator_data = mocker.Mock(spec=GeneratorData)
56+
57+
generator.name.return_value = "mock"
58+
generator.data_type.return_value = type(generator_data)
59+
Model = builder.generate_model([generator])
60+
61+
assert Model.__base__ == PyProject
62+
63+
def test_generator_creation(self, mocker: MockerFixture):
64+
"""
65+
TODO
66+
"""
67+
68+
configuration = ProjectConfiguration()
69+
builder = ProjectBuilder(configuration)
70+
generators = builder.create_generators([], default_pyproject)
71+
72+
assert not generators
73+
74+
generator = mocker.Mock(spec=Generator)
75+
generators = builder.create_generators([generator], default_pyproject)
76+
77+
assert len(generators) == 1

0 commit comments

Comments
 (0)