Skip to content

Commit

Permalink
Add test for nested no-infer-dep in Rust Python dep inference (Cherry…
Browse files Browse the repository at this point in the history
…-pick of #19804) (#19808)

This closes #19751 by adding some tests for it. We're pretty sure the
real fix was in #19293, but only incidentally, so this PR makes sure
we've got a regression test specifically for #19751.

I've marked the test for cherrypicking so that we confirm that this is
fixed in the earlier releases too.

Co-authored-by: Huon Wilson <[email protected]>
  • Loading branch information
WorkerPants and huonw authored Sep 9, 2023
1 parent 6cbb564 commit eb33c20
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/rust/engine/dep_inference/src/python/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,48 @@ fn pragma_ignore() {
* # pants: no-infer-dep",
&[],
);
// Imports nested within other constructs
assert_imports(
r"
if x:
import a # pants: no-infer-dep
",
&[],
);
assert_imports(
r"
if x:
import a # pants: no-infer-dep
import b
",
&["b"],
);
assert_imports(
r"
class X: def method(): if True: while True: class Y: def f(): import a # pants: no-infer-dep
",
&[],
);
assert_imports(
r"
if x:
import \
a # pants: no-infer-dep
",
&[],
);

// https://github.com/pantsbuild/pants/issues/19751
assert_imports(
r"
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from a import ClassA # pants: no-infer-dep
print('Hello, world!')",
&["typing.TYPE_CHECKING"],
);
}

#[test]
Expand Down

0 comments on commit eb33c20

Please sign in to comment.