Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 08a0869

Browse files
committed
Merge pull request #85 from Nurdok/fix-skipped-tests
Fixed skipped test
2 parents 82950c0 + 4da947c commit 08a0869

File tree

4 files changed

+42
-226
lines changed

4 files changed

+42
-226
lines changed

pep257.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,26 @@ def parse_all(self):
267267
"assuming __all__ is not mutated.\n" % self.filename)
268268
sys.stderr.write(msg)
269269
self.consume(tk.OP)
270-
s = '('
271-
while self.current.kind in (tk.NL, tk.COMMENT):
272-
self.stream.move()
273-
if self.current.kind != tk.STRING:
274-
raise AllError('Could not evaluate contents of __all__. ')
275-
while self.current.value not in ')]':
276-
s += self.current.value
270+
271+
self.all = []
272+
all_content = "("
273+
while self.current.kind != tk.OP or self.current.value not in ")]":
274+
if self.current.kind in (tk.NL, tk.COMMENT):
275+
pass
276+
elif (self.current.kind == tk.STRING or
277+
self.current.value == ','):
278+
all_content += self.current.value
279+
else:
280+
raise AllError('Could not evaluate contents of __all__. ')
277281
self.stream.move()
278-
s += ')'
282+
self.consume(tk.OP)
283+
all_content += ")"
279284
try:
280-
self.all = eval(s, {})
281-
except BaseException:
282-
raise AllError('Could not evaluate contents of __all__: %s. ' % s)
285+
self.all = eval(all_content, {})
286+
except BaseException as e:
287+
raise AllError('Could not evaluate contents of __all__.'
288+
'\bThe value was %s. The exception was:\n%s'
289+
% (all_content, e))
283290

284291
def parse_module(self):
285292
"""Parse a module (and its children) and return a Module object."""

test_definitions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def nested_3(self):
3838

3939

4040
def test_parser():
41-
all = ('a', 'bc')
41+
dunder_all = ('a', 'bc')
4242
module = parse(StringIO(source), 'file.py')
4343
assert len(list(module)) == 8
4444
assert Module('file.py', _, 1, len(source.split('\n')),
45-
'"""Module."""', _, _, all) == module
45+
'"""Module."""', _, _, dunder_all) == module
4646

4747
function, class_ = module.children
4848
assert Function('function', _, _, _, '"Function."', _, module) == function
@@ -63,16 +63,16 @@ def test_parser():
6363
assert NestedFunction('nested_3', _, _, _,
6464
'"""Nested."""', _, method_2) == nested_3
6565
assert nested_3.module == module
66-
assert nested_3.all == all
66+
assert nested_3.all == dunder_all
6767

6868
module = parse(StringIO(source_alt), 'file_alt.py')
6969
assert Module('file_alt.py', _, 1, len(source_alt.split('\n')),
70-
None, _, _, all) == module
70+
None, _, _, dunder_all) == module
7171

7272
module = parse(StringIO(source_alt_nl_at_bracket), 'file_alt_nl.py')
7373
assert Module('file_alt_nl.py', _, 1,
7474
len(source_alt_nl_at_bracket.split('\n')), None, _, _,
75-
all) == module
75+
dunder_all) == module
7676

7777

7878
def _test_module():

test_pep257.py

Lines changed: 18 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -2,223 +2,32 @@
22
# -*- coding: utf-8 -*-
33
from __future__ import with_statement
44

5-
from pytest import skip
6-
75
import pep257
6+
import mock
87

98

10-
__all__ = []
9+
__all__ = ()
1110

1211

