summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-03-29 08:07:15 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-03-29 08:07:15 -0500
commit425f89eee9a84da78a4a113bbdbd12214e6459d9 (patch)
treee9f47d29762120d1a1f96fc40db6935e1e76cad4
parent4ea161ff9c2160c4eea5d819f96c449c0edb0c10 (diff)
downloadflake8-425f89eee9a84da78a4a113bbdbd12214e6459d9.tar.gz
Add more tests around the processor module
-rw-r--r--flake8/processor.py11
-rw-r--r--tests/unit/test_file_processor.py40
2 files changed, 49 insertions, 2 deletions
diff --git a/flake8/processor.py b/flake8/processor.py
index bf96c7a..e71784c 100644
--- a/flake8/processor.py
+++ b/flake8/processor.py
@@ -370,6 +370,8 @@ def log_token(log, token):
token[1]))
+# NOTE(sigmavirus24): This was taken wholesale from
+# https://github.com/PyCQA/pycodestyle
def expand_indent(line):
r"""Return the amount of indentation.
@@ -397,6 +399,9 @@ def expand_indent(line):
return result
+# NOTE(sigmavirus24): This was taken wholesale from
+# https://github.com/PyCQA/pycodestyle. The in-line comments were edited to be
+# more descriptive.
def mutate_string(text):
"""Replace contents with 'xxx' to prevent syntax matching.
@@ -407,10 +412,12 @@ def mutate_string(text):
>>> mute_string("r'abc'")
"r'xxx'"
"""
- # String modifiers (e.g. u or r)
+ # NOTE(sigmavirus24): If there are string modifiers (e.g., b, u, r)
+ # use the last "character" to determine if we're using single or double
+ # quotes and then find the first instance of it
start = text.index(text[-1]) + 1
end = len(text) - 1
- # Triple quotes
+ # Check for triple-quoted strings
if text[-3:] in ('"""', "'''"):
start += 2
end -= 2
diff --git a/tests/unit/test_file_processor.py b/tests/unit/test_file_processor.py
index 027e74b..50c5fee 100644
--- a/tests/unit/test_file_processor.py
+++ b/tests/unit/test_file_processor.py
@@ -209,3 +209,43 @@ def test_inside_multiline():
assert file_processor.line_number == 10
assert file_processor.multiline is False
+
+
+@pytest.mark.parametrize('string, expected', [
+ ('""', '""'),
+ ("''", "''"),
+ ('"a"', '"x"'),
+ ("'a'", "'x'"),
+ ('"x"', '"x"'),
+ ("'x'", "'x'"),
+ ('"abcdef"', '"xxxxxx"'),
+ ("'abcdef'", "'xxxxxx'"),
+ ('""""""', '""""""'),
+ ("''''''", "''''''"),
+ ('"""a"""', '"""x"""'),
+ ("'''a'''", "'''x'''"),
+ ('"""x"""', '"""x"""'),
+ ("'''x'''", "'''x'''"),
+ ('"""abcdef"""', '"""xxxxxx"""'),
+ ("'''abcdef'''", "'''xxxxxx'''"),
+ ('"""xxxxxx"""', '"""xxxxxx"""'),
+ ("'''xxxxxx'''", "'''xxxxxx'''"),
+])
+def test_mutate_string(string, expected):
+ """Verify we appropriately mutate the string to sanitize it."""
+ actual = processor.mutate_string(string)
+ assert expected == actual
+
+
+@pytest.mark.parametrize('string, expected', [
+ (' ', 4),
+ (' ', 6),
+ ('\t', 8),
+ ('\t\t', 16),
+ (' \t', 8),
+ (' \t', 16),
+])
+def test_expand_indent(string, expected):
+ """Verify we correctly measure the amount of indentation."""
+ actual = processor.expand_indent(string)
+ assert expected == actual