Skip to content

Commit 4876fca

Browse files
authored
Update Path Tests (#41)
1 parent 9e35682 commit 4876fca

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

cppython/project.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(
9999
self, configuration: ProjectConfiguration, interface: Interface, pyproject_data: dict[str, Any]
100100
) -> None:
101101

102+
self._enabled = False
102103
self.configuration = configuration
103104

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

129+
self._enabled = True
130+
128131
self._interface = interface
129132
self._generators = builder.create_generators(plugins, self.pyproject)
130133

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

134-
def download(self, path: Path):
137+
def download(self):
135138
"""
136139
Download the generator tooling if required
137140
"""
141+
if self._enabled:
142+
path = self.pyproject.tool.cppython.install_path
138143

139-
for generator in self._generators:
144+
for generator in self._generators:
140145

141-
if not generator.generator_downloaded(path):
142-
self._interface.print(f"Downloading the {generator.name()} tool")
146+
if not generator.generator_downloaded(path):
147+
self._interface.print(f"Downloading the {generator.name()} tool")
143148

144-
# TODO: Make async with progress bar
145-
generator.download_generator(path)
146-
self._interface.print("Download complete")
149+
# TODO: Make async with progress bar
150+
generator.download_generator(path)
151+
self._interface.print("Download complete")
147152

148153
# API Contract
149154

150155
def install(self) -> None:
151-
if self.pyproject.tool and self.pyproject.tool.cppython:
156+
if self._enabled:
152157
if self.configuration.verbose:
153158
self._interface.print("CPPython: Installing...")
154-
self.download(self.pyproject.tool.cppython.install_path)
159+
self.download()
155160

156161
for generator in self._generators:
157162
generator.install()
158163

159164
def update(self) -> None:
160-
if self.pyproject.tool and self.pyproject.tool.cppython:
165+
if self._enabled:
161166
if self.configuration.verbose:
162167
self._interface.print("CPPython: Updating...")
163168

164169
for generator in self._generators:
165170
generator.update()
166171

167172
def build(self) -> None:
168-
if self.pyproject.tool and self.pyproject.tool.cppython:
173+
if self._enabled:
169174
if self.configuration.verbose:
170175
self._interface.print("CPPython: Building...")
171176

tests/unit/test_project.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,30 @@ def test_construction(self, mocker: MockerFixture):
3131
configuration = ProjectConfiguration()
3232
Project(configuration, interface_mock, default_pyproject.dict(by_alias=True))
3333

34-
def test_download(self):
34+
def test_download(self, mocker: MockerFixture):
3535
"""
3636
TODO
3737
"""
3838

39+
interface_mock = mocker.MagicMock()
40+
configuration = ProjectConfiguration()
41+
42+
generator_type = mocker.Mock(spec=Generator)
43+
generator_type.name.return_value = "mock"
44+
generator_type.data_type.return_value = MockGeneratorData
45+
46+
gather_override = mocker.patch.object(ProjectBuilder, "gather_plugins")
47+
gather_override.return_value = [generator_type]
48+
49+
project_data = default_pyproject.dict(by_alias=True)
50+
mock_data = MockGeneratorData(check=True)
51+
project_data["tool"]["cppython"]["mock"] = mock_data.dict(by_alias=True)
52+
53+
project = Project(configuration, interface_mock, project_data)
54+
55+
# TODO: This does not verify signature correctness
56+
project.download()
57+
3958

4059
class TestBuilder:
4160
"""

0 commit comments

Comments
 (0)