-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Issue #1111 - Forbid to use \r in line breaks: Made base rule check and test script * Issue #1111 - Forbid to use \r in line breaks: updated CHANGELOG.md in this case * Issue #1111 - Forbid to use \r in line breaks: some minor processing * Issue #1111 - Forbid to use \r in line breaks: some minor processing [step2] * Issue #1111 - Forbid to use \r in line breaks: some minor processing [step3] * Issue #1111 ~~~: [step4] 'Repair test' by update WPS-record for new #noqa violation in #/tests/test_checker/test_noqa.py * Issue #1111 ~~~: [step5] by update WPS-record for new #noqa violation and it Count in #/tests/test_checker/test_noqa.py * Issue #1111 ~~~: [step6] by update WPS-record for new #noqa violation and chng it's Count to Zero in #/tests/test_checker/test_noqa.py * Issue #1111 ~~~: [step7] change sort order with CR-newline Violation(code=357) in #/violations/consistency.py * Issue #1111: fixed logical mistake with if-condition in #/visitors/tokenize/syntax.py * Issue #1111: add new condition in #/visitors/tokenize/syntax.py * Issue #1111: add new condition in #/visitors/tokenize/syntax.py * Issue #1111: add new condition in #/visitors/tokenize/syntax.py * Issue #1111: removed excess condition with 'line' variable in #/visitors/tokenize/syntax.py * Issue #1111: add new condition with token.line in #/visitors/tokenize/syntax.py (locally tested OK) * Fixes build Co-authored-by: ilia shb <45450122+jigi-33@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
130 additions
and
2 deletions.
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
79 changes: 79 additions & 0 deletions
79
tests/test_visitors/test_tokenize/test_consistency/test_string_newlines.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,79 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.consistency import ( | ||
LineCompriseCarriageReturnViolation, | ||
) | ||
from wemake_python_styleguide.visitors.tokenize.syntax import ( | ||
WrongKeywordTokenVisitor, | ||
) | ||
|
||
# Correct: | ||
|
||
correct_newline = 'print(1)\nprint(2)' | ||
correct_nl = 'print(1,\n 2)' | ||
correct_string = '"\r"' | ||
correct_raw_string = 'r"\r"' | ||
correct_real_newline = """ | ||
print(1) | ||
print(2) | ||
""" | ||
|
||
# Wrong: | ||
|
||
wrong_newline_single = 'print(1)\r\nprint(2)' | ||
wrong_newline_sequenced1 = 'print(1)\nprint(2)\r\n' | ||
wrong_newline_sequenced2 = 'print(1)\r\nprint(2)\n' | ||
wrong_newline_sequenced3 = 'print(1,\r\n 2)' | ||
wrong_newline_in_multiline = """print(2)\r | ||
print(3) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
wrong_newline_single, | ||
wrong_newline_sequenced1, | ||
wrong_newline_sequenced2, | ||
wrong_newline_sequenced3, | ||
wrong_newline_in_multiline, | ||
]) | ||
def test_string_wrong_line_breaks( | ||
parse_tokens, | ||
assert_errors, | ||
default_options, | ||
code, | ||
): | ||
"""Ensures that obsolete string's line break raise a violation.""" | ||
file_tokens = parse_tokens(code) | ||
|
||
visitor = WrongKeywordTokenVisitor( | ||
default_options, file_tokens=file_tokens, | ||
) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [LineCompriseCarriageReturnViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
correct_newline, | ||
correct_nl, | ||
correct_string, | ||
correct_raw_string, | ||
correct_real_newline, | ||
]) | ||
def test_string_proper_line_breaks( | ||
parse_tokens, | ||
assert_errors, | ||
default_options, | ||
code, | ||
): | ||
"""Ensures that proper string's line break are fine.""" | ||
file_tokens = parse_tokens(code) | ||
|
||
visitor = WrongKeywordTokenVisitor( | ||
default_options, file_tokens=file_tokens, | ||
) | ||
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