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

Commit b9c2536

Browse files
committed
More test refactoring.
1 parent 5db0695 commit b9c2536

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

src/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
__author__ = 'rachum'

src/tests/test_cases/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
__author__ = 'rachum'

src/tests/test_cases/expected.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)

src/tests/test_cases/test.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
# encoding: utf-8
22
# No docstring, so we can test D100
33
import sys
4-
import os
4+
from expected import Expectation
55

66

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
199

2010
expect('class_', 'D101: Missing docstring in public class')
2111

src/tests/test_cases/unicode_literals.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"""This is a module."""
33

44
from __future__ import unicode_literals
5+
from expected import Expectation
6+
7+
8+
expectation = Expectation()
9+
expect = expectation.expect
510

611

712
def with_unicode_docstring_without_u():
8-
"""Check unicode: \u2611."""
13+
r"""Check unicode: \u2611."""

src/tests/test_definitions.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,17 @@ def test_token_stream():
127127

128128
def test_pep257():
129129
"""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

0 commit comments

Comments
 (0)