diff options
Diffstat (limited to 'tests/test_pycode.py')
-rw-r--r-- | tests/test_pycode.py | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/tests/test_pycode.py b/tests/test_pycode.py index 152a92a27..2b5ae1514 100644 --- a/tests/test_pycode.py +++ b/tests/test_pycode.py @@ -63,20 +63,30 @@ def test_ModuleAnalyzer_find_tags(): ' """function baz"""\n' ' pass\n' '\n' - '@decorator\n' + '@decorator1\n' + '@decorator2\n' 'def quux():\n' - ' pass\n') + ' pass\n' # line: 21 + '\n' + 'class Corge(object):\n' + ' @decorator1\n' + ' @decorator2\n' + ' def grault(self):\n' + ' pass\n') analyzer = ModuleAnalyzer.for_string(code, 'module') tags = analyzer.find_tags() assert set(tags.keys()) == {'Foo', 'Foo.__init__', 'Foo.bar', - 'Foo.Baz', 'Foo.Baz.__init__', 'qux', 'quux'} - assert tags['Foo'] == ('class', 1, 13) # type, start, end - assert tags['Foo.__init__'] == ('def', 3, 5) - assert tags['Foo.bar'] == ('def', 6, 9) - assert tags['Foo.Baz'] == ('class', 10, 13) - assert tags['Foo.Baz.__init__'] == ('def', 11, 13) - assert tags['qux'] == ('def', 14, 17) - assert tags['quux'] == ('def', 18, 21) # decorator + 'Foo.Baz', 'Foo.Baz.__init__', 'qux', 'quux', + 'Corge', 'Corge.grault'} + assert tags['Foo'] == ('class', 1, 12) # type, start, end + assert tags['Foo.__init__'] == ('def', 3, 4) + assert tags['Foo.bar'] == ('def', 6, 8) + assert tags['Foo.Baz'] == ('class', 10, 12) + assert tags['Foo.Baz.__init__'] == ('def', 11, 12) + assert tags['qux'] == ('def', 14, 16) + assert tags['quux'] == ('def', 18, 21) + assert tags['Corge'] == ('class', 23, 27) + assert tags['Corge.grault'] == ('def', 24, 27) def test_ModuleAnalyzer_find_attr_docs(): @@ -114,6 +124,8 @@ def test_ModuleAnalyzer_find_attr_docs(): ('Foo', 'attr3'), ('Foo', 'attr4'), ('Foo', 'attr5'), + ('Foo', 'attr6'), + ('Foo', 'attr7'), ('Foo', 'attr8'), ('Foo', 'attr9')} assert docs[('Foo', 'attr1')] == ['comment before attr1', ''] @@ -121,19 +133,23 @@ def test_ModuleAnalyzer_find_attr_docs(): assert docs[('Foo', 'attr4')] == ['long attribute comment', ''] assert docs[('Foo', 'attr4')] == ['long attribute comment', ''] assert docs[('Foo', 'attr5')] == ['attribute comment for attr5', ''] + assert docs[('Foo', 'attr6')] == ['this comment is ignored', ''] + assert docs[('Foo', 'attr7')] == ['this comment is ignored', ''] assert docs[('Foo', 'attr8')] == ['attribute comment for attr8', ''] assert docs[('Foo', 'attr9')] == ['string after attr9', ''] assert analyzer.tagorder == {'Foo': 0, - 'Foo.__init__': 6, + 'Foo.__init__': 8, 'Foo.attr1': 1, 'Foo.attr2': 2, 'Foo.attr3': 3, 'Foo.attr4': 4, 'Foo.attr5': 5, - 'Foo.attr8': 8, - 'Foo.attr9': 10, - 'Foo.bar': 11, - 'baz': 12, - 'Qux': 13, - 'Qux.attr1': 14, - 'Qux.attr2': 15} + 'Foo.attr6': 6, + 'Foo.attr7': 7, + 'Foo.attr8': 10, + 'Foo.attr9': 12, + 'Foo.bar': 13, + 'baz': 14, + 'Qux': 15, + 'Qux.attr1': 16, + 'Qux.attr2': 17} |