Skip to content

Commit

Permalink
test(cli): add tests for src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Dec 26, 2022
1 parent 3527789 commit cfe17dc
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/cli/test_cli_src_directory.py
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
30 changes: 30 additions & 0 deletions tests/data/project_with_src_directory/pyproject.toml
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from project_with_src_directory.foo import a_local_method
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():
...
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
}

0 comments on commit cfe17dc

Please sign in to comment.