-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): add tests for src directory
- Loading branch information
1 parent
3527789
commit cfe17dc
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import shlex | ||
import shutil | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
from _pytest.tmpdir import TempPathFactory | ||
|
||
from tests.utils import run_within_dir | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def pep_621_dir_with_src_directory(tmp_path_factory: TempPathFactory) -> Path: | ||
tmp_path_proj = tmp_path_factory.getbasetemp() / "project_with_src_directory" | ||
shutil.copytree("tests/data/project_with_src_directory", str(tmp_path_proj)) | ||
with run_within_dir(tmp_path_proj): | ||
assert subprocess.check_call(shlex.split("pip install .")) == 0 | ||
return tmp_path_proj | ||
|
||
|
||
def test_cli_with_src_directory(pep_621_dir_with_src_directory: Path) -> None: | ||
with run_within_dir(pep_621_dir_with_src_directory): | ||
result = subprocess.run(shlex.split("deptry src"), capture_output=True, text=True) | ||
assert result.returncode == 1 | ||
assert ( | ||
"The project contains obsolete dependencies:\n\n\tisort\n\tmypy\n\tpytest\n\trequests\n\n" in result.stderr | ||
) | ||
assert "There are dependencies missing from the project's list of dependencies:\n\n\twhite\n\n" in result.stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[project] | ||
# PEP 621 project metadata | ||
# See https://www.python.org/dev/peps/pep-0621/ | ||
name = "foo" | ||
version = "1.2.3" | ||
requires-python = ">=3.7" | ||
dependencies = [ | ||
"toml", | ||
"urllib3>=1.26.12", | ||
"isort>=5.10.1", | ||
"click>=8.1.3", | ||
"requests>=2.28.1", | ||
"pkginfo>=1.8.3", | ||
] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"black==22.10.0", | ||
"mypy==0.982", | ||
] | ||
test = [ | ||
"pytest==7.2.0", | ||
] | ||
|
||
[build-system] | ||
requires = ["setuptools>=61.0.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.deptry] | ||
ignore_obsolete = ["pkginfo"] |
Empty file.
1 change: 1 addition & 0 deletions
1
tests/data/project_with_src_directory/src/project_with_src_directory/bar.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from project_with_src_directory.foo import a_local_method |
11 changes: 11 additions & 0 deletions
11
tests/data/project_with_src_directory/src/project_with_src_directory/foo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from os import chdir, walk | ||
from pathlib import Path | ||
|
||
import black | ||
import click | ||
import white as w | ||
from urllib3 import contrib | ||
|
||
|
||
def a_local_method(): | ||
... |
37 changes: 37 additions & 0 deletions
37
tests/data/project_with_src_directory/src/project_with_src_directory/notebook.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "9f4924ec-2200-4801-9d49-d4833651cbc4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import click\n", | ||
"from urllib3 import contrib\n", | ||
"import toml" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |