Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix several tests related to constants #10013

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,16 @@ def error_msg_for_unequal_messages(
)
if missing:
msg.append("\nExpected in testdata:")
msg.extend(f" {msg[0]:3}: {msg[1]}" for msg in sorted(missing))
msg.extend(
f" {msg[0]:3}: {msg[1]} (times {times})"
for msg, times in sorted(missing.items())
)
if unexpected:
msg.append("\nUnexpected in testdata:")
msg.extend(f" {msg[0]:3}: {msg[1]}" for msg in sorted(unexpected))
msg.extend(
f" {msg[0]:3}: {msg[1]} (times {times})"
for msg, times in sorted(unexpected.items())
)
error_msg = "\n".join(msg)
if self._config and self._config.getoption("verbose") > 0:
error_msg += "\n\nActual pylint output for this file:\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/checkers/unittest_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestVariablesChecker(CheckerTestCase):

def test_all_elements_without_parent(self) -> None:
node = astroid.extract_node("__all__ = []")
node.value.elts.append(astroid.Const("test"))
node.value.elts.append(astroid.Const("test", parent=None))
root = node.root()
with self.assertNoMessages():
self.checker.visit_module(root)
Comment on lines 23 to 28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good test. Why should adding a constant not result in messages? That's just asserting implementation quirks. We should test the opposite, we should test that synthetic constants result in the same messages.
IMO

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [line-too-long, missing-module-docstring, undefined-all-variable, undefined-all-variable, undefined-all-variable, undefined-all-variable, undefined-all-variable]
# ↓ equivalent to __all__ = ["C", "O", "N", "S", "T"]
__all__ = list("CONST")
#
CONST = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
line-too-long:1:0:None:None::Line too long (163/100):UNDEFINED
missing-module-docstring:1:0:None:None::Missing module docstring:HIGH
undefined-all-variable:1:0:None:None::Undefined variable name 'C' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'N' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'O' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'S' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'T' in __all__:UNDEFINED
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [line-too-long, missing-module-docstring, undefined-all-variable, undefined-all-variable, undefined-all-variable, undefined-all-variable, undefined-all-variable]
# ↓ equivalent to __all__ = ("C", "O", "N", "S", "T")
__all__ = tuple("CONST")

CONST = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
line-too-long:1:0:None:None::Line too long (163/100):UNDEFINED
missing-module-docstring:1:0:None:None::Missing module docstring:HIGH
undefined-all-variable:1:0:None:None::Undefined variable name 'C' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'N' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'O' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'S' in __all__:UNDEFINED
undefined-all-variable:1:0:None:None::Undefined variable name 'T' in __all__:UNDEFINED
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test valid __all__ format."""
__all__ = list("CONST")

__all__ = list(["CONST"])

CONST = 42
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test valid __all__ format."""
__all__ = tuple("CONST")

__all__ = tuple(["CONST"])

CONST = 42
Loading