Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cython / src / Cython / Tests / TestCodeWriter.py
blob6f9b5478a93849b0505dfab83a2ce6ab2271423d
1 from Cython.TestUtils import CythonTest
3 class TestCodeWriter(CythonTest):
4 # CythonTest uses the CodeWriter heavily, so do some checking by
5 # roundtripping Cython code through the test framework.
7 # Note that this test is dependant upon the normal Cython parser
8 # to generate the input trees to the CodeWriter. This save *a lot*
9 # of time; better to spend that time writing other tests than perfecting
10 # this one...
12 # Whitespace is very significant in this process:
13 # - always newline on new block (!)
14 # - indent 4 spaces
15 # - 1 space around every operator
17 def t(self, codestr):
18 self.assertCode(codestr, self.fragment(codestr).root)
20 def test_print(self):
21 self.t(u"""
22 print x, y
23 print x + y ** 2
24 print x, y, z,
25 """)
27 def test_if(self):
28 self.t(u"if x:\n pass")
30 def test_ifelifelse(self):
31 self.t(u"""
32 if x:
33 pass
34 elif y:
35 pass
36 elif z + 34 ** 34 - 2:
37 pass
38 else:
39 pass
40 """)
42 def test_def(self):
43 self.t(u"""
44 def f(x, y, z):
45 pass
46 def f(x = 34, y = 54, z):
47 pass
48 """)
50 def test_longness_and_signedness(self):
51 self.t(u"def f(unsigned long long long long long int y):\n pass")
53 def test_signed_short(self):
54 self.t(u"def f(signed short int y):\n pass")
56 def test_typed_args(self):
57 self.t(u"def f(int x, unsigned long int y):\n pass")
59 def test_cdef_var(self):
60 self.t(u"""
61 cdef int hello
62 cdef int hello = 4, x = 3, y, z
63 """)
65 def test_for_loop(self):
66 self.t(u"""
67 for x, y, z in f(g(h(34) * 2) + 23):
68 print x, y, z
69 else:
70 print 43
71 """)
73 def test_inplace_assignment(self):
74 self.t(u"x += 43")
76 def test_attribute(self):
77 self.t(u"a.x")
79 if __name__ == "__main__":
80 import unittest
81 unittest.main()