13-
@skip
1412
def test_pep257_conformance():
1513
errors = list(pep257.check(['pep257.py', 'test_pep257.py']))
1614
print(errors)
17-
assert len(errors) == 0
18-
19-
20-
def test_get_summary_line_info():
21-
s1 = '''"""First line summary."""'''
22-
s2 = '''"""First line summary.
23-
With subsequent line.
24-
"""'''
25-
s3 = '''""""""'''
26-
s4 = '''"""
27-
Second line summary.
28-
"""'''
29-
s5 = '''"""
30-
Second line summary.
31-
With subsquent line.
32-
"""'''
33-
assert pep257.get_summary_line_info(s1) == ('First line summary.', 0)
34-
assert pep257.get_summary_line_info(s2) == ('First line summary.', 0)
35-
assert pep257.get_summary_line_info(s3) == ('', 0)
36-
assert pep257.get_summary_line_info(s4) == ('Second line summary.', 1)
37-
assert pep257.get_summary_line_info(s5) == ('Second line summary.', 1)
38-
39-
40-
def test_parse_docstring():
41-
s1 = '''def foo(): # o hai comment
42-
"""docstring"""
43-
2 + 2'''
44-
assert pep257.parse_docstring(s1) == '"""docstring"""'
45-
46-
s2 = '''def foo(): # o hai comment
47-
2 + 2'''
48-
assert pep257.parse_docstring(s2) is None
49-
50-
assert pep257.parse_docstring("def foo():pass") is None
51-
# TODO
52-
# assert pep257.parse_docstring("def bar():'doc';pass") == "'doc'"
53-
54-
55-
def test_abs_pos():
56-
assert pep257.abs_pos((1, 0), 'foo') == 0
57-
assert pep257.abs_pos((1, 2), 'foo') == 2
58-
assert pep257.abs_pos((2, 0), 'foo\nbar') == 4
59-
60-
61-
def test_rel_pos():
62-
assert pep257.rel_pos(0, 'foo') == (1, 0)
63-
assert pep257.rel_pos(2, 'foo') == (1, 2)
64-
assert pep257.rel_pos(4, 'foo\nbar') == (2, 0)
65-
assert pep257.rel_pos(6, 'foo\nbar') == (2, 2)
66-
67-
68-
def test_parse_functions():
69-
parse = pep257.parse_functions
70-
assert parse('') == []
71-
# TODO assert pf('def foo():pass') == ['def foo():pass']
72-
assert parse('def foo():\n pass\n') == ['def foo():\n pass\n']
73-
assert parse('def foo():\n pass') == ['def foo():\n pass']
74-
f1 = '''def foo():\n pass\ndef bar():\n pass'''
75-
assert parse(f1) == ['def foo():\n pass\n',
76-
'def bar():\n pass']
77-
f2 = '''def foo():\n pass\noh, hai\ndef bar():\n pass'''
78-
assert parse(f2) == ['def foo():\n pass\n',
79-
'def bar():\n pass']
80-
81-
82-
def test_parse_methods():
83-
parse = pep257.parse_methods
84-
assert parse('') == []
85-
m1 = '''class Foo:
86-
def m1():
87-
pass
88-
def m2():
89-
pass'''
90-
assert parse(m1) == ['def m1():\n pass\n ',
91-
'def m2():\n pass']
92-
m2 = '''class Foo:
93-
def m1():
94-
pass
95-
attribute
96-
def m2():
97-
pass'''
98-
assert parse(m2) == ['def m1():\n pass\n ',
99-
'def m2():\n pass']
100-
101-
102-
def test_check_triple_double_quotes():
103-
check = pep257.check_triple_double_quotes
104-
assert check("'''Not using triple douple quotes'''", None, None)
105-
assert not check('"""Using triple double quotes"""', None, None)
106-
assert not check('r"""Using raw triple double quotes"""', None, None)
107-
assert not check('u"""Using unicode triple double quotes"""', None, None)
108-
109-
110-
def test_check_backslashes():
111-
check = pep257.check_backslashes
112-
assert check('"""backslash\\here""""', None, None)
113-
assert not check('r"""backslash\\here""""', None, None)
114-
115-
116-
def test_check_unicode_docstring():
117-
check = pep257.check_unicode_docstring
118-
assert not check('"""No Unicode here."""', None, None)
119-
assert not check('u"""Здесь Юникод: øπΩ≈ç√∫˜µ≤"""', None, None)
120-
assert check('"""Здесь Юникод: øπΩ≈ç√∫˜µ≤"""', None, None)
121-
122-
123-
def test_check_ends_with_period():
124-
check = pep257.check_ends_with_period
125-
s1 = '"""Should end with a period"""'
126-
s2 = '"""Should end with a period."""'
127-
s3 = '''"""
128-
Should end with a period
129-
"""'''
130-
s4 = '''"""
131-
Should end with a period.
132-
"""'''
133-
assert check(s1, None, None)
134-
assert not check(s2, None, None)
135-
assert check(s3, None, None)
136-
assert not check(s4, None, None)
137-
138-
139-
def test_check_blank_before_after_class():
140-
check = pep257.check_blank_before_after_class
141-
c1 = '''class Perfect(object):
142-
143-
"""This should work perfectly."""
144-
145-
pass'''
146-
assert not check('"""This should work perfectly."""', c1, False)
147-
148-
c2 = '''class BadTop(object):
149-
"""This should fail due to a lack of whitespace above."""
150-
151-
pass'''
152-
assert check('"""This should fail due to a lack of whitespace above."""',
153-
c2, False)
154-
c3 = '''class BadBottom(object):
155-
156-
"""This should fail due to a lack of whitespace below."""
157-
pass'''
158-
assert check('"""This should fail due to a lack of whitespace below."""',
159-
c3, False)
160-
c4 = '''class GoodWithNoFollowingWhiteSpace(object):
161-
162-
"""This should work."""'''
163-
assert not check('"""This should work."""',
164-
c4, False)
165-
c5 = '''class GoodWithFollowingWhiteSpace(object):
166-
167-
"""This should work."""
168-
169-
170-
'''
171-
assert not check('"""This should work."""', c5, False)
172-
173-
c6 = '''class Perfect(object):
174-
175-
"""This should work perfectly."""
176-
177-
def foo(self):
178-
"""This should work perfectly."""
179-
pass
180-
181-
'''
182-
assert not check('"""This should work perfectly."""', c6, False)
183-
184-
185-
def test_check_blank_after_summary():
186-
check = pep257.check_blank_after_summary
187-
s1 = '''"""Blank line missing after one-line summary.
188-
....................
189-
"""'''
190-
s2 = '''"""Blank line missing after one-line summary.
191-
192-
"""'''
193-
s3 = '''"""
194-
Blank line missing after one-line summary.
195-
....................
196-
"""'''
197-
s4 = '''"""
198-
Blank line missing after one-line summary.
199-
200-
"""'''
201-
assert check(s1, None, None)
202-
assert not check(s2, None, None)
203-
assert check(s3, None, None)
204-
assert not check(s4, None, None)
205-
206-
207-
def test_check_indent():
208-
check = pep257.check_indent
209-
context = '''def foo():
210-
"""Docstring.
211-
212-
Properly indented.
213-
214-
"""
215-
pass'''
216-
assert not check('"""%s"""' % context.split('"""')[1], context, None)
217-
context = '''def foo():
218-
"""Docstring.
15+
assert errors == []
21916

220-
Not Properly indented.
22117

18+
def test_ignore_list():
19+
function_to_check = """def function_with_bad_docstring(foo):
20+
\"\"\" does spacing without a period in the end
21+
no blank line after one-liner is bad. Also this - \"\"\"
22+
return foo
22223
"""
223-
pass'''
224-
assert check('"""%s"""' % context.split('"""')[1], context, None)
24+
expected_error_codes = set(('D100', 'D400', 'D401', 'D205', 'D209'))
25+
mock_open = mock.mock_open(read_data=function_to_check)
26+
with mock.patch('pep257.open', mock_open, create=True):
27+
errors = tuple(pep257.check(['filepath']))
28+
error_codes = set(error.code for error in errors)
29+
assert error_codes == expected_error_codes
30+
31+
errors = tuple(pep257.check(['filepath'], ignore=['D100', 'D202']))
32+
error_codes = set(error.code for error in errors)
33+
assert error_codes == expected_error_codes - set(('D100', 'D202'))

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
envlist = py26, py27, py32, py33, py34, pypy, pypy3
88

99
[testenv]
10-
commands = py.test --pep8
10+
commands = py.test --pep8 --clearcache
1111
deps = pytest
1212
pytest-pep8
1313
mock

0 commit comments

Comments
 (0)