Skip to content

Commit

Permalink
Adapt tests for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Oct 10, 2023
1 parent 50d3797 commit 26f5808
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 59 deletions.
8 changes: 4 additions & 4 deletions pylasu/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def assert_single_properties_are_equal(case, expected_property, expected_prop_va
def assert_multi_properties_are_equal(case, expected_property, expected_prop_value, actual_prop_value, context,
consider_position):
# TODO IgnoreChildren
case.assertEquals(actual_prop_value is None, expected_prop_value is None,
f"{context}.{expected_property.name} nullness")
case.assertEqual(actual_prop_value is None, expected_prop_value is None,
f"{context}.{expected_property.name} nullness")
if actual_prop_value is not None and expected_prop_value is not None:
case.assertEquals(len(actual_prop_value), len(expected_prop_value),
f"{context}.{expected_property.name} length")
case.assertEqual(len(actual_prop_value), len(expected_prop_value),
f"{context}.{expected_property.name} length")
for expected_it, actual_it, i in \
zip(expected_prop_value, actual_prop_value, range(len(expected_prop_value))):
assert_asts_are_equal(case, expected_it, actual_it, f"{context}[{i}]",
Expand Down
4 changes: 2 additions & 2 deletions tests/mapping/test_parse_tree_to_ast_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_simple_entities_transformer(self):
entity BAR { }
}
"""))
self.assertEquals(expected_ast, actual_ast)
self.assertEqual(expected_ast, actual_ast)

def test_entities_with_features_transformer(self):
transformer = ParseTreeToASTTransformer(allow_generic_node=False)
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_entities_with_features_transformer(self):
C: FOO;
}
}"""))
self.assertEquals(expected_ast, actual_ast)
self.assertEqual(expected_ast, actual_ast)

