python-libcst/650-sorting-in-test_ordering.patch

41 lines
1.8 KiB
Diff

From d61f6cbd938c361fc746faff3d3d3ccfe273b9fc Mon Sep 17 00:00:00 2001
From: Stanislav Levin <slev@altlinux.org>
Date: Fri, 18 Feb 2022 13:18:04 +0300
Subject: [PATCH] tests: Fix assumption about sorting in test_ordering
The test wrongly assumed that `first_assignment.references`
is ordered collection, while actually it is `set`.
Fixes: https://github.com/Instagram/LibCST/issues/442
Signed-off-by: Stanislav Levin <slev@altlinux.org>
---
libcst/metadata/tests/test_scope_provider.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/libcst/metadata/tests/test_scope_provider.py
+++ b/libcst/metadata/tests/test_scope_provider.py
@@ -1534,19 +1534,20 @@ class ScopeProviderTest(UnitTest):
first_assignment = list(global_scope.assignments)[0]
assert isinstance(first_assignment, cst.metadata.Assignment)
self.assertEqual(first_assignment.node, import_stmt)
- global_refs = list(first_assignment.references)
+ global_refs = first_assignment.references
self.assertEqual(len(global_refs), 2)
+ global_refs_nodes = {x.node for x in global_refs}
class_def = ensure_type(m.body[1], cst.ClassDef)
x = ensure_type(
ensure_type(class_def.body.body[0], cst.SimpleStatementLine).body[0],
cst.Assign,
)
- self.assertEqual(x.value, global_refs[0].node)
+ self.assertIn(x.value, global_refs_nodes)
class_b = ensure_type(
ensure_type(class_def.body.body[1], cst.SimpleStatementLine).body[0],
cst.Assign,
)
- self.assertEqual(class_b.value, global_refs[1].node)
+ self.assertIn(class_b.value, global_refs_nodes)
class_accesses = list(scopes[x].accesses)
self.assertEqual(len(class_accesses), 3)