Skip to content

Commit

Permalink
test_traverse_project: Prepare for testing with 'pyenvs'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jherland committed May 30, 2023
1 parent 11ebb34 commit 36a78ab
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tests/test_traverse_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import pytest

from fawltydeps.settings import ParserChoice, Settings
from fawltydeps.traverse_project import CodeSource, DepsSource, find_sources
from fawltydeps.types import PathOrSpecial, UnparseablePathException
from fawltydeps.traverse_project import find_sources
from fawltydeps.types import (
CodeSource,
DepsSource,
PathOrSpecial,
UnparseablePathException,
)

from .test_sample_projects import SAMPLE_PROJECTS_DIR

Expand All @@ -21,6 +26,7 @@ class TraverseProjectVector:
# The following sets contain paths that are all relative to cwd
code: Set[str] = dataclasses.field(default_factory=lambda: {"."})
deps: Set[str] = dataclasses.field(default_factory=lambda: {"."})
pyenvs: Set[str] = dataclasses.field(default_factory=lambda: {"."})
deps_parser_choice: Optional[ParserChoice] = None
expect_imports_src: Set[str] = dataclasses.field(default_factory=set)
expect_deps_src: Set[str] = dataclasses.field(default_factory=set)
Expand All @@ -36,6 +42,7 @@ class TraverseProjectVector:
"blog_post_example",
code=set(),
deps=set(),
pyenvs=set(),
),
#
# Testing 'code' alone:
Expand All @@ -45,69 +52,79 @@ class TraverseProjectVector:
"blog_post_example",
code={"missing.py"},
deps=set(),
pyenvs=set(),
expect_raised=UnparseablePathException,
),
TraverseProjectVector(
"given_code_as_non_py_file__raises_exception",
"blog_post_example",
code={"README.md"},
deps=set(),
pyenvs=set(),
expect_raised=UnparseablePathException,
),
TraverseProjectVector(
"given_code_as_specialpath_stdin__yields_preserved_specialpath_stdin",
"empty",
code={"<stdin>"},
deps=set(),
pyenvs=set(),
expect_imports_src={"<stdin>"},
),
TraverseProjectVector(
"given_code_as_py_file__yields_file",
"blog_post_example",
code={"my_script.py"},
deps=set(),
pyenvs=set(),
expect_imports_src={"my_script.py"},
),
TraverseProjectVector(
"given_code_as_ipynb_file__yields_file",
"mixed_project",
code={"subdir1/notebook.ipynb"},
deps=set(),
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb"},
),
TraverseProjectVector(
"given_code_as_py_and_ipynb_file__yields_both_files",
"mixed_project",
code={"subdir1/notebook.ipynb", "subdir2/script.py"},
deps=set(),
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir2/script.py"},
),
TraverseProjectVector(
"given_code_as_stdin_and_files__yields_all",
"mixed_project",
code={"<stdin>", "subdir1/notebook.ipynb", "subdir2/script.py"},
deps=set(),
pyenvs=set(),
expect_imports_src={"<stdin>", "subdir1/notebook.ipynb", "subdir2/script.py"},
),
TraverseProjectVector(
"given_code_as_dir__yields_only_files_within",
"mixed_project",
code={"subdir1"},
deps=set(),
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
),
TraverseProjectVector(
"given_code_as_dir_and_stdin__yields_files_within_dir_and_stdin",
"mixed_project",
code={"subdir1", "<stdin>"},
deps=set(),
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py", "<stdin>"},
),
TraverseProjectVector(
"given_code_as_multiple_dirs__yields_files_within_all_dirs",
"mixed_project",
code={"subdir1", "subdir2"},
deps=set(),
pyenvs=set(),
expect_imports_src={
"subdir1/notebook.ipynb",
"subdir1/script.py",
Expand All @@ -121,6 +138,7 @@ class TraverseProjectVector:
"mixed_project",
code={".", "subdir2"},
deps=set(),
pyenvs=set(),
expect_imports_src={
"main.py",
"subdir1/notebook.ipynb",
Expand All @@ -135,6 +153,7 @@ class TraverseProjectVector:
"mixed_project",
code={"subdir1", "subdir2/notebook.ipynb"},
deps=set(),
pyenvs=set(),
expect_imports_src={
"subdir1/notebook.ipynb",
"subdir1/script.py",
Expand All @@ -149,62 +168,71 @@ class TraverseProjectVector:
"blog_post_example",
code=set(),
deps={"missing_requirements.txt"},
pyenvs=set(),
expect_raised=UnparseablePathException,
),
TraverseProjectVector(
"given_deps_as_non_deps_file__raises_exception",
"blog_post_example",
code=set(),
deps={"README.md"},
pyenvs=set(),
expect_raised=UnparseablePathException,
),
TraverseProjectVector(
"given_deps_as_requirements_txt__yields_file",
"blog_post_example",
code=set(),
deps={"requirements.txt"},
pyenvs=set(),
expect_deps_src={"requirements.txt"},
),
TraverseProjectVector(
"given_deps_as_pyproject_toml__yields_file",
"mixed_project",
code=set(),
deps={"pyproject.toml"},
pyenvs=set(),
expect_deps_src={"pyproject.toml"},
),
TraverseProjectVector(
"given_deps_as_setup_cfg_and_pyproject_toml__yields_both_files",
"mixed_project",
code=set(),
deps={"pyproject.toml", "subdir1/setup.cfg"},
pyenvs=set(),
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg"},
),
TraverseProjectVector(
"given_deps_as_dir__yields_only_files_within",
"mixed_project",
code=set(),
deps={"subdir1"},
pyenvs=set(),
expect_deps_src={"subdir1/setup.cfg"},
),
TraverseProjectVector(
"given_deps_as_multiple_dirs__yields_files_within_all_dirs",
"mixed_project",
code=set(),
deps={"subdir1", "subdir2"},
pyenvs=set(),
expect_deps_src={"subdir1/setup.cfg", "subdir2/setup.py"},
),
TraverseProjectVector(
"given_deps_as_parent_and_child_dirs__yields_files_within_all_dirs",
"mixed_project",
code=set(),
deps={".", "subdir2"},
pyenvs=set(),
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg", "subdir2/setup.py"},
),
TraverseProjectVector(
"given_deps_as_file_and_dir__yields_file_and_files_within_dir",
"mixed_project",
code=set(),
deps={"subdir1", "subdir2/setup.py"},
pyenvs=set(),
expect_deps_src={"subdir1/setup.cfg", "subdir2/setup.py"},
),
#
Expand All @@ -215,6 +243,7 @@ class TraverseProjectVector:
"mixed_project",
code=set(),
deps={"pyproject.toml", "subdir1/setup.cfg"},
pyenvs=set(),
deps_parser_choice=ParserChoice.REQUIREMENTS_TXT,
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg"},
),
Expand All @@ -223,6 +252,7 @@ class TraverseProjectVector:
"mixed_project",
code=set(),
deps={"."},
pyenvs=set(),
deps_parser_choice=ParserChoice.SETUP_CFG,
expect_deps_src={"subdir1/setup.cfg"},
),
Expand All @@ -231,6 +261,7 @@ class TraverseProjectVector:
"mixed_project",
code=set(),
deps={"subdir2"},
pyenvs=set(),
deps_parser_choice=ParserChoice.REQUIREMENTS_TXT,
expect_deps_src=set(),
),
Expand All @@ -248,6 +279,7 @@ class TraverseProjectVector:
"blog_post_example",
code={"my_script.py"},
deps={"requirements.txt", "dev-requirements.txt"},
pyenvs=set(),
expect_imports_src={"my_script.py"},
expect_deps_src={"requirements.txt", "dev-requirements.txt"},
),
Expand All @@ -256,6 +288,7 @@ class TraverseProjectVector:
"mixed_project",
code={"subdir1"},
deps={"subdir1"},
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
expect_deps_src={"subdir1/setup.cfg"},
),
Expand All @@ -264,6 +297,7 @@ class TraverseProjectVector:
"mixed_project",
code={"subdir2"},
deps={"subdir2"},
pyenvs=set(),
expect_imports_src={
"subdir2/notebook.ipynb",
"subdir2/script.py",
Expand All @@ -276,6 +310,7 @@ class TraverseProjectVector:
"mixed_project",
code={"subdir1"},
deps={"subdir2"},
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
expect_deps_src={"subdir2/setup.py"},
),
Expand All @@ -284,15 +319,17 @@ class TraverseProjectVector:
"mixed_project",
code={"subdir1"},
deps={"."},
pyenvs=set(),
expect_imports_src={"subdir1/notebook.ipynb", "subdir1/script.py"},
expect_deps_src={"pyproject.toml", "subdir1/setup.cfg", "subdir2/setup.py"},
),
#
# We should not traverse into dot dirs (e.g. .git or .venv) by default
# 'code' + 'deps' don't traverse into dot dirs (e.g. .git, .venv) by default
#
TraverseProjectVector(
"default_traversal_in_no_issues__does_not_traverse_into_dot_venv",
"no_issues",
pyenvs=set(),
expect_imports_src={"python_file.py"},
expect_deps_src={"requirements.txt", "subdir/requirements.txt"},
),
Expand Down Expand Up @@ -322,6 +359,7 @@ def test_find_sources(vector: TraverseProjectVector):
},
deps={project_dir / path for path in vector.deps},
deps_parser_choice=vector.deps_parser_choice,
pyenvs={project_dir / path for path in vector.pyenvs},
)
expect_imports_src = {
path if path == "<stdin>" else project_dir / path
Expand Down

0 comments on commit 36a78ab

Please sign in to comment.