-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
1948 Add Specifying Encoder Rule #2082
Open
GibranHL0
wants to merge
8
commits into
wemake-services:master
Choose a base branch
from
GibranHL0:issue-1948
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e467e1
1948 Add Specifying Encoder Rule
GibranHL0 7203962
Refactored Encoding Visitor
GibranHL0 9bc9033
Simplified code a little
sobolevn c5b458c
Changed encoders to eliminate warnings
GibranHL0 1b5b746
Merge branch 'issue-1948' of https://github.com/GibranHL0/wemake-pyth…
GibranHL0 30e0db9
Modified UnsepcifiedEncodingViolation error template
GibranHL0 84be594
Changed encoder to eliminate warnings
GibranHL0 98fc167
Rollback to utf-8
GibranHL0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/test_visitors/test_ast/test_attributes/test_open_encoding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import pytest | ||
|
||
from wemake_python_styleguide.violations.best_practices import ( | ||
UnspecifiedEncodingViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.attributes import EncodingVisitor | ||
|
||
unspecified_encoding_with = """ | ||
with open('filename.txt') as fd: | ||
fd.read() | ||
""" | ||
|
||
specified_encoding_with = """ | ||
with open('filename.txt', encoding='ascii') as fd: | ||
fd.read() | ||
""" | ||
|
||
unspecified_encoding_assign = """ | ||
file = open('filename.txt', 'r') | ||
""" | ||
|
||
specified_encoding_assign = """ | ||
file = open('filename.txt', 'r', encoding='utf8') | ||
""" | ||
|
||
specified_encoding_with_none = """ | ||
with open('filename.txt', encoding=None) as fd: | ||
fd.read() | ||
""" | ||
|
||
unspecified_encoding_with_multiple = """ | ||
with open('filename.txt', 'w', -1) as fd: | ||
fd.read() | ||
""" | ||
|
||
specified_encoding_with_multiple = """ | ||
with open('filename.txt', 'w', -1, None) as fd: | ||
fd.read() | ||
""" | ||
|
||
unspecified_encoding_assign_multiple = """ | ||
file = open('filename.txt', 'w', -1) | ||
""" | ||
|
||
specified_encoding_assign_multiple = """ | ||
file = open('filename.txt', 'w', -1, None) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
unspecified_encoding_with, | ||
unspecified_encoding_assign, | ||
unspecified_encoding_with_multiple, | ||
unspecified_encoding_assign_multiple, | ||
]) | ||
def test_unspecified_encoding( | ||
assert_errors, | ||
code, | ||
default_options, | ||
parse_ast_tree, | ||
): | ||
"""Testing open encoding is unspecified.""" | ||
tree = parse_ast_tree(code) | ||
visitor = EncodingVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [UnspecifiedEncodingViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
specified_encoding_with, | ||
specified_encoding_assign, | ||
specified_encoding_with_none, | ||
specified_encoding_with_multiple, | ||
specified_encoding_assign_multiple, | ||
]) | ||
def test_specified_encoding( | ||
assert_errors, | ||
code, | ||
default_options, | ||
parse_ast_tree, | ||
): | ||
"""Testing open encoding is specified.""" | ||
tree = parse_ast_tree(code) | ||
visitor = EncodingVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.