Skip to content

Commit

Permalink
Add (failing) tests for the erroneous scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
asfaltboy committed Oct 25, 2016
1 parent 64ad28a commit 9f68faa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
20 changes: 17 additions & 3 deletions test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class TestParser(ast.NodeVisitor):
>>> list(set(map(parser.parse, (21, 22))))
[(None, 'func_test')]
# nested classes are allowed
>>> list(set(map(parser.parse, (25, 26, 27, 28, 31))))
[('ParentClass', None)]
[('ParentClassA', None)]
>>> list(set(map(parser.parse, (29, 30))))
[('ParentClass', None)]
[('ParentClassA', None)]
>>> list(set(map(parser.parse, (32, 33))))
[('ParentClass', 'parent_method')]
[('ParentClassA', 'parent_method')]
# test decorated test case and decorated method
>>> list(set(map(parser.parse, range(41, 44))))
Expand All @@ -66,6 +67,19 @@ class TestParser(ast.NodeVisitor):
>>> parser = TestParser(source=module_source)
>>> parser.parse(line=2)
(None, 'test_first')
# classes defined in test are ignored
>>> list(set(map(parser.parse, (54, 55, 56))))
[('ParentClassB', None)]
>>> list(set(map(parser.parse, (57, 58))))
[('ParentClassB', 'test_foo')]
>>> list(set(map(parser.parse, (60, 61, 63, 67, 68, ))))
[('ParentClassB', 'test_a')]
>>> list(set(map(parser.parse, (70, 71))))
[('ParentClassB', 'test_b')]
"""
nested_class = None

Expand Down
24 changes: 23 additions & 1 deletion tests/_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def func_test():
pass


class ParentClass(AnotherClass):
class ParentClassA(AnotherClass):
class ChildClass:
nested_property = True

Expand All @@ -49,3 +49,25 @@ def test_me(self):
class ParentInModuleClass(mymodule.TestClass):
def test_me(self):
pass


class ParentClassB(TestClass):
foo = 1

def test_foo(self):
pass

def test_a(self):
class ChildClass(object):
nested_property = True

def child_method(self):
pass

another_attribute = 'foo'

cl = ChildClass()
assert cl.nested_property

def test_b(self):
pass

0 comments on commit 9f68faa

Please sign in to comment.