gristlabs / asttokens

Annotate Python AST trees with source text and token information
Apache License 2.0
172 stars 34 forks source link

2.0.5: pytest is failing in few `astroid` units #79

Closed kloczek closed 1 year ago

kloczek commented 2 years ago

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

I'm using astroid 2.11.2.

kloczek commented 2 years ago

Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.0.5-4.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.0.5-4.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra =========================================================================== test session starts ============================================================================ platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/asttokens-2.0.5, configfile: setup.cfg collected 107 items tests/test_astroid.py ...FF.......Fs....FF.F.FFF.FFFF..F....F.FF.F.F. [ 43%] tests/test_asttokens.py ...... [ 49%] tests/test_line_numbers.py ... [ 52%] tests/test_mark_tokens.py ............................................... [ 96%] tests/test_util.py .... [100%] ================================================================================= FAILURES ================================================================================= _________________________________________________________________ TestAstroid.test_assignment_expressions __________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=21, col_offset=0, end_lineno=21, end_col_offset=7)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=21, col_offset=0, end_lineno=21, end_col_offset=7) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 21, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 21, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 21, second = 2, msg = '21 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 21 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_assignment_expressions(self): # From https://www.python.org/dev/peps/pep-0572/ > self.create_mark_checker(""" # Handle a matched regex if (match := pattern.search(data)) is not None: # Do something with match pass # A loop that can't be trivially rewritten using 2-arg iter() while chunk := file.read(8192): process(chunk) # Reuse a value that's expensive to compute [y := f(x), y**2, y**3] # Share a subexpression between a comprehension filter clause and its output filtered_data = [y for x in data if (y := f(x)) is not None] y0 = (y1 := f(x)) # Valid, though discouraged foo(x=(y := f(x))) # Valid, though probably confusing def foo(answer=(p := 42)): # Valid, though not great style ... def foo(answer: (p := 42) = 5): # Valid, but probably never useful ... lambda: (x := 1) # Valid, but unlikely to be useful (x := lambda: 1) # Valid lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid if any((comment := line).startswith('#') for line in lines): print("First comment:", comment) if all((nonblank := line).strip() == '' for line in lines): print("All lines are blank") partial_sums = [total := total + v for v in values] """) tests/test_mark_tokens.py:678: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[43 chars] 21,\n 0,\n 21,\n 7],\n de[699 chars]))])" != "Func[43 chars] 2,\n 0,\n 2,\n 7],\n deco[697 chars]))])" E FunctionDef( E name='foo', E position=[ E - 21, E ? - E + 2, E 0, E - 21, E ? - E + 2, E 7], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='answer')], E defaults=[NamedExpr( E target=Name(name='p'), E value=Const( E value=42, E kind=None))], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Const( E value=Ellipsis, E kind=None))]) ________________________________________________________________________ TestAstroid.test_async_def ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] t2 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=13)) t2 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=13) t2 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 3 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = '6 != 3' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 3 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_async_def(self): > self.create_mark_checker(""" async def foo(): pass @decorator async def foo(): pass """) tests/test_mark_tokens.py:646: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Asyn[47 chars] 6,\n 0,\n 6,\n 13],\n de[519 chars]()])" != "Asyn[47 chars] 3,\n 0,\n 3,\n 13],\n de[519 chars]()])" E AsyncFunctionDef( E name='foo', E position=[ E - 6, E ? ^ E + 3, E ? ^ E 0, E - 6, E ? ^ E + 3, E ? ^ E 13], E decorators=Decorators(nodes=[Name(name='decorator')]), E args=Arguments( E vararg=None, E kwarg=None, E args=[], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Pass()]) _______________________________________________________________________ TestAstroid.test_decorators ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'g'), ...] t2 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'g'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=5)) t2 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=5)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=5) t2 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=5) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 3 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = '6 != 3' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 3 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_decorators(self): # See https://bitbucket.org/plas/thonny/issues/49/range-marker-fails-with-decorators source = textwrap.dedent(""" @deco1 def f(): pass @deco2(a=1) def g(x): pass @deco3() def g(x): pass """) > m = self.create_mark_checker(source) tests/test_mark_tokens.py:491: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[40 chars] 6,\n 0,\n 6,\n 5],\n dec[742 chars]()])" != "Func[40 chars] 3,\n 0,\n 3,\n 5],\n dec[742 chars]()])" E FunctionDef( E name='g', E position=[ E - 6, E ? ^ E + 3, E ? ^ E 0, E - 6, E ? ^ E + 3, E ? ^ E 5], E decorators=Decorators(nodes=[Call( E func=Name(name='deco2'), E args=[], E keywords=[Keyword( E arg='a', E value=Const( E value=1, E kind=None))])]), E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='x')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture10 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ...0>, , ]), ('name', 'TestCase'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ...0>, , ]), ('name', 'TestCase'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = ('body', [, , , ]) t2 = ('body', [, , , ]) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [, , , ] t2 = [, , , ] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'setUp'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'setUp'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=4, end_lineno=6, end_col_offset=13)) t2 = ('position', Position(lineno=4, col_offset=4, end_lineno=4, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=4, end_lineno=6, end_col_offset=13) t2 = Position(lineno=4, col_offset=4, end_lineno=4, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 4 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 4, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 4, msg = '6 != 4' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 4 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture10(self): self.verify_fixture_file('astroid/noendingnewline.py') tests/test_mark_tokens.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[68 chars] 4,\n 0,\n 4,\n 14],\n de[5231 chars]])])" != "Clas[68 chars] 2,\n 0,\n 2,\n 14],\n de[5229 chars]])])" E ClassDef( E name='TestCase', E is_dataclass=False, E position=[ E - 4, E ? ^ E + 2, E ? ^ E 0, E - 4, E ? ^ E + 2, E ? ^ E 14], E decorators=None, E bases=[Attribute( E attrname='TestCase', E expr=Name(name='unittest'))], E keywords=[], E doc_node=None, E body=[ E FunctionDef( E name='setUp', E position=[ E - 6, E 4, E - 6, E ? ^ E + 4, E ? ^ E + 4, E 13], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Attribute( E attrname='setUp', E expr=Attribute( E attrname='TestCase', E expr=Name(name='unittest'))), E args=[Name(name='self')], E keywords=[]))]), E FunctionDef( E name='tearDown', E position=[ E - 10, E ? ^^ E + 8, E ? ^ E 4, E - 10, E ? ^^ E + 8, E ? ^ E 16], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Attribute( E attrname='tearDown', E expr=Attribute( E attrname='TestCase', E expr=Name(name='unittest'))), E args=[Name(name='self')], E keywords=[]))]), E FunctionDef( E name='testIt', E position=[ E - 13, E ? ^ E + 11, E ? ^ E 4, E - 13, E ? ^ E + 11, E ? ^ E 14], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Assign( E targets=[Attribute( E attrname='a', E expr=Name(name='self'))], E value=Const( E value=10, E kind=None)), E Expr(value=Call( E func=Attribute( E attrname='xxx', E expr=Name(name='self')), E args=[], E keywords=[]))]), E FunctionDef( E name='xxx', E position=[ E - 18, E ? ^ E + 16, E ? ^ E 4, E - 18, E ? ^ E + 16, E ? ^ E 11], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[ E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Expr(value=Call( E func=Name(name='print'), E args=[Const( E value='a', E kind=None)], E keywords=[]))], E orelse=[]), E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Pass()], E orelse=[]), E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Expr(value=Call( E func=Name(name='print'), E args=[Const( E value='rara', E kind=None)], E keywords=[]))], E orelse=[])])]) ________________________________________________________________________ TestAstroid.test_fixture11 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 5, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = '5 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 5 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture11(self): self.verify_fixture_file('astroid/notall.py') tests/test_mark_tokens.py:174: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 chars] 2,\n 0,\n 2,\n 9],\n dec[78 chars]()])" E ClassDef( E name='Aaa', E is_dataclass=False, E position=[ E - 5, E ? ^ E + 2, E ? ^ E 0, E - 5, E ? ^ E + 2, E ? ^ E 9], E decorators=None, E bases=[], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture13 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'NotImplemented'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'NotImplemented'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=20)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=20) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 3, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = '3 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 3 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture13(self): self.verify_fixture_file('astroid/suppliermodule_test.py') tests/test_mark_tokens.py:176: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[74 chars] 3,\n 0,\n 3,\n 20],\n de[101 chars]()])" != "Clas[74 chars] 2,\n 0,\n 2,\n 20],\n de[101 chars]()])" E ClassDef( E name='NotImplemented', E is_dataclass=False, E position=[ E - 3, E ? ^ E + 2, E ? ^ E 0, E - 3, E ? ^ E + 2, E ? ^ E 20], E decorators=None, E bases=[Name(name='Exception')], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture3 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 5, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = '5 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 5 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture3(self): self.verify_fixture_file('astroid/all.py') tests/test_mark_tokens.py:166: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 chars] 2,\n 0,\n 2,\n 9],\n dec[78 chars]()])" E ClassDef( E name='Aaa', E is_dataclass=False, E position=[ E - 5, E ? ^ E + 2, E ? ^ E 0, E - 5, E ? ^ E + 2, E ? ^ E 9], E decorators=None, E bases=[], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture4 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Toto'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Toto'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=4, col_offset=0, end_lineno=4, end_col_offset=10)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=10)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=4, col_offset=0, end_lineno=4, end_col_offset=10) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=10) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 4, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 4, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 4, second = 2, msg = '4 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 4 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture4(self): self.verify_fixture_file('astroid/clientmodule_test.py') tests/test_mark_tokens.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[79 chars]()])" != "Clas[64 chars] 2,\n 0,\n 2,\n 10],\n de[79 chars]()])" E ClassDef( E name='Toto', E is_dataclass=False, E position=[ E - 4, E ? ^ E + 2, E ? ^ E 0, E - 4, E ? ^ E + 2, E ? ^ E 10], E decorators=None, E bases=[], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture5 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', [, ]), ('name', 'Page'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', [, ]), ('name', 'Page'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('body', [, ]) t2 = ('body', [, ]) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = [, ] t2 = [, ] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', [<...ign l.9 at 0x7f4462bfb040>, , ]), ('name', 'getPage'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', [<...ssign l.7 at 0x7f4462df5040>, , ]), ('name', 'getPage'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=15)) t2 = ('position', Position(lineno=5, col_offset=4, end_lineno=5, end_col_offset=15)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=15) t2 = Position(lineno=5, col_offset=4, end_lineno=5, end_col_offset=15) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 7, t2 = 5 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 5, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 5, msg = '7 != 5' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 7 != 5 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture5(self): self.verify_fixture_file('astroid/descriptor_crash.py') tests/test_mark_tokens.py:168: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[1986 chars]])])" != "Clas[64 chars] 2,\n 0,\n 2,\n 10],\n de[1986 chars]])])" E ClassDef( E name='Page', E is_dataclass=False, E position=[ E - 4, E ? ^ E + 2, E ? ^ E 0, E - 4, E ? ^ E + 2, E ? ^ E 10], E decorators=None, E bases=[Name(name='object')], E keywords=[], E doc_node=None, E body=[Assign( E targets=[Name(name='_urlOpen')], E value=Call( E func=Name(name='staticmethod'), E args=[Attribute( E attrname='urlopen', E expr=Name(name='urllib'))], E keywords=[])), E FunctionDef( E name='getPage', E position=[ E - 7, E ? ^ E + 5, E ? ^ E 4, E - 7, E ? ^ E + 5, E ? ^ E 15], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self'), Name(name='url')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None, None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None, None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[ E Assign( E targets=[Name(name='handle')], E value=Call( E func=Attribute( E attrname='_urlOpen', E expr=Name(name='self')), E args=[Name(name='url')], E keywords=[])), E Assign( E targets=[Name(name='data')], E value=Call( E func=Attribute( E attrname='read', E expr=Name(name='handle')), E args=[], E keywords=[])), E Expr(value=Call( E func=Attribute( E attrname='close', E expr=Name(name='handle')), E args=[], E keywords=[])), E Return(value=Name(name='data'))])]) ________________________________________________________________________ TestAstroid.test_fixture7 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'definition'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'definition'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=15, col_offset=0, end_lineno=15, end_col_offset=14)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=14)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=15, col_offset=0, end_lineno=15, end_col_offset=14) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=14) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 15, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 15, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 15, second = 2, msg = '15 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 15 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture7(self): self.verify_fixture_file('astroid/format.py') tests/test_mark_tokens.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[49 chars] 15,\n 0,\n 15,\n 14],\n [849 chars]))])" != "Func[49 chars] 2,\n 0,\n 2,\n 14],\n de[847 chars]))])" E FunctionDef( E name='definition', E position=[ E - 15, E ? ^^ E + 2, E ? ^ E 0, E - 15, E ? ^^ E + 2, E ? ^ E 14], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[ E Name(name='a'), E Name(name='b'), E Name(name='c')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[ E None, E None, E None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[ E None, E None, E None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Return(value=BinOp( E op='+', E left=BinOp( E op='+', E left=Name(name='a'), E right=Name(name='b')), E right=Name(name='c')))]) ________________________________________________________________________ TestAstroid.test_fixture8 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', , , ]), ('name', 'global_access'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', , , ]), ('name', 'global_access'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=11, col_offset=0, end_lineno=11, end_col_offset=17)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=17)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=11, col_offset=0, end_lineno=11, end_col_offset=17) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=17) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 11, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 11, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 11, second = 2, msg = '11 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 11 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture8(self): self.verify_fixture_file('astroid/module.py') tests/test_mark_tokens.py:171: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[52 chars] 11,\n 0,\n 11,\n 17],\n [1363 chars]])])" != "Func[52 chars] 2,\n 0,\n 2,\n 17],\n de[1361 chars]])])" E FunctionDef( E name='global_access', E position=[ E - 11, E ? ^^ E + 2, E ? ^ E 0, E - 11, E ? ^^ E + 2, E ? ^ E 17], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='key'), Name(name='val')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None, None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None, None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=Const( E value='function test', E kind=None), E body=[ E Assign( E targets=[Name(name='local')], E value=Const( E value=1, E kind=None)), E Assign( E targets=[Subscript( E ctx=, E value=Name(name='MY_DICT'), E slice=Name(name='key'))], E value=Name(name='val')), E For( E target=Name(name='i'), E iter=Name(name='val'), E body=[If( E test=Name(name='i'), E body=[Delete(targets=[Subscript( E ctx=, E value=Name(name='MY_DICT'), E slice=Name(name='i'))]), E Continue()], E orelse=[Break()])], E orelse=[Return(value=None)])]) ________________________________________________________________________ TestAstroid.test_fixture9 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', [, ]), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Specialization'), ...] t2 = [('decorators', None), ('bases', [, ]), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Specialization'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=20)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=20) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 5, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = '5 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 5 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture9(self): self.verify_fixture_file('astroid/module2.py') tests/test_mark_tokens.py:172: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[74 chars] 5,\n 0,\n 5,\n 20],\n de[114 chars]()])" != "Clas[74 chars] 2,\n 0,\n 2,\n 20],\n de[114 chars]()])" E ClassDef( E name='Specialization', E is_dataclass=False, E position=[ E - 5, E ? ^ E + 2, E ? ^ E 0, E - 5, E ? ^ E + 2, E ? ^ E 20], E decorators=None, E bases=[Name(name='YOUPI'), Name(name='YO')], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fstrings _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 't'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 't'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=1, col_offset=0, end_lineno=1, end_col_offset=5)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=5)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=1, col_offset=0, end_lineno=1, end_col_offset=5) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=5) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 1, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 1, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 1, second = 2, msg = '1 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 1 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_fstrings(self): for source in ( '(f"He said his name is {name!r}.",)', "f'{function(kwarg=24)}'", 'a = f"""result: {value:{width}.{precision}}"""', """[f"abc {a['x']} def"]""", "def t():\n return f'{function(kwarg=24)}'"): > self.create_mark_checker(source) tests/test_mark_tokens.py:306: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[40 chars] 1,\n 0,\n 1,\n 5],\n dec[916 chars]))])" != "Func[40 chars] 2,\n 0,\n 2,\n 5],\n dec[916 chars]))])" E FunctionDef( E name='t', E position=[ E - 1, E ? ^ E + 2, E ? ^ E 0, E - 1, E ? ^ E + 2, E ? ^ E 5], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Return(value=JoinedStr(values=[FormattedValue( E conversion=-1, E value=Call( E func=Name(name='function'), E args=[], E keywords=[Keyword( E arg='kwarg', E value=Const( E value=24, E kind=None))]), E format_spec=None)]))]) ___________________________________________________________________ TestAstroid.test_mark_tokens_simple ____________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', , , ]), ('name', 'global_access'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', , , ]), ('name', 'global_access'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=11, col_offset=0, end_lineno=11, end_col_offset=17)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=17)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=11, col_offset=0, end_lineno=11, end_col_offset=17) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=17) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 11, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 11, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 11, second = 2, msg = '11 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 11 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_mark_tokens_simple(self): source = tools.read_fixture('astroid', 'module.py') > m = self.create_mark_checker(source) tests/test_mark_tokens.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[52 chars] 11,\n 0,\n 11,\n 17],\n [1363 chars]])])" != "Func[52 chars] 2,\n 0,\n 2,\n 17],\n de[1361 chars]])])" E FunctionDef( E name='global_access', E position=[ E - 11, E ? ^^ E + 2, E ? ^ E 0, E - 11, E ? ^^ E + 2, E ? ^ E 17], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='key'), Name(name='val')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None, None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None, None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=Const( E value='function test', E kind=None), E body=[ E Assign( E targets=[Name(name='local')], E value=Const( E value=1, E kind=None)), E Assign( E targets=[Subscript( E ctx=, E value=Name(name='MY_DICT'), E slice=Name(name='key'))], E value=Name(name='val')), E For( E target=Name(name='i'), E iter=Name(name='val'), E body=[If( E test=Name(name='i'), E body=[Delete(targets=[Subscript( E ctx=, E value=Name(name='MY_DICT'), E slice=Name(name='i'))]), E Continue()], E orelse=[Break()])], E orelse=[Return(value=None)])]) _____________________________________________________________________ TestAstroid.test_print_function ______________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', ), ('body', [, ]), ('name', 'enumerate'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', ), ('body', [, ]), ('name', 'enumerate'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=17)) t2 = ('position', Position(lineno=2, col_offset=4, end_lineno=2, end_col_offset=17)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=17) t2 = Position(lineno=2, col_offset=4, end_lineno=2, end_col_offset=17) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 7, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 2, msg = '7 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 7 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_print_function(self): # This testcase imports print as function (using from __future__). Check that we can parse it. # verify_all_nodes doesn't work on Python 2 because the print() call parsed in isolation # is viewed as a Print node since it doesn't see the future import source = tools.read_fixture('astroid/nonregr.py') > m = self.create_mark_checker(source, verify=six.PY3) tests/test_mark_tokens.py:269: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[48 chars] 7,\n 4,\n 7,\n 17],\n de[1139 chars]])])" != "Func[48 chars] 2,\n 4,\n 2,\n 17],\n de[1139 chars]])])" E FunctionDef( E name='enumerate', E position=[ E - 7, E ? ^ E + 2, E ? ^ E 4, E - 7, E ? ^ E + 2, E ? ^ E 17], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='iterable')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=Const( E value='emulates the python2.3 enumerate() function', E kind=None), E body=[Assign( E targets=[Name(name='i')], E value=Const( E value=0, E kind=None)), E For( E target=Name(name='val'), E iter=Name(name='iterable'), E body=[Expr(value=Yield(value=Tuple( E ctx=, E elts=[Name(name='i'), Name(name='val')]))), E AugAssign( E op='+=', E target=Name(name='i'), E value=Const( E value=1, E kind=None))], E orelse=[])]) _________________________________________________________________________ TestAstroid.test_slices __________________________________________________________________________ self = def test_slices(self): # Make sure we don't fail on parsing slices of the form `foo[4:]`. source = "(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], [a[:]][::-1])" m = self.create_mark_checker(source) self.assertIn("Tuple:" + source, m.view_nodes_at(1, 0)) self.assertEqual(m.view_nodes_at(1, 1), { "Attribute:foo.Area_Code", "Name:foo" }) self.assertEqual(m.view_nodes_at(1, 16), { "Subscript:str(foo.Phone)[:3]", "Call:str(foo.Phone)", "Name:str"}) self.assertEqual(m.view_nodes_at(1, 36), { "Subscript:str(foo.Phone)[3:]", "Call:str(foo.Phone)", "Name:str"}) # Slice and ExtSlice nodes are wrong, and in particular placed with parents. They are not very # important, so we skip them here. self.assertEqual({n for n in m.view_nodes_at(1, 56) if 'Slice:' not in n}, { "Subscript:foo[:]", "Name:foo" }) > self.assertEqual({n for n in m.view_nodes_at(1, 64) if 'Slice:' not in n}, { "Subscript:bar[::2, :]", "Name:bar" }) E AssertionError: Items in the first set but not the second: E 'Tuple:bar[::2, :]' tests/test_mark_tokens.py:242: AssertionError __________________________________________________________________________ TestAstroid.test_splat __________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'print_all'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'print_all'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 3, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = '3 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 3 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_splat(self): # See https://bitbucket.org/plas/thonny/issues/151/debugger-crashes-when-encountering-a-splat source = textwrap.dedent(""" arr = [1,2,3,4,5] def print_all(a, b, c, d, e): print(a, b, c, d ,e) print_all(*arr) """) > m = self.create_mark_checker(source) tests/test_mark_tokens.py:334: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[48 chars] 3,\n 0,\n 3,\n 13],\n de[1024 chars]))])" != "Func[48 chars] 2,\n 0,\n 2,\n 13],\n de[1024 chars]))])" E FunctionDef( E name='print_all', E position=[ E - 3, E ? ^ E + 2, E ? ^ E 0, E - 3, E ? ^ E + 2, E ? ^ E 13], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[ E Name(name='a'), E Name(name='b'), E Name(name='c'), E Name(name='d'), E Name(name='e')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[ E None, E None, E None, E None, E None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[ E None, E None, E None, E None, E None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Name(name='print'), E args=[ E Name(name='a'), E Name(name='b'), E Name(name='c'), E Name(name='d'), E Name(name='e')], E keywords=[]))]) _______________________________________________________________________ TestAstroid.test_sys_modules _______________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', ), ('body', [, ]), ('name', '_wrap'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', ), ('body', [, ]), ('name', '_wrap'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=27, col_offset=0, end_lineno=27, end_col_offset=9)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=27, col_offset=0, end_lineno=27, end_col_offset=9) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 27, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 27, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 27, second = 2, msg = '27 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 27 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_sys_modules(self): """ Verify all nodes on source files obtained from sys.modules. This can take a long time as there are many modules, so it only tests all modules if the environment variable ASTTOKENS_SLOW_TESTS has been set. """ modules = list(sys.modules.values()) if not os.environ.get('ASTTOKENS_SLOW_TESTS'): modules = modules[:20] start = time() for module in modules: # Don't let this test (which runs twice) take longer than 13 minutes # to avoid the travis build time limit of 30 minutes if time() - start > 13 * 60: break try: filename = inspect.getsourcefile(module) except TypeError: continue if not filename: continue filename = os.path.abspath(filename) print(filename) try: with io.open(filename) as f: source = f.read() except OSError: continue # Astroid fails with a syntax error if a type comment is on its own line if self.is_astroid_test and re.search(r'^\s*# type: ', source, re.MULTILINE): print('Skipping', filename) continue > self.create_mark_checker(source) tests/test_mark_tokens.py:639: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[45 chars] 27,\n 0,\n 27,\n 9],\n de[2168 chars]))])" != "Func[45 chars] 2,\n 0,\n 2,\n 9],\n deco[2166 chars]))])" E FunctionDef( E name='_wrap', E position=[ E - 27, E ? - E + 2, E 0, E - 27, E ? - E + 2, E 9], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='new'), Name(name='old')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None, None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None, None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=Const( E value='Simple substitute for functools.update_wrapper.', E kind=None), E body=[For( E target=Name(name='replace'), E iter=List( E ctx=, E elts=[ E Const( E value='__module__', E kind=None), E Const( E value='__name__', E kind=None), E Const( E value='__qualname__', E kind=None), E Const( E value='__doc__', E kind=None)]), E body=[If( E test=Call( E func=Name(name='hasattr'), E args=[Name(name='old'), Name(name='replace')], E keywords=[]), E body=[Expr(value=Call( E func=Name(name='setattr'), E args=[ E Name(name='new'), E Name(name='replace'), E Call( E func=Name(name='getattr'), E args=[Name(name='old'), Name(name='replace')], E keywords=[])], E keywords=[]))], E orelse=[])], E orelse=[]), E Expr(value=Call( E func=Attribute( E attrname='update', E expr=Attribute( E attrname='__dict__', E expr=Name(name='new'))), E args=[Attribute( E attrname='__dict__', E expr=Name(name='old'))], E keywords=[]))]) --------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------- /usr/lib64/python3.8/importlib/_bootstrap.py _________________________________________________________________________ TestAstroid.test_tuples __________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True tested_nodes = 0 for node in self.all_nodes: if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node) # In 3.9+, slices are now expressions in the AST, but of course their source code # can't be parsed ) or util.is_slice(node): continue text = self.atok.get_text(node) # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:99: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:790: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=1, col_offset=0, end_lineno=1, end_col_offset=7)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=1, col_offset=0, end_lineno=1, end_col_offset=7) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:788: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 1, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:800: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 1, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 1, second = 2, msg = '1 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 1 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_tuples(self): def get_tuples(code): m = self.create_mark_checker(code) return [m.atok.get_text(n) for n in m.all_nodes if n.__class__.__name__ == "Tuple"] self.assertEqual(get_tuples("a,"), ["a,"]) self.assertEqual(get_tuples("(a,)"), ["(a,)"]) self.assertEqual(get_tuples("(a),"), ["(a),"]) self.assertEqual(get_tuples("((a),)"), ["((a),)"]) self.assertEqual(get_tuples("(a,),"), ["(a,),", "(a,)"]) self.assertEqual(get_tuples("((a,),)"), ["((a,),)", "(a,)"]) self.assertEqual(get_tuples("()"), ["()"]) self.assertEqual(get_tuples("(),"), ["(),", "()"]) self.assertEqual(get_tuples("((),)"), ["((),)", "()"]) self.assertEqual(get_tuples("((),(a,))"), ["((),(a,))", "()", "(a,)"]) self.assertEqual(get_tuples("((),(a,),)"), ["((),(a,),)", "()", "(a,)"]) self.assertEqual(get_tuples("((),(a,),),"), ["((),(a,),),", "((),(a,),)", "()", "(a,)"]) self.assertEqual(get_tuples('((foo, bar),)'), ['((foo, bar),)', '(foo, bar)']) self.assertEqual(get_tuples('(foo, bar),'), ['(foo, bar),', '(foo, bar)']) > self.assertEqual(get_tuples('def foo(a=()): ((x, (y,)),) = ((), (a,),),'), [ '()', '((x, (y,)),)', '(x, (y,))', '(y,)', '((), (a,),),', '((), (a,),)', '()', '(a,)']) tests/test_mark_tokens.py:416: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:399: in get_tuples m = self.create_mark_checker(code) tests/test_mark_tokens.py:43: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:103: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[42 chars] 1,\n 0,\n 1,\n 7],\n dec[1237 chars]))])" != "Func[42 chars] 2,\n 0,\n 2,\n 7],\n dec[1237 chars]))])" E FunctionDef( E name='foo', E position=[ E - 1, E ? ^ E + 2, E ? ^ E 0, E - 1, E ? ^ E + 2, E ? ^ E 7], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='a')], E defaults=[Tuple( E ctx=, E elts=[])], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Assign( E targets=[Tuple( E ctx=, E elts=[Tuple( E ctx=, E elts=[Name(name='x'), Tuple( E ctx=, E elts=[Name(name='y')])])])], E value=Tuple( E ctx=, E elts=[Tuple( E ctx=, E elts=[Tuple( E ctx=, E elts=[]), E Tuple( E ctx=, E elts=[Name(name='a')])])]))]) ========================================================================= short test summary info ========================================================================== SKIPPED [1] tests/test_mark_tokens.py:179: astroid-2.0 does not support this FAILED tests/test_astroid.py::TestAstroid::test_assignment_expressions - AssertionError: "Func[43 chars] 21,\n 0,\n 21,\n 7],\n de[699 chars]))])" !=... FAILED tests/test_astroid.py::TestAstroid::test_async_def - AssertionError: "Asyn[47 chars] 6,\n 0,\n 6,\n 13],\n de[519 chars]()])" != "Asyn[47 cha... FAILED tests/test_astroid.py::TestAstroid::test_decorators - AssertionError: "Func[40 chars] 6,\n 0,\n 6,\n 5],\n dec[742 chars]()])" != "Func[40 ch... FAILED tests/test_astroid.py::TestAstroid::test_fixture10 - AssertionError: "Clas[68 chars] 4,\n 0,\n 4,\n 14],\n de[5231 chars]])])" != "Clas[68 ch... FAILED tests/test_astroid.py::TestAstroid::test_fixture11 - AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 char... FAILED tests/test_astroid.py::TestAstroid::test_fixture13 - AssertionError: "Clas[74 chars] 3,\n 0,\n 3,\n 20],\n de[101 chars]()])" != "Clas[74 cha... FAILED tests/test_astroid.py::TestAstroid::test_fixture3 - AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 chars... FAILED tests/test_astroid.py::TestAstroid::test_fixture4 - AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[79 chars]()])" != "Clas[64 chars... FAILED tests/test_astroid.py::TestAstroid::test_fixture5 - AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[1986 chars]])])" != "Clas[64 cha... FAILED tests/test_astroid.py::TestAstroid::test_fixture7 - AssertionError: "Func[49 chars] 15,\n 0,\n 15,\n 14],\n [849 chars]))])" != "Func[49 char... FAILED tests/test_astroid.py::TestAstroid::test_fixture8 - AssertionError: "Func[52 chars] 11,\n 0,\n 11,\n 17],\n [1363 chars]])])" != "Func[52 cha... FAILED tests/test_astroid.py::TestAstroid::test_fixture9 - AssertionError: "Clas[74 chars] 5,\n 0,\n 5,\n 20],\n de[114 chars]()])" != "Clas[74 char... FAILED tests/test_astroid.py::TestAstroid::test_fstrings - AssertionError: "Func[40 chars] 1,\n 0,\n 1,\n 5],\n dec[916 chars]))])" != "Func[40 char... FAILED tests/test_astroid.py::TestAstroid::test_mark_tokens_simple - AssertionError: "Func[52 chars] 11,\n 0,\n 11,\n 17],\n [1363 chars]])])" != "F... FAILED tests/test_astroid.py::TestAstroid::test_print_function - AssertionError: "Func[48 chars] 7,\n 4,\n 7,\n 17],\n de[1139 chars]])])" != "Func[... FAILED tests/test_astroid.py::TestAstroid::test_slices - AssertionError: Items in the first set but not the second: FAILED tests/test_astroid.py::TestAstroid::test_splat - AssertionError: "Func[48 chars] 3,\n 0,\n 3,\n 13],\n de[1024 chars]))])" != "Func[48 chars]... FAILED tests/test_astroid.py::TestAstroid::test_sys_modules - AssertionError: "Func[45 chars] 27,\n 0,\n 27,\n 9],\n de[2168 chars]))])" != "Func[45 ... FAILED tests/test_astroid.py::TestAstroid::test_tuples - AssertionError: "Func[42 chars] 1,\n 0,\n 1,\n 7],\n dec[1237 chars]))])" != "Func[42 chars... ========================================================== 19 failed, 87 passed, 1 skipped, 569 warnings in 9.32s ========================================================== ```
alexmojaki commented 2 years ago

