Skip to content

Commit

Permalink
Fix two incorrect/broken tests in tests/checkers/unittest_imports.py (
Browse files Browse the repository at this point in the history
  • Loading branch information
akamat10 authored Sep 20, 2024
1 parent 56c64e5 commit c0fe1c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions tests/checkers/unittest_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pylint.checkers import imports
from pylint.interfaces import UNDEFINED
from pylint.lint import augmented_sys_path, discover_package_path
from pylint.testutils import CheckerTestCase, MessageTest
from pylint.testutils._run import _Run as Run

Expand Down Expand Up @@ -92,28 +93,33 @@ def test_relative_beyond_top_level_four(capsys: CaptureFixture[str]) -> None:
assert errors == ""

def test_wildcard_import_init(self) -> None:
module = astroid.MANAGER.ast_from_module_name("init_wildcard", REGR_DATA)
import_from = module.body[0]
context_file = os.path.join(REGR_DATA, "dummy_wildcard.py")

with self.assertNoMessages():
self.checker.visit_importfrom(import_from)
with augmented_sys_path([discover_package_path(context_file, [])]):
module = astroid.MANAGER.ast_from_module_name("init_wildcard", context_file)
import_from = module.body[0]

with self.assertNoMessages():
self.checker.visit_importfrom(import_from)

def test_wildcard_import_non_init(self) -> None:
module = astroid.MANAGER.ast_from_module_name("wildcard", REGR_DATA)
import_from = module.body[0]
context_file = os.path.join(REGR_DATA, "dummy_wildcard.py")

msg = MessageTest(
msg_id="wildcard-import",
node=import_from,
args="empty",
confidence=UNDEFINED,
line=1,
col_offset=0,
end_line=1,
end_col_offset=19,
)
with self.assertAddsMessages(msg):
self.checker.visit_importfrom(import_from)
with augmented_sys_path([discover_package_path(context_file, [])]):
module = astroid.MANAGER.ast_from_module_name("wildcard", context_file)
import_from = module.body[0]
msg = MessageTest(
msg_id="wildcard-import",
node=import_from,
args="empty",
confidence=UNDEFINED,
line=1,
col_offset=0,
end_line=1,
end_col_offset=19,
)
with self.assertAddsMessages(msg):
self.checker.visit_importfrom(import_from)

@staticmethod
def test_preferred_module(capsys: CaptureFixture[str]) -> None:
Expand Down
Empty file.

0 comments on commit c0fe1c5

Please sign in to comment.