Skip to content

Commit 626aa6c

Browse files
committed
test_traverse_project: Prepare for testing with 'pyenvs'
We are about to introduce Python environments into the traverse_project logic. When testing the new logic we will - in addition to passing in code + deps via settings and expecting corresponding CodeSource and DepsSource objects to be created - also do the same for settings.pyenvs, resulting in the creation of PyEnvSource objects. The default mode of operation will be to auto-detect Python environments under the current project dir (as we currently do for code + deps). In order for the new logic not to interfere with the existing code/deps tests, we must therefore explicitly pass an empty pyenvs set to the existing tests. This commit does exactly that. A lot of diff noise to ensure that a future change does not change how these existing tests will work.
1 parent 63f4a03 commit 626aa6c

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tests/test_traverse_project.py

+41-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
import pytest
77

88
from fawltydeps.settings import ParserChoice, Settings
9-
from fawltydeps.traverse_project import CodeSource, DepsSource, find_sources
10-
from fawltydeps.types import PathOrSpecial, UnparseablePathException
9+
from fawltydeps.traverse_project import find_sources
10+
from fawltydeps.types import (
11+
CodeSource,
12+
DepsSource,
13+
PathOrSpecial,
14+
UnparseablePathException,
15+
)
1116

1217
from .test_sample_projects import SAMPLE_PROJECTS_DIR
1318

