Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cython / src / Cython / Compiler / Tests / TestTreeFragment.py
blob3352c71d57e6e749003f39335460fc2c41d28d46
1 from Cython.TestUtils import CythonTest
2 from Cython.Compiler.TreeFragment import *
3 from Cython.Compiler.Nodes import *
4 from Cython.Compiler.UtilNodes import *
5 import Cython.Compiler.Naming as Naming
7 class TestTreeFragments(CythonTest):
9 def test_basic(self):
10 F = self.fragment(u"x = 4")
11 T = F.copy()
12 self.assertCode(u"x = 4", T)
14 def test_copy_is_taken(self):
15 F = self.fragment(u"if True: x = 4")
16 T1 = F.root
17 T2 = F.copy()
18 self.assertEqual("x", T2.stats[0].if_clauses[0].body.lhs.name)
19 T2.stats[0].if_clauses[0].body.lhs.name = "other"
20 self.assertEqual("x", T1.stats[0].if_clauses[0].body.lhs.name)
22 def test_substitutions_are_copied(self):
23 T = self.fragment(u"y + y").substitute({"y": NameNode(pos=None, name="x")})
24 self.assertEqual("x", T.stats[0].expr.operand1.name)
25 self.assertEqual("x", T.stats[0].expr.operand2.name)
26 self.assert_(T.stats[0].expr.operand1 is not T.stats[0].expr.operand2)
28 def test_substitution(self):
29 F = self.fragment(u"x = 4")
30 y = NameNode(pos=None, name=u"y")
31 T = F.substitute({"x" : y})
32 self.assertCode(u"y = 4", T)
34 def test_exprstat(self):
35 F = self.fragment(u"PASS")
36 pass_stat = PassStatNode(pos=None)
37 T = F.substitute({"PASS" : pass_stat})
38 self.assert_(isinstance(T.stats[0], PassStatNode), T)
40 def test_pos_is_transferred(self):
41 F = self.fragment(u"""
42 x = y
43 x = u * v ** w
44 """)
45 T = F.substitute({"v" : NameNode(pos=None, name="a")})
46 v = F.root.stats[1].rhs.operand2.operand1
47 a = T.stats[1].rhs.operand2.operand1
48 self.assertEquals(v.pos, a.pos)
50 def test_temps(self):
51 TemplateTransform.temp_name_counter = 0
52 F = self.fragment(u"""
53 TMP
54 x = TMP
55 """)
56 T = F.substitute(temps=[u"TMP"])
57 s = T.body.stats
58 self.assert_(isinstance(s[0].expr, TempRefNode))
59 self.assert_(isinstance(s[1].rhs, TempRefNode))
60 self.assert_(s[0].expr.handle is s[1].rhs.handle)
62 if __name__ == "__main__":
63 import unittest
64 unittest.main()