| 224 | |
| 225 | |
| 226 | def test_class() -> None: |
| 227 | source = ( |
| 228 | 'class Foo(object):\n' |
| 229 | ' attr1 = None #: comment1\n' |
| 230 | ' attr2 = None #: comment2\n' |
| 231 | '\n' |
| 232 | ' def __init__(self):\n' |
| 233 | ' self.a = 1 + 1 #: comment3\n' |
| 234 | ' self.attr2 = 1 + 1 #: overridden\n' |
| 235 | ' b = 1 + 1 #: comment5\n' |
| 236 | '\n' |
| 237 | ' def some_method(self):\n' |
| 238 | ' c = 1 + 1 #: comment6\n' |
| 239 | ) |
| 240 | parser = Parser(source) |
| 241 | parser.parse() |
| 242 | assert parser.comments == { |
| 243 | ('Foo', 'attr1'): 'comment1', |
| 244 | ('Foo', 'a'): 'comment3', |
| 245 | ('Foo', 'attr2'): 'overridden', |
| 246 | } |
| 247 | assert parser.definitions == { |
| 248 | 'Foo': ('class', 1, 11), |
| 249 | 'Foo.__init__': ('def', 5, 8), |
| 250 | 'Foo.some_method': ('def', 10, 11), |
| 251 | } |
| 252 | assert parser.deforders == { |
| 253 | 'Foo': 0, |
| 254 | 'Foo.attr1': 1, |
| 255 | 'Foo.__init__': 3, |
| 256 | 'Foo.a': 4, |
| 257 | 'Foo.attr2': 5, |
| 258 | 'Foo.some_method': 6, |
| 259 | } |
| 260 | |
| 261 | |
| 262 | def test_class_uses_non_self() -> None: |