Skip to content

Commit

Permalink
test(functional): more tests for gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Oct 21, 2024
1 parent 1837f6f commit e7212eb
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/data/project_with_gitignore/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
foobar.py
/src/barfoo.py
2 changes: 2 additions & 0 deletions tests/data/project_with_gitignore/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/baz.py
/src/bar.py
1 change: 1 addition & 0 deletions tests/data/project_with_gitignore/src/barfoo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import hello
1 change: 1 addition & 0 deletions tests/data/project_with_gitignore/src/baz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import hej
86 changes: 86 additions & 0 deletions tests/functional/cli/test_cli_gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
def test_cli_gitignore_is_used(pip_venv_factory: PipVenvFactory) -> None:
with pip_venv_factory(Project.GITIGNORE) as virtual_env:
issue_report = f"{uuid.uuid4()}.json"

# Simulate the presence of a gitignore outside root directory from where deptry is invoked.
with Path("../.gitignore").open("w") as f:
f.write("*")

result = virtual_env.run(f"deptry . -o {issue_report}")

assert result.returncode == 1
Expand Down Expand Up @@ -60,10 +65,67 @@ def test_cli_gitignore_is_used(pip_venv_factory: PipVenvFactory) -> None:
]


@pytest.mark.xdist_group(name=Project.GITIGNORE)
def test_cli_gitignore_is_used_non_root_directory(pip_venv_factory: PipVenvFactory) -> None:
with pip_venv_factory(Project.GITIGNORE) as virtual_env:
issue_report = f"{uuid.uuid4()}.json"

# Simulate the presence of a gitignore outside root directory from where deptry is invoked.
with Path("../.gitignore").open("w") as f:
f.write("*")

result = virtual_env.run(f"deptry src -o {issue_report}")

assert result.returncode == 1
assert get_issues_report(Path(issue_report)) == [
{
"error": {
"code": "DEP002",
"message": "'requests' defined as a dependency but not used in the codebase",
},
"module": "requests",
"location": {
"file": str(Path("pyproject.toml")),
"line": None,
"column": None,
},
},
{
"error": {
"code": "DEP002",
"message": "'mypy' defined as a dependency but not used in the codebase",
},
"module": "mypy",
"location": {
"file": str(Path("pyproject.toml")),
"line": None,
"column": None,
},
},
{
"error": {
"code": "DEP002",
"message": "'pytest' defined as a dependency but not used in the codebase",
},
"module": "pytest",
"location": {
"file": str(Path("pyproject.toml")),
"line": None,
"column": None,
},
},
]


@pytest.mark.xdist_group(name=Project.GITIGNORE)
def test_cli_gitignore_is_not_used(pip_venv_factory: PipVenvFactory) -> None:
with pip_venv_factory(Project.GITIGNORE) as virtual_env:
issue_report = f"{uuid.uuid4()}.json"

# Simulate the presence of a gitignore outside root directory from where deptry is invoked.
with Path("../.gitignore").open("w") as f:
f.write("*")

result = virtual_env.run(f"deptry . --exclude build/|src/bar.py -o {issue_report}")

assert result.returncode == 1
Expand Down Expand Up @@ -104,4 +166,28 @@ def test_cli_gitignore_is_not_used(pip_venv_factory: PipVenvFactory) -> None:
"column": None,
},
},
{
"error": {
"code": "DEP001",
"message": "'hello' imported but missing from the dependency definitions",
},
"module": "hello",
"location": {
"file": str(Path("src/barfoo.py")),
"line": 1,
"column": 8,
},
},
{
"error": {
"code": "DEP001",
"message": "'hej' imported but missing from the dependency definitions",
},
"module": "hej",
"location": {
"file": str(Path("src/baz.py")),
"line": 1,
"column": 8,
},
},
]

0 comments on commit e7212eb

Please sign in to comment.