Skip to content

Commit

Permalink
Add relative-path tests for banned-api (#4033)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Apr 19, 2023
1 parent 25a6bfa commit eed6866
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 13 deletions.

This file was deleted.

32 changes: 31 additions & 1 deletion crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod tests {
use super::ApiBan;

#[test]
fn banned_api_true_positives() -> Result<()> {
fn banned_api() -> Result<()> {
let diagnostics = test_path(
Path::new("flake8_tidy_imports/TID251.py"),
&Settings {
Expand All @@ -148,4 +148,34 @@ mod tests {
assert_messages!(diagnostics);
Ok(())
}

#[test]
fn banned_api_package() -> Result<()> {
let diagnostics = test_path(
Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"),
&Settings {
flake8_tidy_imports: super::super::Settings {
banned_api: FxHashMap::from_iter([
(
"attrs".to_string(),
ApiBan {
msg: "The attrs module is deprecated.".to_string(),
},
),
(
"my_package.sublib.protocol".to_string(),
ApiBan {
msg: "The protocol module is deprecated.".to_string(),
},
),
]),
..Default::default()
},
namespace_packages: vec![Path::new("my_package").to_path_buf()],
..Settings::for_rules(vec![Rule::BannedApi])
},
)?;
assert_messages!(diagnostics);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
#[test]
fn ban_parent_imports_package() -> Result<()> {
let diagnostics = test_path(
Path::new("flake8_tidy_imports/TID252/my_package/sublib/api/application.py"),
Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"),
&Settings {
flake8_tidy_imports: super::super::Settings {
ban_relative_imports: Strictness::Parents,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs
---
application.py:3:8: TID251 `attrs` is banned: The attrs module is deprecated.
|
3 | from typing import TYPE_CHECKING, Any, ClassVar
4 |
5 | import attrs
| ^^^^^ TID251
6 |
7 | from ....import unknown
|

application.py:6:1: TID251 `my_package.sublib.protocol` is banned: The protocol module is deprecated.
|
6 | from ....import unknown
7 | from ..protocol import commands, definitions, responses
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251
8 | from ..server import example
9 | from .. import server
|

application.py:10:1: TID251 `my_package.sublib.protocol` is banned: The protocol module is deprecated.
|
10 | from .. import server
11 | from . import logger, models
12 | from ..protocol.UpperCaseModule import some_function
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251
|


0 comments on commit eed6866

Please sign in to comment.