@@ -21,6 +26,7 @@ class TraverseProjectVector:
2126
# The following sets contain paths that are all relative to cwd
2227
code: Set[str] = dataclasses.field(default_factory=lambda: {"."})
2328
deps: Set[str] = dataclasses.field(default_factory=lambda: {"."})
29+
pyenvs: Set[str] = dataclasses.field(default_factory=lambda: {"."})
2430
deps_parser_choice: Optional[ParserChoice] = None
2531
expect_imports_src: Set[str] = dataclasses.field(default_factory=set)
2632
expect_deps_src: Set[str] = dataclasses.field(default_factory=set)
@@ -36,6 +42,7 @@ class TraverseProjectVector:
3642
"blog_post_example",
3743
code=set(),
3844
deps=set(),
45+
pyenvs=set(),
3946
),
4047
#
4148
# Testing 'code' alone:
@@ -45,69 +52,79 @@ class TraverseProjectVector:
4552
"blog_post_example",
4653
code={"missing.py"},
4754
deps=set(),
55+
pyenvs=set(),
4856
expect_raised=UnparseablePathException,
4957
),
5058
TraverseProjectVector(
5159
"given_code_as_non_py_file__raises_exception",
5260
"blog_post_example",
5361
code={"README.md"},
5462
deps=set(),
63+
pyenvs=set(),
5564
expect_raised=UnparseablePathException,
5665
),
5766
TraverseProjectVector(
5867
"given_code_as_specialpath_stdin__yields_preserved_specialpath_stdin",
5968
"empty",
6069
code={"<stdin>"},
6170
deps=set(),
71+
pyenvs=set(),
6272
expect_imports_src={"<stdin>"},
6373
),
6474
TraverseProjectVector(
6575
"given_code_as_py_file__yields_file",
6676
"blog_post_example",
6777
code={"my_script.py"},
6878
deps=set(),
79+
pyenvs=set(),
6980
expect_imports_src={"my_script.py"},
7081
),
7182
TraverseProjectVector(
7283
"given_code_as_ipynb_file__yields_file",
7384
"mixed_project",
7485
code={"subdir1/notebook.ipynb"},
7586
deps=set(),
87+
pyenvs=set(),
7688
expect_imports_src={"subdir1/notebook.ipynb"},
7789
),
7890
TraverseProjectVector(
7991
"given_code_as_py_and_ipynb_file__yields_both_files",
8092
"mixed_project",
8193
code={"subdir1/notebook.ipynb", "subdir2/script.py"},
8294
deps=set(),
95+
pyenvs=set(),
8396
expect_imports_src={"subdir1/notebook.ipynb", "subdir2/script.py"},
8497
),
8598
TraverseProjectVector(
8699
"given_code_as_stdin_and_files__yields_all",
87100
"mixed_project",
88101
code={"<stdin>", "subdir1/notebook.ipynb", "subdir2/script.py"},
89102
deps=set(),
103+
pyenvs=set(),
90104
expect_imports_src={"<stdin>", "subdir1/notebook.ipynb", "subdir2/script.py"},
91105
),
92106
TraverseProjectVector(
93107
"given_code_as_dir__yields_only_files_within",
94108
"mixed_project",
95109
code={"subdir1"},
96110
deps=set(),
111+
pyenvs=set(),
97112
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
98113
),
99114
TraverseProjectVector(
100115
"given_code_as_dir_and_stdin__yields_files_within_dir_and_stdin",
101116
"mixed_project",
102117
code={"subdir1", "<stdin>"},
103118
deps=set(),
119+
pyenvs=set(),
104120
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py", "<stdin>"},
105121
),
106122
TraverseProjectVector(
107123
"given_code_as_multiple_dirs__yields_files_within_all_dirs",
108124
"mixed_project",
109125
code={"subdir1", "subdir2"},
110126
deps=set(),
127+
pyenvs=set(),
111128
expect_imports_src={
112129
"subdir1/notebook.ipynb",
113130
"subdir1/script.py",
@@ -121,6 +138,7 @@ class TraverseProjectVector:
121138
"mixed_project",
122139
code={".", "subdir2"},
123140
deps=set(),
141+
pyenvs=set(),
124142
expect_imports_src={
125143
"main.py",
126144
"subdir1/notebook.ipynb",
@@ -135,6 +153,7 @@ class TraverseProjectVector:
135153
"mixed_project",
136154
code={"subdir1", "subdir2/notebook.ipynb"},
137155
deps=set(),
156+
pyenvs=set(),
138157
expect_imports_src={
139158
"subdir1/notebook.ipynb",
140159
"subdir1/script.py",
@@ -149,62 +168,71 @@ class TraverseProjectVector:
149168
"blog_post_example",
150169
code=set(),
151170
deps={"missing_requirements.txt"},
171+
pyenvs=set(),
152172
expect_raised=UnparseablePathException,
153173
),
154174
TraverseProjectVector(
155175
"given_deps_as_non_deps_file__raises_exception",
156176
"blog_post_example",
157177
code=set(),
158178
deps={"README.md"},
179+
pyenvs=set(),
159180
expect_raised=UnparseablePathException,
160181
),
161182
TraverseProjectVector(
162183
"given_deps_as_requirements_txt__yields_file",
163184
"blog_post_example",
164185
code=set(),
165186
deps={"requirements.txt"},
187+
pyenvs=set(),
166188
expect_deps_src={"requirements.txt"},
167189
),
168190
TraverseProjectVector(
169191
"given_deps_as_pyproject_toml__yields_file",
170192
"mixed_project",
171193
code=set(),
172194
deps={"pyproject.toml"},
195+
pyenvs=set(),
173196
expect_deps_src={"pyproject.toml"},
174197
),
175198
TraverseProjectVector(
176199
"given_deps_as_setup_cfg_and_pyproject_toml__yields_both_files",
177200
"mixed_project",
178201
code=set(),
179202
deps={"pyproject.toml", "subdir1/setup.cfg"},
203+
pyenvs=set(),
180204
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg"},
181205
),
182206
TraverseProjectVector(
183207
"given_deps_as_dir__yields_only_files_within",
184208
"mixed_project",
185209
code=set(),
186210
deps={"subdir1"},
211+
pyenvs=set(),
187212
expect_deps_src={"subdir1/setup.cfg"},
188213
),
189214
TraverseProjectVector(
190215
"given_deps_as_multiple_dirs__yields_files_within_all_dirs",
191216
"mixed_project",
192217
code=set(),
193218
deps={"subdir1", "subdir2"},
219+
pyenvs=set(),
194220
expect_deps_src={"subdir1/setup.cfg", "subdir2/setup.py"},
195221
),
196222
TraverseProjectVector(
197223
"given_deps_as_parent_and_child_dirs__yields_files_within_all_dirs",
198224
"mixed_project",
199225
code=set(),
200226
deps={".", "subdir2"},
227+
pyenvs=set(),
201228
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg", "subdir2/setup.py"},
202229
),
203230
TraverseProjectVector(
204231
"given_deps_as_file_and_dir__yields_file_and_files_within_dir",
205232
"mixed_project",
206233
code=set(),
207234
deps={"subdir1", "subdir2/setup.py"},
235+
pyenvs=set(),
208236
expect_deps_src={"subdir1/setup.cfg", "subdir2/setup.py"},
209237
),
210238
#
@@ -215,6 +243,7 @@ class TraverseProjectVector:
215243
"mixed_project",
216244
code=set(),
217245
deps={"pyproject.toml", "subdir1/setup.cfg"},
246+
pyenvs=set(),
218247
deps_parser_choice=ParserChoice.REQUIREMENTS_TXT,
219248
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg"},
220249
),
@@ -223,6 +252,7 @@ class TraverseProjectVector:
223252
"mixed_project",
224253
code=set(),
225254
deps={"."},
255+
pyenvs=set(),
226256
deps_parser_choice=ParserChoice.SETUP_CFG,
227257
expect_deps_src={"subdir1/setup.cfg"},
228258
),
@@ -231,6 +261,7 @@ class TraverseProjectVector:
231261
"mixed_project",
232262
code=set(),
233263
deps={"subdir2"},
264+
pyenvs=set(),
234265
deps_parser_choice=ParserChoice.REQUIREMENTS_TXT,
235266
expect_deps_src=set(),
236267
),
@@ -248,6 +279,7 @@ class TraverseProjectVector:
248279
"blog_post_example",
249280
code={"my_script.py"},
250281
deps={"requirements.txt", "dev-requirements.txt"},
282+
pyenvs=set(),
251283
expect_imports_src={"my_script.py"},
252284
expect_deps_src={"requirements.txt", "dev-requirements.txt"},
253285
),
@@ -256,6 +288,7 @@ class TraverseProjectVector:
256288
"mixed_project",
257289
code={"subdir1"},
258290
deps={"subdir1"},
291+
pyenvs=set(),
259292
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
260293
expect_deps_src={"subdir1/setup.cfg"},
261294
),
@@ -264,6 +297,7 @@ class TraverseProjectVector:
264297
"mixed_project",
265298
code={"subdir2"},
266299
deps={"subdir2"},
300+
pyenvs=set(),
267301
expect_imports_src={
268302
"subdir2/notebook.ipynb",
269303
"subdir2/script.py",
@@ -276,6 +310,7 @@ class TraverseProjectVector:
276310
"mixed_project",
277311
code={"subdir1"},
278312
deps={"subdir2"},
313+
pyenvs=set(),
279314
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
280315
expect_deps_src={"subdir2/setup.py"},
281316
),
@@ -284,15 +319,17 @@ class TraverseProjectVector:
284319
"mixed_project",
285320
code={"subdir1"},
286321
deps={"."},
322+
pyenvs=set(),
287323
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
288324
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg", "subdir2/setup.py"},
289325
),
290326
#
291-
# We should not traverse into dot dirs (e.g. .git or .venv) by default
327+
# 'code' + 'deps' don't traverse into dot dirs (e.g. .git, .venv) by default
292328
#
293329
TraverseProjectVector(
294330
"default_traversal_in_no_issues__does_not_traverse_into_dot_venv",
295331
"no_issues",
332+
pyenvs=set(),
296333
expect_imports_src={"python_file.py"},
297334
expect_deps_src={"requirements.txt", "subdir/requirements.txt"},
298335
),
@@ -322,6 +359,7 @@ def test_find_sources(vector: TraverseProjectVector):
322359
},
323360
deps={project_dir / path for path in vector.deps},
324361
deps_parser_choice=vector.deps_parser_choice,
362+
pyenvs={project_dir / path for path in vector.pyenvs},
325363
)
326364
expect_imports_src = {
327365
path if path == "<stdin>" else project_dir / path

0 commit comments

Comments
 (0)