Skip to content

Commit

Permalink
Model Generation Fix (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Behemyth authored Apr 14, 2022
1 parent 79ba21a commit b9d31c9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cppython/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def info(config):
"""
TODO
"""
project = config.create_project()
config.create_project()


@cli.command()
Expand Down
12 changes: 6 additions & 6 deletions cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def gather_plugins(self, plugin_type: Type[DerivedPlugin]) -> list[Type[DerivedP

def generate_model(self, plugins: list[Type[Generator]]) -> Type[PyProject]:
"""
TODO
TODO: Proper return type hint
"""
plugin_fields = {}
for plugin_type in plugins:
plugin_fields[plugin_type.name()] = plugin_type.data_type()
plugin_fields[plugin_type.name()] = (plugin_type.data_type(), ...)

extended_cppython_type = create_model(
"ExtendedCPPythonData",
Expand All @@ -67,14 +67,14 @@ def generate_model(self, plugins: list[Type[Generator]]) -> Type[PyProject]:
)

extended_tool_type = create_model(
"ToolData",
cppython=extended_cppython_type,
"ExtendedToolData",
cppython=(extended_cppython_type, ...),
__base__=ToolData,
)

return create_model(
"PyProject",
tool=extended_tool_type,
"ExtendedPyProject",
tool=(extended_tool_type, ...),
__base__=PyProject,
)

Expand Down
18 changes: 9 additions & 9 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
from cppython.project import Project, ProjectBuilder, ProjectConfiguration


class MockGeneratorData(GeneratorData):
"""
TODO
"""

check: bool


class TestProject:
"""
TODO
Expand Down Expand Up @@ -51,14 +59,22 @@ def test_generator_data_construction(self, mocker: MockerFixture):

assert model_type.__base__ == PyProject

generator = mocker.Mock(spec=Generator)
generator_data = mocker.Mock(spec=GeneratorData)
generator_type = mocker.Mock(spec=Generator)
generator_type.name.return_value = "mock"
generator_type.data_type.return_value = MockGeneratorData

generator.name.return_value = "mock"
generator.data_type.return_value = type(generator_data)
model_type = builder.generate_model([generator])
model_type = builder.generate_model([generator_type])

assert model_type.__base__ == PyProject
project_data = default_pyproject.dict()

mock_data = MockGeneratorData(check=True)
project_data["tool"]["cppython"]["mock"] = mock_data.dict()
result = model_type(**project_data)

assert result.tool is not None
assert result.tool.cppython is not None

assert result.tool.cppython.mock.check

def test_generator_creation(self, mocker: MockerFixture):
"""
Expand Down

0 comments on commit b9d31c9

Please sign in to comment.