Skip to content

Commit

Permalink
Update Path Tests (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Behemyth authored Apr 16, 2022
1 parent 9e35682 commit 4876fca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
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

0 comments on commit 4876fca

Please sign in to comment.