Skip to content

Commit a3f7585

Browse files
committed
Fix up testsuite for W504
1 parent 8f3aebd commit a3f7585

6 files changed

Lines changed: 37 additions & 42 deletions

File tree

pycodestyle.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,16 +1184,15 @@ def break_before_binary_operator(logical_line, tokens):
11841184
11851185
W503: (width == 0\n + height == 0)
11861186
W503: (width == 0\n and height == 0)
1187+
W503: var = (1\n & ~2)
1188+
W503: var = (1\n / -2)
1189+
W503: var = (1\n + -1\n + -2)
11871190
1188-
Okay: (width == 0 +\n height == 0)
11891191
Okay: foo(\n -x)
11901192
Okay: foo(x\n [])
11911193
Okay: x = '''\n''' + ''
11921194
Okay: foo(x,\n -y)
11931195
Okay: foo(x, # comment\n -y)
1194-
Okay: var = (1 &\n ~2)
1195-
Okay: var = (1 /\n -2)
1196-
Okay: var = (1 +\n -1 +\n -2)
11971196
"""
11981197
for context in _break_around_binary_operators(tokens):
11991198
(token_type, text, previous_token_type, previous_text,
@@ -1215,25 +1214,26 @@ def break_after_binary_operator(logical_line, tokens):
12151214
12161215
W504: (width == 0 +\n height == 0)
12171216
W504: (width == 0 and\n height == 0)
1217+
W504: var = (1 &\n ~2)
12181218
1219-
Okay: (width == 0\n + height == 0)
12201219
Okay: foo(\n -x)
12211220
Okay: foo(x\n [])
12221221
Okay: x = '''\n''' + ''
12231222
Okay: x = '' + '''\n'''
12241223
Okay: foo(x,\n -y)
12251224
Okay: foo(x, # comment\n -y)
1226-
Okay: var = (1\n & ~2)
1227-
Okay: var = (1\n / -2)
1228-
Okay: var = (1\n + -1\n + -2)
1225+
1226+
The following should be W504 but unary_context is tricky with these
1227+
Okay: var = (1 /\n -2)
1228+
Okay: var = (1 +\n -1 +\n -2)
12291229
"""
12301230
for context in _break_around_binary_operators(tokens):
12311231
(token_type, text, previous_token_type, previous_text,
12321232
line_break, unary_context, start) = context
1233-
if (_is_binary_operator(previous_token_type, previous_text)
1234-
and line_break
1235-
and not unary_context
1236-
and not _is_binary_operator(token_type, text)):
1233+
if (_is_binary_operator(previous_token_type, previous_text) and
1234+
line_break and
1235+
not unary_context and
1236+
not _is_binary_operator(token_type, text)):
12371237
error_pos = (start[0] - 1, start[1])
12381238
yield error_pos, "W504 line break after binary operator"
12391239

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ license_file = LICENSE
66

77
[pycodestyle]
88
select =
9-
ignore = E226,E24
9+
ignore = E226,E24,W504
1010
max_line_length = 79

testsuite/E12not.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
or y > 1 \
1717
or x == 3:
1818
pass
19-
20-
19+
#: W503
2120
if (foo == bar
2221
and baz == frop):
2322
pass
24-
23+
#: W503
2524
if (
2625
foo == bar
2726
and baz == frop
@@ -108,7 +107,7 @@
108107
'BBB' \
109108
'iii' \
110109
'CCC'
111-
110+
#: W504 W504
112111
abricot = (3 +
113112
4 +
114113
5 + 6)
@@ -137,8 +136,7 @@ def long_function_name(
137136
var_one, var_two, var_three,
138137
var_four):
139138
print(var_one)
140-
141-
139+
#: W504
142140
if ((row < 0 or self.moduleCount <= row or
143141
col < 0 or self.moduleCount <= col)):
144142
raise Exception("%s,%s - %s" % (row, col, self.moduleCount))
@@ -183,23 +181,23 @@ def long_function_name(
183181
"to match that of the opening "
184182
"bracket's line"
185183
)
186-
#
184+
#: W504
187185
# you want vertical alignment, so use a parens
188186
if ((foo.bar("baz") and
189187
foo.bar("frop")
190188
)):
191189
print "yes"
192-
190+
#: W504
193191
# also ok, but starting to look like LISP
194192
if ((foo.bar("baz") and
195193
foo.bar("frop"))):
196194
print "yes"
197-
195+
#: W504
198196
if (a == 2 or
199197
b == "abc def ghi"
200198
"jkl mno"):
201199
return True
202-
200+
#: W504
203201
if (a == 2 or
204202
b == """abc def ghi
205203
jkl mno"""):
@@ -223,22 +221,19 @@ def long_function_name(
223221
print('%-7d %s per second (%d total)' % (
224222
options.counters[key] / elapsed, key,
225223
options.counters[key]))
226-
227-
224+
#: W504
228225
if os.path.exists(os.path.join(path, PEP8_BIN)):
229226
cmd = ([os.path.join(path, PEP8_BIN)] +
230227
self._pep8_options(targetfile))
231-
232-
228+
#: W504
233229
fixed = (re.sub(r'\t+', ' ', target[c::-1], 1)[::-1] +
234230
target[c + 1:])
235-
231+
#: W504
236232
fixed = (
237233
re.sub(r'\t+', ' ', target[c::-1], 1)[::-1] +
238234
target[c + 1:]
239235
)
240-
241-
236+
#: W504
242237
if foo is None and bar is "frop" and \
243238
blah == 'yeah':
244239
blah = 'yeahnah'

testsuite/W19.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#: W191
88
y = x == 2 \
99
or x == 3
10-
#: E101 W191
10+
#: E101 W191 W504
1111
if (
1212
x == (
1313
3
@@ -26,11 +26,11 @@
2626
pass
2727
#:
2828

29-
#: E101 W191
29+
#: E101 W191 W504
3030
if (foo == bar and
3131
baz == frop):
3232
pass
33-
#: E101 W191
33+
#: E101 W191 W504
3434
if (
3535
foo == bar and
3636
baz == frop
@@ -52,7 +52,7 @@ def long_function_name(
5252
var_one, var_two, var_three,
5353
var_four):
5454
print(var_one)
55-
#: E101 W191
55+
#: E101 W191 W504
5656
if ((row < 0 or self.moduleCount <= row or
5757
col < 0 or self.moduleCount <= col)):
5858
raise Exception("%s,%s - %s" % (row, col, self.moduleCount))
@@ -65,23 +65,23 @@ def long_function_name(
6565
"bracket's line"
6666
)
6767
#
68-
#: E101 W191
68+
#: E101 W191 W504
6969
# you want vertical alignment, so use a parens
7070
if ((foo.bar("baz") and
7171
foo.bar("frop")
7272
)):
7373
print "yes"
74-
#: E101 W191
74+
#: E101 W191 W504
7575
# also ok, but starting to look like LISP
7676
if ((foo.bar("baz") and
7777
foo.bar("frop"))):
7878
print "yes"
79-
#: E101 W191
79+
#: E101 W191 W504
8080
if (a == 2 or
8181
b == "abc def ghi"
8282
"jkl mno"):
8383
return True
84-
#: E101 W191
84+
#: E101 W191 W504
8585
if (a == 2 or
8686
b == """abc def ghi
8787
jkl mno"""):
@@ -93,7 +93,7 @@ def long_function_name(
9393

9494

9595
#
96-
#: E101 W191 W191
96+
#: E101 W191 W191 W504
9797
if os.path.exists(os.path.join(path, PEP8_BIN)):
9898
cmd = ([os.path.join(path, PEP8_BIN)] +
9999
self._pep8_options(targetfile))

testsuite/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_own_dog_food(self):
4343
os.path.join(ROOT_DIR, 'setup.py')]
4444
report = self._style.init_report(pycodestyle.StandardReport)
4545
report = self._style.check_files(files)
46-
self.assertFalse(report.total_errors,
46+
self.assertEqual(list(report.messages.keys()), ['W504'],
4747
msg='Failures: %s' % report.messages)
4848

4949

testsuite/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_styleguide_options(self):
166166
self.assertEqual(pep8style.options.filename, ['*.py'])
167167
self.assertEqual(pep8style.options.format, 'default')
168168
self.assertEqual(pep8style.options.select, ())
169-
self.assertEqual(pep8style.options.ignore, ('E226', 'E24'))
169+
self.assertEqual(pep8style.options.ignore, ('E226', 'E24', 'W504'))
170170
self.assertEqual(pep8style.options.max_line_length, 79)
171171

172172
def test_styleguide_ignore_code(self):
@@ -182,7 +182,7 @@ def parse_argv(argstring):
182182
self.assertEqual(options.select, ())
183183
self.assertEqual(
184184
options.ignore,
185-
('E121', 'E123', 'E126', 'E226', 'E24', 'E704', 'W503')
185+
('E121', 'E123', 'E126', 'E226', 'E24', 'E704', 'W503', 'W504')
186186
)
187187

188188
options = parse_argv('--doctest').options

0 commit comments

Comments
 (0)