setup.cfg specifies astroid<=2.5.3 for tests, that was committed here: https://github.com/gristlabs/asttokens/pull/75/commits/8896a3d7a6f68f088c05c7e18d61339c09ab3fee

Looks like tests were already known to be failing on newer versions back then.

alexmojaki commented 2 years ago

Related: #70

kloczek commented 2 years ago

So no support for latest astroid? 🤔 2.5.3 is already +year old ..

keszybz commented 2 years ago

This is also failing in Fedora rawhide with python3-astroid-2.11.3-1.fc37.noarch and python3-3.11.0~a7-2.fc37.x86_64: https://download.copr.fedorainfracloud.org/results/@python/python3.11/fedora-rawhide-x86_64/04307405-python-asttokens/build.log.gz

alexmojaki commented 2 years ago

The only 'user' I know of that uses the astroid side of asttokens is gristlabs itself, and the old version hasn't caused any problems AFAIK. Is anyone else using astroid at all?

IPython, icecream, birdseye, snoop, heartrate, stack_data, etc. all use asttokens with the standard ast. So while fixes to these tests would obviously be appreciated, that's why this isn't considered a priority and why configuring other builds to use the same version restriction should be fine.

keszybz commented 2 years ago

pylint uses astroid, so we upgraded astroid so that pylint works with python3.11. Other packages don't use it, but there might be user code that uses it, and we can't know that. Ideally, both asttokens and pylint could just use the latest astroid version. Providing a different version of astroid for asttokens creates additional work and complications.

