Skip to content

ProjectBuilder: Generator Creation #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def generate_model(self, plugins: list[Type[Plugin]]) -> Type[PyProject]:
__base__=PyProject,
)

def create_generators(self, plugins: list[Type[Generator]], pyproject: PyProject) -> list[Generator]:
"""
TODO
"""
_generators = []
for plugin_type in plugins:
_generators.append(plugin_type(pyproject))

return _generators


class Project(API):
"""
Expand Down Expand Up @@ -116,10 +126,7 @@ def __init__(
self.enabled = True

self._interface = interface

self._generators = []
for plugin_type in plugins:
self._generators.append(plugin_type(pyproject))
self._generators = builder.create_generators(plugins, pyproject)

if self.configuration.verbose:
interface.print("CPPython project initialized")
Expand Down
2 changes: 1 addition & 1 deletion pdm.lock

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

31 changes: 29 additions & 2 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test the functions related to the internal interface implementation and the 'Interface' interface itself
"""

from cppython_core.schema import Generator
from cppython_core.schema import Generator, GeneratorData, PyProject
from pytest_mock import MockerFixture

from cppython.data import default_pyproject
Expand Down Expand Up @@ -40,11 +40,38 @@ def test_plugin_gather(self):

assert len(plugins) == 0

def test_generator_data_construction(self):
def test_generator_data_construction(self, mocker: MockerFixture):
"""
TODO
"""

configuration = ProjectConfiguration()
builder = ProjectBuilder(configuration)
Model = builder.generate_model([])

assert Model.__base__ == PyProject

generator = mocker.Mock(spec=Generator)
generator_data = mocker.Mock(spec=GeneratorData)

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

assert Model.__base__ == PyProject

def test_generator_creation(self, mocker: MockerFixture):
"""
TODO
"""

configuration = ProjectConfiguration()
builder = ProjectBuilder(configuration)
generators = builder.create_generators([], default_pyproject)

assert not generators

generator = mocker.Mock(spec=Generator)
generators = builder.create_generators([generator], default_pyproject)

assert len(generators) == 1