This repository was archived by the owner on Nov 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +38
-23
lines changed Expand file tree Collapse file tree 6 files changed +38
-23
lines changed Original file line number Diff line number Diff line change 1
- __author__ = 'rachum'
Original file line number Diff line number Diff line change 1
- __author__ = 'rachum'
Original file line number Diff line number Diff line change
1
+ class Expectation (object ):
2
+ """Hold expectation for pep257 violations in tests."""
3
+
4
+ def __init__ (self ):
5
+ self .expected = set ([])
6
+
7
+ def expect (self , * args ):
8
+ """Decorator that expects a certain PEP 257 violation."""
9
+ def none (_ ):
10
+ return None
11
+
12
+ if len (args ) == 1 :
13
+ return lambda f : (self .expected .add ((f .__name__ , args [0 ])) or
14
+ none (f ()) or f )
15
+ self .expected .add (args )
Original file line number Diff line number Diff line change 1
1
# encoding: utf-8
2
2
# No docstring, so we can test D100
3
3
import sys
4
- import os
4
+ from expected import Expectation
5
5
6
6
7
- expected = set ([])
8
-
9
-
10
- def expect (* args ):
11
- """Decorator that expects a certain PEP 257 violation."""
12
- def none (a ):
13
- return None
14
-
15
- if len (args ) == 1 :
16
- return lambda f : expected .add ((f .__name__ , args [0 ])) or none (f ()) or f
17
- expected .add (args )
18
-
7
+ expectation = Expectation ()
8
+ expect = expectation .expect
19
9
20
10
expect ('class_' , 'D101: Missing docstring in public class' )
21
11
Original file line number Diff line number Diff line change 2
2
"""This is a module."""
3
3
4
4
from __future__ import unicode_literals
5
+ from expected import Expectation
6
+
7
+
8
+ expectation = Expectation ()
9
+ expect = expectation .expect
5
10
6
11
7
12
def with_unicode_docstring_without_u ():
8
- """Check unicode: \u2611 ."""
13
+ r """Check unicode: \u2611."""
Original file line number Diff line number Diff line change @@ -127,10 +127,17 @@ def test_token_stream():
127
127
128
128
def test_pep257 ():
129
129
"""Run domain-specific tests from test.py file."""
130
- from .test_cases import test
131
- results = list (check ([os .path .join (os .path .dirname (__file__ ),
132
- 'test_cases' , 'test.py' )]))
133
- for error in results :
134
- assert isinstance (error , Error )
135
- results = set ([(e .definition .name , e .message ) for e in results ])
136
- assert test .expected == results
130
+ test_cases = ('test' , 'unicode_literals' )
131
+ for test_case in test_cases :
132
+ case_module = __import__ ('test_cases.{0}' .format (test_case ),
133
+ globals = globals (),
134
+ locals = locals (),
135
+ fromlist = ['expected' ],
136
+ level = 1 )
137
+ # from .test_cases import test
138
+ results = list (check ([os .path .join (os .path .dirname (__file__ ),
139
+ 'test_cases' , test_case + '.py' )]))
140
+ for error in results :
141
+ assert isinstance (error , Error )
142
+ results = set ([(e .definition .name , e .message ) for e in results ])
143
+ assert case_module .expectation .expected == results
You can’t perform that action at this time.
0 commit comments