Skip to content

Commit 2aaf842

Browse files
authored
Pass Concrete GeneratorData Type to Constructors (#70)
1 parent 26cf24c commit 2aaf842

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

cppython/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
The central delegation of the CPPython project
33
"""
44

5-
import collections.abc
65
import logging
76
from importlib import metadata
87
from pathlib import Path
@@ -89,7 +88,8 @@ def create_generators(
8988
"""
9089
_generators = []
9190
for plugin_type in plugins:
92-
_generators.append(plugin_type(configuration, project, cppython))
91+
name = plugin_type.name()
92+
_generators.append(plugin_type(configuration, project, cppython, getattr(cppython, name)))
9393

9494
return _generators
9595

pdm.lock

Lines changed: 8 additions & 8 deletions
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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class MockGeneratorData(GeneratorData):
3333
check: bool
3434

3535

36+
class ExtendedCPPython(CPPythonData):
37+
"""
38+
TODO
39+
"""
40+
41+
mock: MockGeneratorData
42+
43+
3644
class TestProject:
3745
"""
3846
TODO
@@ -105,9 +113,20 @@ def test_generator_creation(self, mocker: MockerFixture):
105113

106114
assert not generators
107115

108-
generator = mocker.Mock()
116+
generator_type = mocker.Mock()
117+
generator_type.name.return_value = "mock"
118+
generator_type.data_type.return_value = MockGeneratorData
119+
120+
mock_data = MockGeneratorData(check=True)
121+
extended_cppython_dict = default_cppython_data.dict(exclude_defaults=True)
122+
extended_cppython_dict["mock"] = mock_data
123+
extended_cppython = ExtendedCPPython(**extended_cppython_dict)
124+
109125
generators = builder.create_generators(
110-
[generator], generator_configuration, default_pep621, default_cppython_data
126+
[generator_type],
127+
generator_configuration,
128+
default_pep621,
129+
extended_cppython,
111130
)
112131

113132
assert len(generators) == 1

0 commit comments

Comments
 (0)