alexmojaki commented 2 years ago

asttokens doesn't depend on astroid. Installing asttokens shouldn't automatically install astroid. If a package out there specifically uses asttokens with astroid, it should list them both as explicit dependencies.

keszybz commented 2 years ago

asttokens testsuite fails if astroid is not installed. So the procedure goes like this: we try to upgrade python to the latest versions, execute all the tests on all the packages. Now astroid fails, but we look at the history, and the latest version (which we would want to have anyway) has fixes for 3.11, so we update that, and execute all the tests on all packages again, and it fails on asttokens. We don't want to skip the tests on asttokens, because if we don't do the tests, we don't know if asttokens actually works with new python and all the other packages out there. The only sane solution is to have latest versions of everything and run as many upstream tests as possible and have them pass.

alexmojaki commented 2 years ago

Can't you test and build asttokens in isolation from everything else? Do all packages have to be built and tested in the same environment with the same dependencies and versions?

The reality is that asttokens doesn't support the latest astroid. I haven't really checked but I'm guessing that the test failures represent actual incompatibility, not just a problem with tests. That's obviously not great, and fixes would be appreciated. At the same time, I wouldn't be surprised if there's actually no one out there affected by this.

The asttokens package shouldn't place any restrictions on the installed version of astroid. Users should be allowed to install the latest asttokens and astroid in the same env because they're not actually interacting with each other. The version restriction should only exist in the tests.

