diff options
| author | Anton Samokhvalov <[email protected]> | 2022-02-10 16:45:17 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:45:17 +0300 |
| commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
| tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py | |
| parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
Restoring authorship annotation for Anton Samokhvalov <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py')
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py b/contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py index 5256ed93d75..9ee8da5478c 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestTreeFragment.py @@ -1,64 +1,64 @@ -from Cython.TestUtils import CythonTest -from Cython.Compiler.TreeFragment import * -from Cython.Compiler.Nodes import * -from Cython.Compiler.UtilNodes import * -import Cython.Compiler.Naming as Naming - -class TestTreeFragments(CythonTest): - - def test_basic(self): - F = self.fragment(u"x = 4") - T = F.copy() - self.assertCode(u"x = 4", T) - - def test_copy_is_taken(self): - F = self.fragment(u"if True: x = 4") - T1 = F.root - T2 = F.copy() - self.assertEqual("x", T2.stats[0].if_clauses[0].body.lhs.name) - T2.stats[0].if_clauses[0].body.lhs.name = "other" - self.assertEqual("x", T1.stats[0].if_clauses[0].body.lhs.name) - - def test_substitutions_are_copied(self): - T = self.fragment(u"y + y").substitute({"y": NameNode(pos=None, name="x")}) - self.assertEqual("x", T.stats[0].expr.operand1.name) - self.assertEqual("x", T.stats[0].expr.operand2.name) +from Cython.TestUtils import CythonTest +from Cython.Compiler.TreeFragment import * +from Cython.Compiler.Nodes import * +from Cython.Compiler.UtilNodes import * +import Cython.Compiler.Naming as Naming + +class TestTreeFragments(CythonTest): + + def test_basic(self): + F = self.fragment(u"x = 4") + T = F.copy() + self.assertCode(u"x = 4", T) + + def test_copy_is_taken(self): + F = self.fragment(u"if True: x = 4") + T1 = F.root + T2 = F.copy() + self.assertEqual("x", T2.stats[0].if_clauses[0].body.lhs.name) + T2.stats[0].if_clauses[0].body.lhs.name = "other" + self.assertEqual("x", T1.stats[0].if_clauses[0].body.lhs.name) + + def test_substitutions_are_copied(self): + T = self.fragment(u"y + y").substitute({"y": NameNode(pos=None, name="x")}) + self.assertEqual("x", T.stats[0].expr.operand1.name) + self.assertEqual("x", T.stats[0].expr.operand2.name) self.assertTrue(T.stats[0].expr.operand1 is not T.stats[0].expr.operand2) - - def test_substitution(self): - F = self.fragment(u"x = 4") - y = NameNode(pos=None, name=u"y") - T = F.substitute({"x" : y}) - self.assertCode(u"y = 4", T) - - def test_exprstat(self): - F = self.fragment(u"PASS") - pass_stat = PassStatNode(pos=None) - T = F.substitute({"PASS" : pass_stat}) + + def test_substitution(self): + F = self.fragment(u"x = 4") + y = NameNode(pos=None, name=u"y") + T = F.substitute({"x" : y}) + self.assertCode(u"y = 4", T) + + def test_exprstat(self): + F = self.fragment(u"PASS") + pass_stat = PassStatNode(pos=None) + T = F.substitute({"PASS" : pass_stat}) self.assertTrue(isinstance(T.stats[0], PassStatNode), T) - - def test_pos_is_transferred(self): - F = self.fragment(u""" - x = y - x = u * v ** w - """) - T = F.substitute({"v" : NameNode(pos=None, name="a")}) - v = F.root.stats[1].rhs.operand2.operand1 - a = T.stats[1].rhs.operand2.operand1 + + def test_pos_is_transferred(self): + F = self.fragment(u""" + x = y + x = u * v ** w + """) + T = F.substitute({"v" : NameNode(pos=None, name="a")}) + v = F.root.stats[1].rhs.operand2.operand1 + a = T.stats[1].rhs.operand2.operand1 self.assertEqual(v.pos, a.pos) - - def test_temps(self): - TemplateTransform.temp_name_counter = 0 - F = self.fragment(u""" - TMP - x = TMP - """) - T = F.substitute(temps=[u"TMP"]) - s = T.body.stats + + def test_temps(self): + TemplateTransform.temp_name_counter = 0 + F = self.fragment(u""" + TMP + x = TMP + """) + T = F.substitute(temps=[u"TMP"]) + s = T.body.stats self.assertTrue(isinstance(s[0].expr, TempRefNode)) self.assertTrue(isinstance(s[1].rhs, TempRefNode)) self.assertTrue(s[0].expr.handle is s[1].rhs.handle) - -if __name__ == "__main__": - import unittest - unittest.main() + +if __name__ == "__main__": + import unittest + unittest.main() |
