diff --git a/tests/cli/test_cli_src_directory.py b/tests/cli/test_cli_src_directory.py new file mode 100644 index 00000000..8570ea18 --- /dev/null +++ b/tests/cli/test_cli_src_directory.py @@ -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 diff --git a/tests/data/project_with_src_directory/pyproject.toml b/tests/data/project_with_src_directory/pyproject.toml new file mode 100644 index 00000000..0685665b --- /dev/null +++ b/tests/data/project_with_src_directory/pyproject.toml @@ -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"] diff --git a/tests/data/project_with_src_directory/src/project_with_src_directory/__init__.py b/tests/data/project_with_src_directory/src/project_with_src_directory/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/project_with_src_directory/src/project_with_src_directory/bar.py b/tests/data/project_with_src_directory/src/project_with_src_directory/bar.py new file mode 100644 index 00000000..dbc1a7b7 --- /dev/null +++ b/tests/data/project_with_src_directory/src/project_with_src_directory/bar.py @@ -0,0 +1 @@ +from project_with_src_directory.foo import a_local_method diff --git a/tests/data/project_with_src_directory/src/project_with_src_directory/foo.py b/tests/data/project_with_src_directory/src/project_with_src_directory/foo.py new file mode 100644 index 00000000..92f88c21 --- /dev/null +++ b/tests/data/project_with_src_directory/src/project_with_src_directory/foo.py @@ -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(): + ... diff --git a/tests/data/project_with_src_directory/src/project_with_src_directory/notebook.ipynb b/tests/data/project_with_src_directory/src/project_with_src_directory/notebook.ipynb new file mode 100644 index 00000000..a51bdb9d --- /dev/null +++ b/tests/data/project_with_src_directory/src/project_with_src_directory/notebook.ipynb @@ -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 +}