Skip to content

Commit

Permalink
fix(violations): show module name for DEP003 (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Mar 26, 2024
1 parent 6d7779a commit ab32284
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion python/deptry/violations/dep003_transitive/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class DEP003TransitiveDependencyViolation(Violation):
issue: Module

def get_error_message(self) -> str:
return self.error_template.format(name=self.issue.package)
return self.error_template.format(name=self.issue.name)
8 changes: 4 additions & 4 deletions tests/unit/reporters/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_simple(tmp_path: Path) -> None:
with run_within_dir(tmp_path):
JSONReporter(
[
DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)),
DEP001MissingDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)),
DEP002UnusedDependencyViolation(
Dependency("foo", Path("pyproject.toml")), Location(Path("pyproject.toml"))
),
DEP003TransitiveDependencyViolation(
Module("foo", package="foo_package"), Location(Path("foo/bar.py"), 1, 2)
Module("foo", package="foo-package"), Location(Path("foo/bar.py"), 1, 2)
),
DEP004MisplacedDevDependencyViolation(
Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)
Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)
),
],
"output.json",
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_simple(tmp_path: Path) -> None:
},
},
{
"error": {"code": "DEP003", "message": "'foo_package' imported but it is a transitive dependency"},
"error": {"code": "DEP003", "message": "'foo' imported but it is a transitive dependency"},
"module": "foo",
"location": {
"file": str(Path("foo/bar.py")),
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/reporters/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
def test_logging_number_multiple(caplog: LogCaptureFixture) -> None:
with caplog.at_level(logging.INFO):
violations = [
DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)),
DEP001MissingDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)),
DEP002UnusedDependencyViolation(
Dependency("foo", Path("pyproject.toml")), Location(Path("pyproject.toml"))
),
DEP003TransitiveDependencyViolation(
Module("foo", package="foo_package"), Location(Path("foo/bar.py"), 1, 2)
Module("foo", package="foo-package"), Location(Path("foo/bar.py"), 1, 2)
),
DEP004MisplacedDevDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)),
DEP004MisplacedDevDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)),
]
TextReporter(violations).report()

Expand All @@ -54,7 +54,7 @@ def test_logging_number_multiple(caplog: LogCaptureFixture) -> None:
file=Path("pyproject.toml"),
),
stylize(
"{BOLD}{file}{RESET}{CYAN}:{RESET}1{CYAN}:{RESET}2{CYAN}:{RESET} {BOLD}{RED}DEP003{RESET} 'foo_package'"
"{BOLD}{file}{RESET}{CYAN}:{RESET}1{CYAN}:{RESET}2{CYAN}:{RESET} {BOLD}{RED}DEP003{RESET} 'foo'"
" imported but it is a transitive dependency",
file=Path("foo/bar.py"),
),
Expand All @@ -71,7 +71,7 @@ def test_logging_number_multiple(caplog: LogCaptureFixture) -> None:
def test_logging_number_single(caplog: LogCaptureFixture) -> None:
with caplog.at_level(logging.INFO):
TextReporter([
DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2))
DEP001MissingDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2))
]).report()

assert caplog.messages == [
Expand Down Expand Up @@ -99,14 +99,14 @@ def test_logging_number_none(caplog: LogCaptureFixture) -> None:
def test_logging_no_ansi(caplog: LogCaptureFixture) -> None:
with caplog.at_level(logging.INFO):
violations = [
DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)),
DEP001MissingDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)),
DEP002UnusedDependencyViolation(
Dependency("foo", Path("pyproject.toml")), Location(Path("pyproject.toml"))
),
DEP003TransitiveDependencyViolation(
Module("foo", package="foo_package"), Location(Path("foo/bar.py"), 1, 2)
Module("foo", package="foo-package"), Location(Path("foo/bar.py"), 1, 2)
),
DEP004MisplacedDevDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)),
DEP004MisplacedDevDependencyViolation(Module("foo", package="foo-package"), Location(Path("foo.py"), 1, 2)),
]
TextReporter(violations, use_ansi=False).report()

Expand All @@ -118,7 +118,7 @@ def test_logging_no_ansi(caplog: LogCaptureFixture) -> None:
"",
f"{Path('foo.py')}:1:2: DEP001 'foo' imported but missing from the dependency definitions",
f"{Path('pyproject.toml')}: DEP002 'foo' defined as a dependency but not used in the codebase",
f"{Path('foo/bar.py')}:1:2: DEP003 'foo_package' imported but it is a transitive dependency",
f"{Path('foo/bar.py')}:1:2: DEP003 'foo' imported but it is a transitive dependency",
f"{Path('foo.py')}:1:2: DEP004 'foo' imported but declared as a dev dependency",
"Found 4 dependency issues.",
"\nFor more information, see the documentation: https://deptry.com/",
Expand Down

0 comments on commit ab32284

Please sign in to comment.