6
6
import unittest
7
7
8
8
import pycodestyle
9
- from testsuite .support import InMemoryReport
9
+ from testsuite .support import errors_from_src
10
10
11
11
12
12
class BlankLinesTestCase (unittest .TestCase ):
13
13
"""
14
14
Common code for running blank_lines tests.
15
15
"""
16
16
17
- def check (self , content ):
18
- """
19
- Run checks on `content` and return the the list of errors.
20
- """
21
- sut = pycodestyle .StyleGuide ()
22
- reporter = sut .init_report (InMemoryReport )
23
- sut .input_file (
24
- filename = 'in-memory-test-file.py' ,
25
- lines = content .splitlines (True ),
26
- )
27
- return reporter .in_memory_errors
28
-
29
17
def assertNoErrors (self , actual ):
30
18
"""
31
19
Check that the actual result from the checker has no errors.
@@ -43,7 +31,7 @@ def test_initial_no_blank(self):
43
31
"""
44
32
It will accept no blank lines at the start of the file.
45
33
"""
46
- result = self . check ("""def some_function():
34
+ result = errors_from_src ("""def some_function():
47
35
pass
48
36
""" )
49
37
@@ -54,7 +42,7 @@ def test_initial_lines_one_blank(self):
54
42
It will accept 1 blank lines before the first line of actual
55
43
code, even if in other places it asks for 2
56
44
"""
57
- result = self . check ("""
45
+ result = errors_from_src ("""
58
46
def some_function():
59
47
pass
60
48
""" )
@@ -66,7 +54,7 @@ def test_initial_lines_two_blanks(self):
66
54
It will accept 2 blank lines before the first line of actual
67
55
code, as normal.
68
56
"""
69
- result = self . check ("""
57
+ result = errors_from_src ("""
70
58
71
59
def some_function():
72
60
pass
@@ -79,7 +67,7 @@ def test_method_less_blank_lines(self):
79
67
It will trigger an error when less than 1 blank lin is found
80
68
before method definitions.
81
69
"""
82
- result = self . check ("""# First comment line.
70
+ result = errors_from_src ("""# First comment line.
83
71
class X:
84
72
85
73
def a():
@@ -96,7 +84,7 @@ def test_method_less_blank_lines_comment(self):
96
84
It will trigger an error when less than 1 blank lin is found
97
85
before method definition, ignoring comments.
98
86
"""
99
- result = self . check ("""# First comment line.
87
+ result = errors_from_src ("""# First comment line.
100
88
class X:
101
89
102
90
def a():
@@ -114,7 +102,7 @@ def test_top_level_fewer_blank_lines(self):
114
102
It will trigger an error when less 2 blank lines are found
115
103
before top level definitions.
116
104
"""
117
- result = self . check ("""# First comment line.
105
+ result = errors_from_src ("""# First comment line.
118
106
# Second line of comment.
119
107
120
108
def some_function():
@@ -148,7 +136,7 @@ def test_top_level_more_blank_lines(self):
148
136
It will trigger an error when more 2 blank lines are found
149
137
before top level definitions.
150
138
"""
151
- result = self . check ("""# First comment line.
139
+ result = errors_from_src ("""# First comment line.
152
140
# Second line of comment.
153
141
154
142
@@ -179,7 +167,7 @@ def test_method_more_blank_lines(self):
179
167
It will trigger an error when more than 1 blank line is found
180
168
before method definition
181
169
"""
182
- result = self . check ("""# First comment line.
170
+ result = errors_from_src ("""# First comment line.
183
171
184
172
185
173
class SomeCloseClass(object):
@@ -211,7 +199,7 @@ def test_initial_lines_more_blank(self):
211
199
It will trigger an error for more than 2 blank lines before the
212
200
first line of actual code.
213
201
"""
214
- result = self . check ("""
202
+ result = errors_from_src ("""
215
203
216
204
217
205
def some_function():
@@ -224,7 +212,7 @@ def test_blank_line_between_decorator(self):
224
212
It will trigger an error when the decorator is followed by a
225
213
blank line.
226
214
"""
227
- result = self . check ("""# First line.
215
+ result = errors_from_src ("""# First line.
228
216
229
217
230
218
@some_decorator
@@ -247,7 +235,7 @@ def test_blank_line_decorator(self):
247
235
It will accept the decorators which are adjacent to the function
248
236
and method definition.
249
237
"""
250
- result = self . check ("""# First line.
238
+ result = errors_from_src ("""# First line.
251
239
252
240
253
241
@another_decorator
@@ -269,7 +257,7 @@ def test_top_level_fewer_follow_lines(self):
269
257
It will trigger an error when less than 2 blank lines are
270
258
found between a top level definitions and other top level code.
271
259
"""
272
- result = self . check ("""
260
+ result = errors_from_src ("""
273
261
def a():
274
262
print('Something')
275
263
@@ -285,7 +273,7 @@ def test_top_level_fewer_follow_lines_comments(self):
285
273
found between a top level definitions and other top level code,
286
274
even if we have comments before
287
275
"""
288
- result = self . check ("""
276
+ result = errors_from_src ("""
289
277
def a():
290
278
print('Something')
291
279
@@ -306,7 +294,7 @@ def test_top_level_good_follow_lines(self):
306
294
It not trigger an error when 2 blank lines are
307
295
found between a top level definitions and other top level code.
308
296
"""
309
- result = self . check ("""
297
+ result = errors_from_src ("""
310
298
def a():
311
299
print('Something')
312
300
@@ -326,7 +314,7 @@ def test_method_fewer_follow_lines(self):
326
314
It will trigger an error when less than 1 blank line is
327
315
found between a method and previous definitions.
328
316
"""
329
- result = self . check ("""
317
+ result = errors_from_src ("""
330
318
def a():
331
319
x = 1
332
320
def b():
@@ -342,7 +330,7 @@ def test_method_nested_fewer_follow_lines(self):
342
330
found between a method and previous definitions, even when
343
331
nested.
344
332
"""
345
- result = self . check ("""
333
+ result = errors_from_src ("""
346
334
def a():
347
335
x = 2
348
336
@@ -361,7 +349,7 @@ def test_method_nested_less_class(self):
361
349
between a method and previous definitions, even when used to
362
350
define a class.
363
351
"""
364
- result = self . check ("""
352
+ result = errors_from_src ("""
365
353
def a():
366
354
x = 1
367
355
class C:
@@ -377,7 +365,7 @@ def test_method_nested_ok(self):
377
365
found between a method and previous definitions, even when
378
366
nested.
379
367
"""
380
- result = self . check ("""
368
+ result = errors_from_src ("""
381
369
def a():
382
370
x = 2
383
371
@@ -412,7 +400,7 @@ def test_initial_lines_one_blanks(self):
412
400
It will accept less than 3 blank lines before the first line of
413
401
actual code.
414
402
"""
415
- result = self . check ("""
403
+ result = errors_from_src ("""
416
404
417
405
418
406
def some_function():
@@ -426,7 +414,7 @@ def test_initial_lines_tree_blanks(self):
426
414
It will accept 3 blank lines before the first line of actual
427
415
code, as normal.
428
416
"""
429
- result = self . check ("""
417
+ result = errors_from_src ("""
430
418
431
419
432
420
def some_function():
@@ -440,7 +428,7 @@ def test_top_level_fewer_blank_lines(self):
440
428
It will trigger an error when less 3 blank lines are found
441
429
before top level definitions.
442
430
"""
443
- result = self . check ("""# First comment line.
431
+ result = errors_from_src ("""# First comment line.
444
432
# Second line of comment.
445
433
446
434
@@ -479,7 +467,7 @@ def test_top_level_more_blank_lines(self):
479
467
It will trigger an error when more 2 blank lines are found
480
468
before top level definitions.
481
469
"""
482
- result = self . check ("""# First comment line.
470
+ result = errors_from_src ("""# First comment line.
483
471
# Second line of comment.
484
472
485
473
@@ -513,7 +501,7 @@ def test_the_right_blanks(self):
513
501
"""
514
502
It will accept 3 blank for top level and 2 for nested.
515
503
"""
516
- result = self . check ("""
504
+ result = errors_from_src ("""
517
505
518
506
519
507
def some_function():
0 commit comments