Skip to content

Commit 416e985

Browse files
committed
Add a failing test
1 parent 2f54d05 commit 416e985

File tree

1 file changed

+33
-1
lines changed
  • crates/ruff_linter/src/rules/pyflakes

1 file changed

+33
-1
lines changed

crates/ruff_linter/src/rules/pyflakes/mod.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod tests {
1111

1212
use anyhow::Result;
1313
use regex::Regex;
14+
use rustc_hash::FxHashMap;
1415

1516
use test_case::test_case;
1617

@@ -24,11 +25,12 @@ mod tests {
2425

2526
use crate::linter::check_path;
2627
use crate::registry::{AsRule, Linter, Rule};
28+
use crate::rules::isort;
2729
use crate::rules::pyflakes;
2830
use crate::settings::types::PreviewMode;
2931
use crate::settings::{flags, LinterSettings};
3032
use crate::source_kind::SourceKind;
31-
use crate::test::{test_path, test_snippet};
33+
use crate::test::{test_contents, test_path, test_snippet};
3234
use crate::{assert_messages, directives};
3335

3436
#[test_case(Rule::UnusedImport, Path::new("F401_0.py"))]
@@ -232,6 +234,36 @@ mod tests {
232234
Ok(())
233235
}
234236

237+
#[test_case(
238+
r"
239+
import submodule.a
240+
__all__ = ['FOO']
241+
FOO = 42",
242+
"f401_preview_first_party_submodule"
243+
)]
244+
fn f401_preview_first_party_submodule(contents: &str, snapshot: &str) {
245+
let diagnostics = test_contents(
246+
&SourceKind::Python(dedent(contents).to_string()),
247+
Path::new("__init__.py"),
248+
&LinterSettings {
249+
preview: PreviewMode::Enabled,
250+
isort: isort::settings::Settings {
251+
known_modules: isort::categorize::KnownModules::new(
252+
vec!["submodule".parse().unwrap()],
253+
vec![],
254+
vec![],
255+
vec![],
256+
FxHashMap::default(),
257+
),
258+
..isort::settings::Settings::default()
259+
},
260+
..LinterSettings::for_rule(Rule::UnusedImport)
261+
},
262+
)
263+
.0;
264+
assert_messages!(snapshot, diagnostics);
265+
}
266+
235267
#[test_case(Rule::UnusedImport, Path::new("F401_24/__init__.py"))]
236268
#[test_case(Rule::UnusedImport, Path::new("F401_25__all_nonempty/__init__.py"))]
237269
#[test_case(Rule::UnusedImport, Path::new("F401_26__all_empty/__init__.py"))]

0 commit comments

Comments
 (0)