keszybz commented 2 years ago

We are building asttokens in isolation from everything else. Like with any other package: they are all built in a freshly-set-up environment with the specified set of dependencies. But we want to have just one version of every package for a given release of the distribution. (OK, sometimes we will introduce a "compat version", but as I mentioned, we avoid that because it's extra work, somebody has to remember to do this, and then somebody has to remember to retire the package when it's not needed, and we have to figure out how to handle the case where both versions are wanted, e.g. though recursive dependencies.) Thus, ideally, we can just use the latest upstream versions of all the packages involved.

The information that this has limited scope is useful. Since this is only about tests, it doesn't seem worth the trouble to introduce a compat package. We can skip the tests that would fail w/o astroid. If at some point asttokens starts working with the latest astroid, that'd be great.

kloczek commented 2 years ago

Just started updating to 2.1.0 and here is pytest result

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.1.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.1.0-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra =========================================================================== test session starts ============================================================================ platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/asttokens-2.1.0, configfile: setup.cfg collected 114 items tests/test_astroid.py ...FF.....FF.Fs....FF.F.FFF.FFFF.FF...FF.FF.FFF. [ 42%] tests/test_asttokens.py ....... [ 48%] tests/test_line_numbers.py ... [ 50%] tests/test_mark_tokens.py ................................................ [ 92%] tests/test_tokenless.py ... [ 95%] tests/test_util.py ..... [100%] ================================================================================= FAILURES ================================================================================= _________________________________________________________________ TestAstroid.test_assignment_expressions __________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=21, col_offset=0, end_lineno=21, end_col_offset=7)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=21, col_offset=0, end_lineno=21, end_col_offset=7) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=7) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 21, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 21, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 21, second = 2, msg = '21 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 21 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_assignment_expressions(self): # From https://www.python.org/dev/peps/pep-0572/ > self.create_mark_checker(""" # Handle a matched regex if (match := pattern.search(data)) is not None: # Do something with match pass # A loop that can't be trivially rewritten using 2-arg iter() while chunk := file.read(8192): process(chunk) # Reuse a value that's expensive to compute [y := f(x), y**2, y**3] # Share a subexpression between a comprehension filter clause and its output filtered_data = [y for x in data if (y := f(x)) is not None] y0 = (y1 := f(x)) # Valid, though discouraged foo(x=(y := f(x))) # Valid, though probably confusing def foo(answer=(p := 42)): # Valid, though not great style ... def foo(answer: (p := 42) = 5): # Valid, but probably never useful ... lambda: (x := 1) # Valid, but unlikely to be useful (x := lambda: 1) # Valid lambda line: (m := re.match(pattern, line)) and m.group(1) # Valid if any((comment := line).startswith('#') for line in lines): print("First comment:", comment) if all((nonblank := line).strip() == '' for line in lines): print("All lines are blank") partial_sums = [total := total + v for v in values] """) tests/test_mark_tokens.py:707: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:44: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[43 chars] 21,\n 0,\n 21,\n 7],\n de[699 chars]))])" != "Func[43 chars] 2,\n 0,\n 2,\n 7],\n deco[697 chars]))])" E FunctionDef( E name='foo', E position=[ E - 21, E ? - E + 2, E 0, E - 21, E ? - E + 2, E 7], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='answer')], E defaults=[NamedExpr( E target=Name(name='p'), E value=Const( E value=42, E kind=None))], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Const( E value=Ellipsis, E kind=None))]) ________________________________________________________________________ TestAstroid.test_async_def ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] t2 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'foo'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=13)) t2 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=13) t2 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 3 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = '6 != 3' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 3 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_async_def(self): > self.create_mark_checker(""" async def foo(): pass @decorator async def foo(): pass """) tests/test_mark_tokens.py:675: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:44: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Asyn[47 chars] 6,\n 0,\n 6,\n 13],\n de[519 chars]()])" != "Asyn[47 chars] 3,\n 0,\n 3,\n 13],\n de[519 chars]()])" E AsyncFunctionDef( E name='foo', E position=[ E - 6, E ? ^ E + 3, E ? ^ E 0, E - 6, E ? ^ E + 3, E ? ^ E 13], E decorators=Decorators(nodes=[Name(name='decorator')]), E args=Arguments( E vararg=None, E kwarg=None, E args=[], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Pass()]) ________________________________________________________________ TestAstroid.test_complex_slice_and_parens _________________________________________________________________ self = def test_complex_slice_and_parens(self): source = 'f((x)[:, 0])' > self.create_mark_checker(source) tests/test_mark_tokens.py:615: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(1, 2), end=(1, 3), line='f((x)[:, 0])', index=2, startpos=2, endpos=3) last_token = Token(type=54, string=']', start=(1, 10), end=(1, 11), line='f((x)[:, 0])', index=9, startpos=10, endpos=11) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError _____________________________________________________________________ TestAstroid.test_comprehensions ______________________________________________________________________ self = def test_comprehensions(self): # See https://bitbucket.org/plas/thonny/issues/8/range-marker-doesnt-work-correctly-with for source in ( "[(key, val) for key, val in ast.iter_fields(node)]", "((key, val) for key, val in ast.iter_fields(node))", "{(key, val) for key, val in ast.iter_fields(node)}", "{key: val for key, val in ast.iter_fields(node)}", "[[c for c in key] for key, val in ast.iter_fields(node)]"): > self.create_mark_checker(source) tests/test_mark_tokens.py:391: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(1, 1), end=(1, 2), line='[(key, val) for key, val in ast.iter_fields(node)]', index=1, startpos=1, endpos=2) last_token = Token(type=54, string=')', start=(1, 10), end=(1, 11), line='[(key, val) for key, val in ast.iter_fields(node)]', index=5, startpos=10, endpos=11) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError _______________________________________________________________________ TestAstroid.test_decorators ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'g'), ...] t2 = [('decorators', ), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'g'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=5)) t2 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=5)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=0, end_lineno=6, end_col_offset=5) t2 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=5) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 3 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 3, msg = '6 != 3' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 3 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_decorators(self): # See https://bitbucket.org/plas/thonny/issues/49/range-marker-fails-with-decorators source = textwrap.dedent(""" @deco1 def f(): pass @deco2(a=1) def g(x): pass @deco3() def g(x): pass """) > m = self.create_mark_checker(source) tests/test_mark_tokens.py:506: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:44: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[40 chars] 6,\n 0,\n 6,\n 5],\n dec[742 chars]()])" != "Func[40 chars] 3,\n 0,\n 3,\n 5],\n dec[742 chars]()])" E FunctionDef( E name='g', E position=[ E - 6, E ? ^ E + 3, E ? ^ E 0, E - 6, E ? ^ E + 3, E ? ^ E 5], E decorators=Decorators(nodes=[Call( E func=Name(name='deco2'), E args=[], E keywords=[Keyword( E arg='a', E value=Const( E value=1, E kind=None))])]), E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='x')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture10 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ...0>, , ]), ('name', 'TestCase'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ...0>, , ]), ('name', 'TestCase'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = ('body', [, , , ]) t2 = ('body', [, , , ]) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [, , , ] t2 = [, , , ] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'setUp'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'setUp'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=6, col_offset=4, end_lineno=6, end_col_offset=13)) t2 = ('position', Position(lineno=4, col_offset=4, end_lineno=4, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=6, col_offset=4, end_lineno=6, end_col_offset=13) t2 = Position(lineno=4, col_offset=4, end_lineno=4, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 6, t2 = 4 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 4, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 6, second = 4, msg = '6 != 4' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 6 != 4 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture10(self): self.verify_fixture_file('astroid/noendingnewline.py') tests/test_mark_tokens.py:177: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:135: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[68 chars] 4,\n 0,\n 4,\n 14],\n de[5231 chars]])])" != "Clas[68 chars] 2,\n 0,\n 2,\n 14],\n de[5229 chars]])])" E ClassDef( E name='TestCase', E is_dataclass=False, E position=[ E - 4, E ? ^ E + 2, E ? ^ E 0, E - 4, E ? ^ E + 2, E ? ^ E 14], E decorators=None, E bases=[Attribute( E attrname='TestCase', E expr=Name(name='unittest'))], E keywords=[], E doc_node=None, E body=[ E FunctionDef( E name='setUp', E position=[ E - 6, E 4, E - 6, E ? ^ E + 4, E ? ^ E + 4, E 13], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Attribute( E attrname='setUp', E expr=Attribute( E attrname='TestCase', E expr=Name(name='unittest'))), E args=[Name(name='self')], E keywords=[]))]), E FunctionDef( E name='tearDown', E position=[ E - 10, E ? ^^ E + 8, E ? ^ E 4, E - 10, E ? ^^ E + 8, E ? ^ E 16], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Attribute( E attrname='tearDown', E expr=Attribute( E attrname='TestCase', E expr=Name(name='unittest'))), E args=[Name(name='self')], E keywords=[]))]), E FunctionDef( E name='testIt', E position=[ E - 13, E ? ^ E + 11, E ? ^ E 4, E - 13, E ? ^ E + 11, E ? ^ E 14], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Assign( E targets=[Attribute( E attrname='a', E expr=Name(name='self'))], E value=Const( E value=10, E kind=None)), E Expr(value=Call( E func=Attribute( E attrname='xxx', E expr=Name(name='self')), E args=[], E keywords=[]))]), E FunctionDef( E name='xxx', E position=[ E - 18, E ? ^ E + 16, E ? ^ E 4, E - 18, E ? ^ E + 16, E ? ^ E 11], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[ E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Expr(value=Call( E func=Name(name='print'), E args=[Const( E value='a', E kind=None)], E keywords=[]))], E orelse=[]), E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Pass()], E orelse=[]), E If( E test=Const( E value=False, E kind=None), E body=[Pass(), Expr(value=Call( E func=Name(name='print'), E args=[Const( E value='rara', E kind=None)], E keywords=[]))], E orelse=[])])]) ________________________________________________________________________ TestAstroid.test_fixture11 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'Aaa'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=5, col_offset=0, end_lineno=5, end_col_offset=9) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=9) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 5, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 5, second = 2, msg = '5 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 5 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture11(self): self.verify_fixture_file('astroid/notall.py') tests/test_mark_tokens.py:178: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:135: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 chars] 2,\n 0,\n 2,\n 9],\n dec[78 chars]()])" E ClassDef( E name='Aaa', E is_dataclass=False, E position=[ E - 5, E ? ^ E + 2, E ? ^ E 0, E - 5, E ? ^ E + 2, E ? ^ E 9], E decorators=None, E bases=[], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture13 ________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'NotImplemented'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', []), ('name', 'NotImplemented'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=20)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=20) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=20) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 3, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = '3 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 3 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture13(self): self.verify_fixture_file('astroid/suppliermodule_test.py') tests/test_mark_tokens.py:180: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:135: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[74 chars] 3,\n 0,\n 3,\n 20],\n de[101 chars]()])" != "Clas[74 chars] 2,\n 0,\n 2,\n 20],\n de[101 chars]()])" E ClassDef( E name='NotImplemented', E is_dataclass=False, E position=[ E - 3, E ? ^ E + 2, E ? ^ E 0, E - 3, E ? ^ E + 2, E ? ^ E 20], E decorators=None, E bases=[Name(name='Exception')], E keywords=[], E doc_node=None, E body=[Pass()]) ________________________________________________________________________ TestAstroid.test_fixture3 _________________________________________________________________________ self = > def test_fixture3(self): self.verify_fixture_file('astroid/all.py') tests/test_mark_tokens.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file m = self.create_mark_checker(source, verify=False) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=3, string="'Aaa'", start=(9, 10), end=(9, 15), line="__all__ = 'Aaa', '_bla', 'name'\n", index=32, startpos=85, endpos=90) last_token = Token(type=3, string="'name'", start=(9, 25), end=(9, 31), line="__all__ = 'Aaa', '_bla', 'name'\n", index=36, startpos=100, endpos=106) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ________________________________________________________________________ TestAstroid.test_fixture4 _________________________________________________________________________ self = > def test_fixture4(self): self.verify_fixture_file('astroid/clientmodule_test.py') tests/test_mark_tokens.py:171: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file m = self.create_mark_checker(source, verify=False) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(8, 21), end=(8, 22), line=' __implements__ = (IFace,)\n', index=29, startpos=194, endpos=195) last_token = Token(type=54, string=')', start=(8, 28), end=(8, 29), line=' __implements__ = (IFace,)\n', index=32, startpos=201, endpos=202) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ________________________________________________________________________ TestAstroid.test_fixture5 _________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', [, ]), ('name', 'Page'), ...] t2 = [('decorators', None), ('bases', []), ('keywords', []), ('doc_node', None), ('body', [, ]), ('name', 'Page'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('body', [, ]) t2 = ('body', [, ]) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = [, ] t2 = [, ] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', [<...ign l.9 at 0x7f804005eac0>, , ]), ('name', 'getPage'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', [<...ssign l.7 at 0x7f8040255af0>, , ]), ('name', 'getPage'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=15)) t2 = ('position', Position(lineno=5, col_offset=4, end_lineno=5, end_col_offset=15)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=7, col_offset=4, end_lineno=7, end_col_offset=15) t2 = Position(lineno=5, col_offset=4, end_lineno=5, end_col_offset=15) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 7, t2 = 5 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 5, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 7, second = 5, msg = '7 != 5' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 7 != 5 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = > def test_fixture5(self): self.verify_fixture_file('astroid/descriptor_crash.py') tests/test_mark_tokens.py:172: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:135: in verify_fixture_file tested_nodes = m.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[1986 chars]])])" != "Clas[64 chars] 2,\n 0,\n 2,\n 10],\n de[1986 chars]])])" E ClassDef( E name='Page', E is_dataclass=False, E position=[ E - 4, E ? ^ E + 2, E ? ^ E 0, E - 4, E ? ^ E + 2, E ? ^ E 10], E decorators=None, E bases=[Name(name='object')], E keywords=[], E doc_node=None, E body=[Assign( E targets=[Name(name='_urlOpen')], E value=Call( E func=Name(name='staticmethod'), E args=[Attribute( E attrname='urlopen', E expr=Name(name='urllib'))], E keywords=[])), E FunctionDef( E name='getPage', E position=[ E - 7, E ? ^ E + 5, E ? ^ E 4, E - 7, E ? ^ E + 5, E ? ^ E 15], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[Name(name='self'), Name(name='url')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[None, None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[None, None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[ E Assign( E targets=[Name(name='handle')], E value=Call( E func=Attribute( E attrname='_urlOpen', E expr=Name(name='self')), E args=[Name(name='url')], E keywords=[])), E Assign( E targets=[Name(name='data')], E value=Call( E func=Attribute( E attrname='read', E expr=Name(name='handle')), E args=[], E keywords=[])), E Expr(value=Call( E func=Attribute( E attrname='close', E expr=Name(name='handle')), E args=[], E keywords=[])), E Return(value=Name(name='data'))])]) ________________________________________________________________________ TestAstroid.test_fixture7 _________________________________________________________________________ self = > def test_fixture7(self): self.verify_fixture_file('astroid/format.py') tests/test_mark_tokens.py:174: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file m = self.create_mark_checker(source, verify=False) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=1, string='aaaa', start=(26, 4), end=(26, 8), line=' aaaa,bbbb = 1,2\n', index=93, startpos=320, endpos=324) last_token = Token(type=1, string='bbbb', start=(26, 9), end=(26, 13), line=' aaaa,bbbb = 1,2\n', index=95, startpos=325, endpos=329) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ________________________________________________________________________ TestAstroid.test_fixture8 _________________________________________________________________________ self = > def test_fixture8(self): self.verify_fixture_file('astroid/module.py') tests/test_mark_tokens.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file m = self.create_mark_checker(source, verify=False) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(34, 15), end=(34, 16), line=' except (NameError, TypeError):\n', index=143, startpos=631, endpos=632) last_token = Token(type=54, string=')', start=(34, 36), end=(34, 37), line=' except (NameError, TypeError):\n', index=147, startpos=652, endpos=653) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ________________________________________________________________________ TestAstroid.test_fixture9 _________________________________________________________________________ self = > def test_fixture9(self): self.verify_fixture_file('astroid/module2.py') tests/test_mark_tokens.py:176: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:134: in verify_fixture_file m = self.create_mark_checker(source, verify=False) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(58, 21), end=(58, 22), line=' __implements__ = (MyIFace, AnotherIFace)\n', index=183, startpos=620, endpos=621) last_token = Token(type=54, string=')', start=(58, 43), end=(58, 44), line=' __implements__ = (MyIFace, AnotherIFace)\n', index=187, startpos=642, endpos=643) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ________________________________________________________________________ TestAstroid.test_fstrings _________________________________________________________________________ self = def test_fstrings(self): for source in ( '(f"He said his name is {name!r}.",)', "f'{function(kwarg=24)}'", 'a = f"""result: {value:{width}.{precision}}"""', """[f"abc {a['x']} def"]""", "def t():\n return f'{function(kwarg=24)}'"): > self.create_mark_checker(source) tests/test_mark_tokens.py:311: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(1, 0), end=(1, 1), line='(f"He said his name is {name!r}.",)', index=0, startpos=0, endpos=1) last_token = Token(type=54, string=')', start=(1, 34), end=(1, 35), line='(f"He said his name is {name!r}.",)', index=3, startpos=34, endpos=35) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError __________________________________________________________________ TestAstroid.test_mark_tokens_multiline __________________________________________________________________ self = def test_mark_tokens_multiline(self): source = ( """( # line1 a, # line2 b + # line3 c + # line4 d # line5 )""") > m = self.create_mark_checker(source) tests/test_mark_tokens.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(1, 0), end=(1, 1), line='( # line1\n', index=0, startpos=0, endpos=1) last_token = Token(type=54, string=')', start=(6, 0), end=(6, 1), line=')', index=18, startpos=77, endpos=78) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ___________________________________________________________________ TestAstroid.test_mark_tokens_simple ____________________________________________________________________ self = def test_mark_tokens_simple(self): source = tools.read_fixture('astroid', 'module.py') > m = self.create_mark_checker(source) tests/test_mark_tokens.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(34, 15), end=(34, 16), line=' except (NameError, TypeError):\n', index=143, startpos=631, endpos=632) last_token = Token(type=54, string=')', start=(34, 36), end=(34, 37), line=' except (NameError, TypeError):\n', index=147, startpos=652, endpos=653) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ___________________________________________________________________ TestAstroid.test_parens_around_func ____________________________________________________________________ self = def test_parens_around_func(self): source = textwrap.dedent( ''' foo() (foo)() (lambda: 0)() (lambda: ())() (foo)((1)) (lambda: ())((2)) x = (obj.attribute.get_callback() or default_callback)() ''') > m = self.create_mark_checker(source) tests/test_mark_tokens.py:601: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(5, 9), end=(5, 10), line='(lambda: ())()\n', index=22, startpos=38, endpos=39) last_token = Token(type=54, string=')', start=(5, 10), end=(5, 11), line='(lambda: ())()\n', index=23, startpos=39, endpos=40) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError _____________________________________________________________________ TestAstroid.test_print_function ______________________________________________________________________ self = def test_print_function(self): # This testcase imports print as function (using from __future__). Check that we can parse it. # verify_all_nodes doesn't work on Python 2 because the print() call parsed in isolation # is viewed as a Print node since it doesn't see the future import source = tools.read_fixture('astroid/nonregr.py') > m = self.create_mark_checker(source, verify=six.PY3) tests/test_mark_tokens.py:273: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=1, string='i', start=(11, 18), end=(11, 19), line=' yield i, val\n', index=39, startpos=200, endpos=201) last_token = Token(type=1, string='val', start=(11, 21), end=(11, 24), line=' yield i, val\n', index=41, startpos=203, endpos=206) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError _________________________________________________________________________ TestAstroid.test_slices __________________________________________________________________________ self = def test_slices(self): # Make sure we don't fail on parsing slices of the form `foo[4:]`. source = "(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], [a[:]][::-1])" > m = self.create_mark_checker(source) tests/test_mark_tokens.py:234: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=1, string='bar', start=(1, 64), end=(1, 67), line='(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], [a[:]][::-1])', index=32, startpos=64, endpos=67) last_token = Token(type=54, string=']', start=(1, 74), end=(1, 75), line='(foo.Area_Code, str(foo.Phone)[:3], str(foo.Phone)[3:], foo[:], bar[::2, :], [a[:]][::-1])', index=39, startpos=74, endpos=75) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError __________________________________________________________________________ TestAstroid.test_splat __________________________________________________________________________ self = , test_case = def verify_all_nodes(self, test_case): """ Generically test atok.get_text() on the ast tree: for each statement and expression in the tree, we extract the text, parse it, and see if it produces an equivalent tree. Returns the number of nodes that were tested this way. """ test_case.longMessage = True if supports_tokenless() and not test_case.is_astroid_test: num_supported = sum(supports_tokenless(n) for n in self.all_nodes) num_nodes = len(self.all_nodes) test_case.assertGreater(num_supported / num_nodes, 0.5, (num_supported, num_nodes)) tested_nodes = 0 for node in self.all_nodes: text = self.atok.get_text(node) self.check_get_text_tokenless(node, test_case, text) if not ( util.is_stmt(node) or util.is_expr(node) or util.is_module(node)): continue # slices currently only get the correct tokens for ast, not astroid. if util.is_slice(node) and test_case.is_astroid_test: continue # await is not allowed outside async functions below 3.7 # parsing again would give a syntax error if 'await' in text and 'async def' not in text and sys.version_info < (3, 7): continue # `elif:` is really just `else: if:` to the AST, # so get_text can return text starting with elif when given an If node. # This is generally harmless and there's probably no good alternative, # but in isolation it's invalid syntax text = re.sub(r'^(\s*)elif(\W)', r'\1if\2', text, re.MULTILINE) rebuilt_node = test_case.parse_snippet(text, node) try: > test_case.assert_nodes_equal(node, rebuilt_node) tests/tools.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = , t2 = def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): > self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) tests/test_mark_tokens.py:822: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = t1 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'print_all'), ...] t2 = [('decorators', None), ('args', ), ('returns', None), ('doc_node', None), ('body', []), ('name', 'print_all'), ...] def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = ('position', Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13)) t2 = ('position', Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=13)) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = Position(lineno=3, col_offset=0, end_lineno=3, end_col_offset=13) t2 = Position(lineno=2, col_offset=0, end_lineno=2, end_col_offset=13) def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): > self.assert_nodes_equal(vc1, vc2) tests/test_mark_tokens.py:820: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , t1 = 3, t2 = 2 def assert_nodes_equal(self, t1, t2): # Ignore the context of each node which can change when parsing # substrings of source code. We just want equal structure and contents. for context_classes_group in self.context_classes: if isinstance(t1, context_classes_group): self.assertIsInstance(t2, context_classes_group) break else: self.assertEqual(type(t1), type(t2)) if isinstance(t1, (list, tuple)): self.assertEqual(len(t1), len(t2)) for vc1, vc2 in zip(t1, t2): self.assert_nodes_equal(vc1, vc2) elif isinstance(t1, self.nodes_classes): self.assert_nodes_equal( list(self.iter_fields(t1)), list(self.iter_fields(t2)), ) else: # Weird bug in astroid that collapses spaces in docstrings sometimes maybe if self.is_astroid_test and isinstance(t1, six.string_types): t1 = re.sub(r'^ +$', '', t1, flags=re.MULTILINE) t2 = re.sub(r'^ +$', '', t2, flags=re.MULTILINE) > self.assertEqual(t1, t2) tests/test_mark_tokens.py:832: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = None def assertEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' operator. """ assertion_func = self._getAssertEqualityFunc(first, second) > assertion_func(first, second, msg=msg) /usr/lib64/python3.8/unittest/case.py:912: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , first = 3, second = 2, msg = '3 != 2' def _baseAssertEqual(self, first, second, msg=None): """The default assertEqual implementation, not type specific.""" if not first == second: standardMsg = '%s != %s' % _common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) > raise self.failureException(msg) E AssertionError: 3 != 2 /usr/lib64/python3.8/unittest/case.py:905: AssertionError During handling of the above exception, another exception occurred: self = def test_splat(self): # See https://bitbucket.org/plas/thonny/issues/151/debugger-crashes-when-encountering-a-splat source = textwrap.dedent(""" arr = [1,2,3,4,5] def print_all(a, b, c, d, e): print(a, b, c, d ,e) print_all(*arr) """) > m = self.create_mark_checker(source) tests/test_mark_tokens.py:339: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:44: in create_mark_checker checker.verify_all_nodes(self) tests/tools.py:114: in verify_all_nodes test_case.assertEqual( E AssertionError: "Func[48 chars] 3,\n 0,\n 3,\n 13],\n de[1024 chars]))])" != "Func[48 chars] 2,\n 0,\n 2,\n 13],\n de[1024 chars]))])" E FunctionDef( E name='print_all', E position=[ E - 3, E ? ^ E + 2, E ? ^ E 0, E - 3, E ? ^ E + 2, E ? ^ E 13], E decorators=None, E args=Arguments( E vararg=None, E kwarg=None, E args=[ E Name(name='a'), E Name(name='b'), E Name(name='c'), E Name(name='d'), E Name(name='e')], E defaults=[], E kwonlyargs=[], E posonlyargs=[], E posonlyargs_annotations=[], E kw_defaults=[], E annotations=[ E None, E None, E None, E None, E None], E varargannotation=None, E kwargannotation=None, E kwonlyargs_annotations=[], E type_comment_args=[ E None, E None, E None, E None, E None], E type_comment_kwonlyargs=[], E type_comment_posonlyargs=[]), E returns=None, E doc_node=None, E body=[Expr(value=Call( E func=Name(name='print'), E args=[ E Name(name='a'), E Name(name='b'), E Name(name='c'), E Name(name='d'), E Name(name='e')], E keywords=[]))]) _______________________________________________________________________ TestAstroid.test_sys_modules _______________________________________________________________________ self = def test_sys_modules(self): """ Verify all nodes on source files obtained from sys.modules. This can take a long time as there are many modules, so it only tests all modules if the environment variable ASTTOKENS_SLOW_TESTS has been set. """ modules = list(sys.modules.values()) if not os.environ.get('ASTTOKENS_SLOW_TESTS'): modules = modules[:20] start = time() for module in modules: # Don't let this test (which runs twice) take longer than 13 minutes # to avoid the travis build time limit of 30 minutes if time() - start > 13 * 60: break try: filename = inspect.getsourcefile(module) except TypeError: continue if not filename: continue filename = os.path.abspath(filename) print(filename) try: with io.open(filename) as f: source = f.read() except OSError: continue if self.is_astroid_test and ( # Astroid fails with a syntax error if a type comment is on its own line re.search(r'^\s*# type: ', source, re.MULTILINE) # Astroid can fail on this file, specifically raising an exception at this line of code: # lambda node: node.name == "NamedTuple" and node.parent.name == "typing" # with the error: # AttributeError: 'If' object has no attribute 'name' # See https://github.com/gristlabs/asttokens/runs/7602147792 # I think the code that causes the problem is: # if sys.version_info >= (3, 11): # NamedTuple = typing.NamedTuple or filename.endswith("typing_extensions.py") ): print('Skipping', filename) continue > self.create_mark_checker(source) tests/test_mark_tokens.py:668: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(225, 34), end=(225, 35), line=" if not message.startswith(('#', 'import ')):\n", index=1044, startpos=7021, endpos=7022) last_token = Token(type=54, string=')', start=(225, 49), end=(225, 50), line=" if not message.startswith(('#', 'import ')):\n", index=1048, startpos=7036, endpos=7037) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError --------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------- /usr/lib64/python3.8/importlib/_bootstrap.py _____________________________________________________________________ TestAstroid.test_trailing_commas _____________________________________________________________________ self = def test_trailing_commas(self): # Make sure we handle trailing commas on comma-separated structures (e.g. tuples, sets, etc.) for source in ( "(a,b,)", "[c,d,]", "{e,f,}", "{h:1,i:2,}"): > self.create_mark_checker(source) tests/test_mark_tokens.py:400: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=54, string='(', start=(1, 0), end=(1, 1), line='(a,b,)', index=0, startpos=0, endpos=1) last_token = Token(type=54, string=')', start=(1, 5), end=(1, 6), line='(a,b,)', index=5, startpos=5, endpos=6) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError _________________________________________________________________________ TestAstroid.test_tuples __________________________________________________________________________ self = def test_tuples(self): def get_tuples(code): m = self.create_mark_checker(code) return [m.atok.get_text(n) for n in m.all_nodes if n.__class__.__name__ == "Tuple"] > self.assertEqual(get_tuples("a,"), ["a,"]) tests/test_mark_tokens.py:407: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/test_mark_tokens.py:404: in get_tuples m = self.create_mark_checker(code) tests/test_mark_tokens.py:33: in create_mark_checker atok = self.create_asttokens(source) tests/test_astroid.py:39: in create_asttokens return ASTTokens(source, tree=tree) asttokens/asttokens.py:127: in __init__ self.mark_tokens(self._tree) asttokens/asttokens.py:139: in mark_tokens MarkTokens(self).visit_tree(root_node) asttokens/mark_tokens.py:66: in visit_tree util.visit_tree(node, self._visit_before_children, self._visit_after_children) asttokens/util.py:263: in visit_tree ret = postvisit(current, par_value, cast(Optional[Token], value)) asttokens/mark_tokens.py:111: in _visit_after_children nfirst, nlast = self._methods.get(self, node.__class__)(node, first, last) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , node = first_token = Token(type=1, string='a', start=(1, 0), end=(1, 1), line='a,', index=0, startpos=0, endpos=1) last_token = Token(type=1, string='a', start=(1, 0), end=(1, 1), line='a,', index=0, startpos=0, endpos=1) def visit_tuple(self, node, first_token, last_token): # type: (AstNode, util.Token, util.Token) -> Tuple[util.Token, util.Token] > assert isinstance(node, ast.Tuple) or isinstance(node, nc._BaseContainer) E AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' asttokens/mark_tokens.py:331: AttributeError ========================================================================= short test summary info ========================================================================== SKIPPED [1] tests/test_mark_tokens.py:183: astroid-2.0 does not support this FAILED tests/test_astroid.py::TestAstroid::test_assignment_expressions - AssertionError: "Func[43 chars] 21,\n 0,\n 21,\n 7],\n de[699 chars]))])" != "Func[43 chars] 2,\n 0,\n 2,\n 7],\n deco[697 char... FAILED tests/test_astroid.py::TestAstroid::test_async_def - AssertionError: "Asyn[47 chars] 6,\n 0,\n 6,\n 13],\n de[519 chars]()])" != "Asyn[47 chars] 3,\n 0,\n 3,\n 13],\n de[519 char... FAILED tests/test_astroid.py::TestAstroid::test_complex_slice_and_parens - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_comprehensions - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_decorators - AssertionError: "Func[40 chars] 6,\n 0,\n 6,\n 5],\n dec[742 chars]()])" != "Func[40 chars] 3,\n 0,\n 3,\n 5],\n dec[742 char... FAILED tests/test_astroid.py::TestAstroid::test_fixture10 - AssertionError: "Clas[68 chars] 4,\n 0,\n 4,\n 14],\n de[5231 chars]])])" != "Clas[68 chars] 2,\n 0,\n 2,\n 14],\n de[5229 ch... FAILED tests/test_astroid.py::TestAstroid::test_fixture11 - AssertionError: "Clas[63 chars] 5,\n 0,\n 5,\n 9],\n dec[78 chars]()])" != "Clas[63 chars] 2,\n 0,\n 2,\n 9],\n dec[78 chars]... FAILED tests/test_astroid.py::TestAstroid::test_fixture13 - AssertionError: "Clas[74 chars] 3,\n 0,\n 3,\n 20],\n de[101 chars]()])" != "Clas[74 chars] 2,\n 0,\n 2,\n 20],\n de[101 char... FAILED tests/test_astroid.py::TestAstroid::test_fixture3 - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_fixture4 - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_fixture5 - AssertionError: "Clas[64 chars] 4,\n 0,\n 4,\n 10],\n de[1986 chars]])])" != "Clas[64 chars] 2,\n 0,\n 2,\n 10],\n de[1986 ch... FAILED tests/test_astroid.py::TestAstroid::test_fixture7 - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_fixture8 - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_fixture9 - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_fstrings - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_mark_tokens_multiline - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_mark_tokens_simple - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_parens_around_func - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_print_function - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_slices - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_splat - AssertionError: "Func[48 chars] 3,\n 0,\n 3,\n 13],\n de[1024 chars]))])" != "Func[48 chars] 2,\n 0,\n 2,\n 13],\n de[1024 ch... FAILED tests/test_astroid.py::TestAstroid::test_sys_modules - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_trailing_commas - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' FAILED tests/test_astroid.py::TestAstroid::test_tuples - AttributeError: module 'astroid.node_classes' has no attribute '_BaseContainer' ========================================================== 24 failed, 89 passed, 1 skipped, 175 warnings in 8.97s ========================================================== ```
alexmojaki commented 1 year ago

Fixed in 2.2.0

kloczek commented 1 year ago

Just tested 2.2.0 and all looks good now.

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.2.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-asttokens-2.2.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/asttokens-2.2.0, configfile: setup.cfg
collected 114 items

tests/test_astroid.py ..............s.................................                                                                                               [ 42%]
tests/test_asttokens.py .......                                                                                                                                      [ 48%]
tests/test_line_numbers.py ...                                                                                                                                       [ 50%]
tests/test_mark_tokens.py ................................................                                                                                           [ 92%]
tests/test_tokenless.py ...                                                                                                                                          [ 95%]
tests/test_util.py .....                                                                                                                                             [100%]

========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/test_mark_tokens.py:188: astroid-2.0 does not support this
============================================================== 113 passed, 1 skipped, 2285 warnings in 13.71s ==============================================================

Thank you 👍

kloczek commented 1 year ago

Tested and now all is clean. Thank you 👍