Skip to content

Commit

Permalink
test(unit): avoid dependency on full projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Oct 26, 2024
1 parent f2ff2e6 commit a58184e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 21 deletions.
42 changes: 42 additions & 0 deletions tests/fixtures/some_imports.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "9f4924ec-2200-4801-9d49-d4833651cbc4",
"metadata": {},
"outputs": [],
"source": [
"!ls\n",
"%timeit\n",
"%%timeit\n",
"import click\n",
"from urllib3 import contrib\n",
"import toml\n",
"1 +\\\n",
" 2"
]
}
],
"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
}
2 changes: 1 addition & 1 deletion tests/unit/imports/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_import_parser_py() -> None:


def test_import_parser_ipynb() -> None:
notebook_path = Path("tests/fixtures/example_project/src/notebook.ipynb")
notebook_path = Path("tests/fixtures/some_imports.ipynb")

assert get_imported_modules_from_list_of_files([notebook_path]) == {
"click": [Location(notebook_path, 4, 8)],
Expand Down
49 changes: 29 additions & 20 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@

from pathlib import Path

import pytest

from deptry.exceptions import PyprojectFileNotFoundError
from deptry.utils import load_pyproject_toml
from tests.utils import run_within_dir


def test_load_pyproject_toml(tmp_path: Path) -> None:
pyproject_toml = """\
[project]
name = "foo"
dependencies = ["bar", "baz>=20.9",]
[dependency-groups]
dev = ["foobar", "foobaz"]
"""
with run_within_dir(tmp_path):
with Path("pyproject.toml").open("w") as f:
f.write(pyproject_toml)

def test_load_pyproject_toml() -> None:
assert load_pyproject_toml(Path("tests/fixtures/example_project/pyproject.toml")) == {
"tool": {
"deptry": {"per_rule_ignores": {"DEP002": ["pkginfo"]}},
"poetry": {
"authors": ["test <test@test.com>"],
"dependencies": {
"click": "^8.1.3",
"isort": "^5.10.1",
"pkginfo": "^1.8.3",
"python": ">=3.7,<4.0",
"requests": "^2.28.1",
"toml": "^0.10.2",
"urllib3": "^1.26.12",
},
"description": "A test project",
"dev-dependencies": {"black": "^22.6.0"},
"name": "test",
"version": "0.0.1",
assert load_pyproject_toml(Path("pyproject.toml")) == {
"project": {
"name": "foo",
"dependencies": ["bar", "baz>=20.9"],
},
"dependency-groups": {
"dev": ["foobar", "foobaz"],
},
}
}


def test_load_pyproject_toml_not_found(tmp_path: Path) -> None:
with run_within_dir(tmp_path), pytest.raises(PyprojectFileNotFoundError):
load_pyproject_toml(Path("non_existing_pyproject.toml"))

0 comments on commit a58184e

Please sign in to comment.