Skip to content

Update Path Tests #41

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 1 commit into from
Apr 16, 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
27 changes: 16 additions & 11 deletions cppython/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
self, configuration: ProjectConfiguration, interface: Interface, pyproject_data: dict[str, Any]
) -> None:

self._enabled = False
self.configuration = configuration

if self.configuration.verbose:
Expand All @@ -125,47 +126,51 @@ def __init__(
interface.print("Table [tool.cppython] is not defined")
return

self._enabled = True

self._interface = interface
self._generators = builder.create_generators(plugins, self.pyproject)

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

def download(self, path: Path):
def download(self):
"""
Download the generator tooling if required
"""
if self._enabled:
path = self.pyproject.tool.cppython.install_path

for generator in self._generators:
for generator in self._generators:

if not generator.generator_downloaded(path):
self._interface.print(f"Downloading the {generator.name()} tool")
if not generator.generator_downloaded(path):
self._interface.print(f"Downloading the {generator.name()} tool")

# TODO: Make async with progress bar
generator.download_generator(path)
self._interface.print("Download complete")
# TODO: Make async with progress bar
generator.download_generator(path)
self._interface.print("Download complete")

# API Contract

def install(self) -> None:
if self.pyproject.tool and self.pyproject.tool.cppython:
if self._enabled:
if self.configuration.verbose:
self._interface.print("CPPython: Installing...")
self.download(self.pyproject.tool.cppython.install_path)
self.download()

for generator in self._generators:
generator.install()

def update(self) -> None:
if self.pyproject.tool and self.pyproject.tool.cppython:
if self._enabled:
if self.configuration.verbose:
self._interface.print("CPPython: Updating...")

for generator in self._generators:
generator.update()

def build(self) -> None:
if self.pyproject.tool and self.pyproject.tool.cppython:
if self._enabled:
if self.configuration.verbose:
self._interface.print("CPPython: Building...")

Expand Down
21 changes: 20 additions & 1 deletion tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,30 @@ def test_construction(self, mocker: MockerFixture):
configuration = ProjectConfiguration()
Project(configuration, interface_mock, default_pyproject.dict(by_alias=True))

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

interface_mock = mocker.MagicMock()
configuration = ProjectConfiguration()

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

gather_override = mocker.patch.object(ProjectBuilder, "gather_plugins")
gather_override.return_value = [generator_type]

project_data = default_pyproject.dict(by_alias=True)
mock_data = MockGeneratorData(check=True)
project_data["tool"]["cppython"]["mock"] = mock_data.dict(by_alias=True)

project = Project(configuration, interface_mock, project_data)

# TODO: This does not verify signature correctness
project.download()


class TestBuilder:
"""
Expand Down