def parse_entities(self, code: str) -> AntlrEntityParser.ModuleContext:
lexer = AntlrEntityLexer(InputStream(code))
Expand Down
12 changes: 6 additions & 6 deletions tests/test_metamodel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def open_out_stream(self, other=None):
resource.append(eClass)
with BytesIO() as out:
resource.save(out)
self.assertEquals(
self.assertEqual(
json.loads('''{
"eClass": "http://www.eclipse.org/emf/2002/Ecore#//EPackage",
"nsPrefix": "test",
Expand Down Expand Up @@ -101,24 +101,24 @@ def test_build_metamodel_single_package(self):
mb = MetamodelBuilder("tests.fixtures", "https://strumenta.com/pylasu/test/fixtures")
box = mb.provide_class(Box)
self.assertIsInstance(box(), EObject)
self.assertEquals(box.eClass.ePackage, mb.package)
self.assertEqual(box.eClass.ePackage, mb.package)
self.assertTrue(box.eClass in mb.package.eContents)
self.assertIsNotNone(
next((a for a in box.eClass.eAllAttributes() if a.name == "name"), None))
self.assertEquals(1, len(box.eClass.eAllAttributes()))
self.assertEqual(1, len(box.eClass.eAllAttributes()))

def test_build_metamodel_single_package_inheritance(self):
mb = MetamodelBuilder("tests.fixtures", "https://strumenta.com/pylasu/test/fixtures")
box = mb.provide_class(ReinforcedBox)
self.assertIsInstance(box(), EObject)
self.assertEquals(box.eClass.ePackage, mb.package)
self.assertEquals(2, len(mb.package.eContents))
self.assertEqual(box.eClass.ePackage, mb.package)
self.assertEqual(2, len(mb.package.eContents))
self.assertTrue(box.eClass in mb.package.eContents)
self.assertIsNotNone(
next((a for a in box.eClass.eAllAttributes() if a.name == "name"), None))
self.assertIsNotNone(
next((a for a in box.eClass.eAllAttributes() if a.name == "strength"), None))
self.assertEquals(2, len(box.eClass.eAllAttributes()))
self.assertEqual(2, len(box.eClass.eAllAttributes()))


STARLASU_MODEL_JSON = '''{
Expand Down
30 changes: 15 additions & 15 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class ModelTest(unittest.TestCase):

def test_reference_by_name_unsolved_str(self):
ref_unsolved = ReferenceByName[SomeNode]("foo")
self.assertEquals("Ref(foo)[Unsolved]", str(ref_unsolved))
self.assertEqual("Ref(foo)[Unsolved]", str(ref_unsolved))

def test_reference_by_name_solved_str(self):
ref_solved = ReferenceByName[SomeNode]("foo", SomeNode(name="foo"))
self.assertEquals("Ref(foo)[Solved]", str(ref_solved))
self.assertEqual("Ref(foo)[Solved]", str(ref_solved))

def test_try_to_resolve_positive_case_same_case(self):
ref = ReferenceByName[SomeNode]("foo")
Expand All @@ -61,9 +61,9 @@ def test_empty_node(self):

def test_node_with_position(self):
node = Node().with_position(Position(Point(1, 0), Point(2, 1)))
self.assertEquals(Position(Point(1, 0), Point(2, 1)), node.position)
self.assertEqual(Position(Point(1, 0), Point(2, 1)), node.position)
node = SomeNode("").with_position(Position(Point(1, 0), Point(2, 1)))
self.assertEquals(Position(Point(1, 0), Point(2, 1)), node.position)
self.assertEqual(Position(Point(1, 0), Point(2, 1)), node.position)

def test_node_properties(self):
node = SomeNode("n").with_position(Position(Point(1, 0), Point(2, 1)))
Expand All @@ -84,15 +84,15 @@ def test_scope_lookup_0(self):
local_symbol = SomeSymbol(name='a', index=0)
scope = Scope(symbols={'a': [local_symbol]}, parent=Scope(symbols={'a': [SomeSymbol(name='a', index=1)]}))
result = scope.lookup(symbol_name='a')
self.assertEquals(result, local_symbol)
self.assertEqual(result, local_symbol)
self.assertIsInstance(result, Symbol)

def test_scope_lookup_1(self):
"""Symbol found in upper scope with name and default type"""
upper_symbol = SomeSymbol(name='a', index=0)
scope = Scope(symbols={'b': [SomeSymbol(name='b', index=0)]}, parent=Scope(symbols={'a': [upper_symbol]}))
result = scope.lookup(symbol_name='a')
self.assertEquals(result, upper_symbol)
self.assertEqual(result, upper_symbol)
self.assertIsInstance(result, Symbol)

def test_scope_lookup_2(self):
Expand All @@ -111,15 +111,15 @@ def test_scope_lookup_4(self):
upper_symbol = SomeSymbol(name='a', index=0)
scope = Scope(symbols={'b': [SomeSymbol(name='b', index=0)]}, parent=Scope(symbols={'a': [upper_symbol]}))
result = scope.lookup(symbol_name='a', symbol_type=SomeSymbol)
self.assertEquals(result, upper_symbol)
self.assertEqual(result, upper_symbol)
self.assertIsInstance(result, SomeSymbol)

def test_scope_lookup_5(self):
"""Symbol found in upper scope with name and type (local with different type)"""
upper_symbol = SomeSymbol(name='a', index=0)
scope = Scope(symbols={'a': [AnotherSymbol(name='a', index=0)]}, parent=Scope(symbols={'a': [upper_symbol]}))
result = scope.lookup(symbol_name='a', symbol_type=SomeSymbol)
self.assertEquals(result, upper_symbol)
self.assertEqual(result, upper_symbol)
self.assertIsInstance(result, SomeSymbol)

def test_scope_lookup_6(self):
Expand All @@ -138,15 +138,15 @@ def test_scope_lookup_7(self):

def test_node_properties_meta(self):
pds = [pd for pd in sorted(SomeNode.node_properties, key=lambda x: x.name)]
self.assertEquals(5, len(pds))
self.assertEquals("bar", pds[0].name)
self.assertEqual(5, len(pds))
self.assertEqual("bar", pds[0].name)
self.assertFalse(pds[0].provides_nodes)
self.assertEquals("foo", pds[1].name)
self.assertEqual("foo", pds[1].name)
self.assertFalse(pds[1].provides_nodes)
self.assertEquals("multiple", pds[2].name)
self.assertEqual("multiple", pds[2].name)
self.assertTrue(pds[2].provides_nodes)
self.assertEquals(Multiplicity.MANY, pds[2].multiplicity)
self.assertEquals("name", pds[3].name)
self.assertEqual(Multiplicity.MANY, pds[2].multiplicity)
self.assertEqual("name", pds[3].name)
self.assertFalse(pds[3].provides_nodes)
self.assertEquals("ref", pds[4].name)
self.assertEqual("ref", pds[4].name)
self.assertTrue(pds[4].provides_nodes)
4 changes: 2 additions & 2 deletions tests/test_parse_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_parse_tree_origin(self):
origin = ParseTreeOrigin(parse_tree)
position = origin.position
self.assertIsNotNone(position)
self.assertEquals(position.start, Point(1, 0))
self.assertEquals(position.end, Point(2, 2))
self.assertEqual(position.start, Point(1, 0))
self.assertEqual(position.end, Point(2, 2))

def test_ast_gen(self):
generate_nodes_classes_for_parser(SimpleLangParser, globals())
Expand Down
10 changes: 5 additions & 5 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CW(Node):

class ProcessingTest(unittest.TestCase):
def test_search_by_type(self):
self.assertEquals(["1", "2", "3", "4", "5", "6"], [i.name for i in box.search_by_type(Item)])
self.assertEquals(
self.assertEqual(["1", "2", "3", "4", "5", "6"], [i.name for i in box.search_by_type(Item)])
self.assertEqual(
["root", "first", "1", "2", "big", "small", "3", "4", "5", "6"],
[n.name for n in box.search_by_type(Node)]
)
Expand All @@ -39,8 +39,8 @@ def test_replace_in_list(self):
b = BW(a1, [a2, a3])
b.assign_parents()
a2.replace_with(a4)
self.assertEquals("4", b.many_as[0].s)
self.assertEquals(BW(a1, [a4, a3]), b)
self.assertEqual("4", b.many_as[0].s)
self.assertEqual(BW(a1, [a4, a3]), b)

def test_replace_in_set(self):
a1 = AW("1")
Expand All @@ -57,4 +57,4 @@ def test_replace_single(self):
b = BW(a1, [])
b.assign_parents()
a1.replace_with(a2)
self.assertEquals("2", b.a.s)
self.assertEqual("2", b.a.s)
18 changes: 9 additions & 9 deletions tests/test_transpilation_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def test_serialize_transpilation_issue(self):
message="some issue",
severity=starlasu.IssueSeverity.getEEnumLiteral("WARNING"))]
)
self.assertEquals("a:1", tt.originalCode)
self.assertEquals("b:2", tt.generatedCode)
self.assertEquals("some issue", tt.issues[0].message)
self.assertEquals("a", tt.sourceResult.root.name)
self.assertEquals(1, tt.sourceResult.root.value)
self.assertEquals("b", tt.targetResult.root.name)
self.assertEquals(2, tt.targetResult.root.value)
self.assertEqual("a:1", tt.originalCode)
self.assertEqual("b:2", tt.generatedCode)
self.assertEqual("some issue", tt.issues[0].message)
self.assertEqual("a", tt.sourceResult.root.name)
self.assertEqual(1, tt.sourceResult.root.value)
self.assertEqual("b", tt.targetResult.root.name)
self.assertEqual(2, tt.targetResult.root.value)

expected = """{
"eClass" : "https://strumenta.com/kolasu/transpilation/v1#//TranspilationTrace",
Expand All @@ -69,7 +69,7 @@ def test_serialize_transpilation_issue(self):
"severity" : "WARNING"
} ]
}"""
self.assertEquals(json.loads(expected), json.loads(tt.save_as_json("foo.json")))
self.assertEqual(json.loads(expected), json.loads(tt.save_as_json("foo.json")))

def test_serialize_transpilation_from_nodes(self):
mmb = MetamodelBuilder("tests.fixtures", "https://strumenta.com/pylasu/test/fixtures")
Expand Down Expand Up @@ -112,4 +112,4 @@ def test_serialize_transpilation_from_nodes(self):
}
}"""
as_json = tt.save_as_json("foo.json", mmb.generate())
self.assertEquals(json.loads(expected), json.loads(as_json))
self.assertEqual(json.loads(expected), json.loads(as_json))
16 changes: 8 additions & 8 deletions tests/test_traversing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

class TraversingTest(unittest.TestCase):
def test_walk_within_with_outside_position(self):
self.assertEquals([], [n.name for n in box.walk_within(pos(15, 1, 15, 1))])
self.assertEqual([], [n.name for n in box.walk_within(pos(15, 1, 15, 1))])

def test_walk_within_with_root_position(self):
self.assertEquals(
self.assertEqual(
["root", "first", "1", "2", "big", "small", "3", "4", "5", "6"],
[n.name for n in box.walk_within(box.position)]
)

def test_walk_within_with_leaf_position(self):
self.assertEquals(["6"], [n.name for n in box.walk_within(pos(13, 3, 13, 9))])
self.assertEqual(["6"], [n.name for n in box.walk_within(pos(13, 3, 13, 9))])

def test_walk_within_with_subtree_position(self):
self.assertEquals(["small", "3", "4", "5"], [n.name for n in box.walk_within(pos(7, 5, 11, 5))])
self.assertEqual(["small", "3", "4", "5"], [n.name for n in box.walk_within(pos(7, 5, 11, 5))])

def test_walk_depth_first(self):
self.assertEquals(
self.assertEqual(
["root", "first", "1", "2", "big", "small", "3", "4", "5", "6"],
[n.name for n in box.walk()]
)

def test_walk_leaves_first(self):
self.assertEquals(
self.assertEqual(
["1", "first", "2", "3", "4", "5", "small", "big", "6", "root"],
[n.name for n in box.walk_leaves_first()]
)

def test_walk_descendants(self):
self.assertEquals(
self.assertEqual(
["first", "1", "2", "big", "small", "3", "4", "5", "6"],
[n.name for n in box.walk_descendants()]
)

def test_walk_ancestors(self):
box.assign_parents()
item4 = box.contents[2].contents[0].contents[1]
self.assertEquals(["small", "big", "root"], [n.name for n in item4.walk_ancestors()])
self.assertEqual(["small", "big", "root"], [n.name for n in item4.walk_ancestors()])
16 changes: 8 additions & 8 deletions tests/transformation/test_ast_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_identitiy_transformer(self):
SetStatement(variable="foo", value=123),
DisplayIntStatement(value=456)])
transformed_cu = transformer.transform(cu)
self.assertEquals(cu, transformed_cu)
self.assertEquals(transformed_cu.origin, cu)
self.assertEqual(cu, transformed_cu)
self.assertEqual(transformed_cu.origin, cu)

def test_translate_binary_expression(self):
"""Example of transformation to perform a refactoring within the same language."""
Expand All @@ -87,7 +87,7 @@ def generic_binary_expression_to_ast(source: GenericBinaryExpression):
my_transformer.register_identity_transformation(IntLiteral)
source = GenericBinaryExpression(Operator.MULT, IntLiteral(7), IntLiteral(8))
t1 = my_transformer.transform(source)
self.assertEquals(t1, source.to_ast())
self.assertEqual(t1, source.to_ast())

def test_translate_across_languages(self):
transformer = ASTTransformer(allow_generic_node=False)
Expand All @@ -98,7 +98,7 @@ def test_translate_across_languages(self):
transformer.register_node_factory(
ALangMult,
lambda source: BLangMult(transformer.transform(source.left), transformer.transform(source.right)))
self.assertEquals(
self.assertEqual(
BLangMult(
BLangSum(
BLangIntLiteral(1),
Expand All @@ -123,8 +123,8 @@ def test_dropping_nodes(self):
cu = CU(statements=[DisplayIntStatement(value=456), SetStatement(variable="foo", value=123)])
transformed_cu = transformer.transform(cu)
# TODO not yet supported self.assertTrue(transformed_cu.hasValidParents())
self.assertEquals(transformed_cu.origin, cu)
self.assertEquals(1, len(transformed_cu.statements))
self.assertEqual(transformed_cu.origin, cu)
self.assertEqual(1, len(transformed_cu.statements))
assert_asts_are_equal(self, cu.statements[1], transformed_cu.statements[0])

def test_nested_origin(self):
Expand All @@ -135,7 +135,7 @@ def test_nested_origin(self):
cu = CU(statements=[DisplayIntStatement(value=456)])
transformed_cu = transformer.transform(cu)
# TODO not yet supported self.assertTrue(transformed_cu.hasValidParents())
self.assertEquals(transformed_cu.origin, cu)
self.assertEqual(transformed_cu.origin, cu)
self.assertIsInstance(transformed_cu.statements[0].origin, GenericNode)

def test_transforming_one_node_to_many(self):
Expand All @@ -146,7 +146,7 @@ def test_transforming_one_node_to_many(self):
original = BarRoot([BarStmt("a"), BarStmt("b")])
transformed = transformer.transform(original)
# TODO not yet supported assertTrue { transformed.hasValidParents() }
self.assertEquals(transformed.origin, original)
self.assertEqual(transformed.origin, original)
assert_asts_are_equal(
self,
BazRoot([BazStmt("a-1"), BazStmt("a-2"), BazStmt("b-1"), BazStmt("b-2")]),
Expand Down

0 comments on commit 26f5808

Please sign in to comment.