-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Issue 3267: fixed wps226 location #3269
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! We also need a test case for that. You can probably use ._location()
in any of the existing tests.
@@ -67,6 +67,11 @@ def __init__(self, *args, **kwargs) -> None: | |||
int, | |||
] = defaultdict(int) | |||
|
|||
self._string_constants_first_node: defaultdict[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be self._string_constants_first_node: ast.AST | None = None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain the idea, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need the first node, right? We don't need all nodes. So, we can only save the first node here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. And it is done so. For each string their first nodes are collected in dict.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3269 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 357 357
Lines 11703 11715 +12
Branches 801 802 +1
=========================================
+ Hits 11703 11715 +12 ☔ View full report in Codecov by Sentry. |
tests/test_visitors/conftest.py
Outdated
if ignored_types: | ||
real_errors = [ | ||
error | ||
for error in visitor.violations | ||
if not isinstance(error, ignored_types) | ||
] | ||
else: | ||
real_errors = visitor.violations | ||
|
||
for violation in real_errors: | ||
assert violation._location() != (0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ignored_types: | |
real_errors = [ | |
error | |
for error in visitor.violations | |
if not isinstance(error, ignored_types) | |
] | |
else: | |
real_errors = visitor.violations | |
for violation in real_errors: | |
assert violation._location() != (0, 0) | |
assert len(visitor.violations) == 1 | |
violation = visitor.violations[0] | |
assert violation._location() == expected |
tests/test_visitors/conftest.py
Outdated
def factory( | ||
visitor: BaseVisitor, | ||
ignored_types: _IgnoredTypes = None, | ||
) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def factory( | |
visitor: BaseVisitor, | |
ignored_types: _IgnoredTypes = None, | |
) -> None: | |
def factory( | |
visitor: BaseVisitor, | |
expected: tuple[int, int], | |
) -> None: |
@@ -177,6 +178,7 @@ def test_string_overuse( | |||
string_value.replace('"', '') or "''", | |||
default_options.max_string_usages, | |||
) | |||
assert_violation_location(visitor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_violation_location(visitor, (X, Y))
@@ -67,6 +67,11 @@ def __init__(self, *args, **kwargs) -> None: | |||
int, | |||
] = defaultdict(int) | |||
|
|||
self._string_constants_first_node: defaultdict[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need the first node, right? We don't need all nodes. So, we can only save the first node here.
Problem is slightly more trickier than I thought. |
@@ -178,7 +181,7 @@ def test_string_overuse( | |||
string_value.replace('"', '') or "''", | |||
default_options.max_string_usages, | |||
) | |||
assert_violation_location(visitor) | |||
assert_error_location(visitor, expected_location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just create a single test with known location? Like x = 'abc'
and have it as a constant? Like (1, 4)
? Right now it seems too complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you!
I have made things!
Checklist
CHANGELOG.md
Related issues
🙏 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.