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 / TestUtilityLoad.py
bloba7ec3ef8fe7ab6d7a89df52e561fef666f123d60
1 import unittest
3 from Cython.Compiler import Code, UtilityCode
6 def strip_2tup(tup):
7 return tup[0] and tup[0].strip(), tup[1] and tup[1].strip()
9 class TestUtilityLoader(unittest.TestCase):
10 """
11 Test loading UtilityCodes
12 """
14 expected = "test {{loader}} prototype", "test {{loader}} impl"
16 required = "req {{loader}} proto", "req {{loader}} impl"
18 context = dict(loader='Loader')
20 name = "TestUtilityLoader"
21 filename = "TestUtilityLoader.c"
22 cls = Code.UtilityCode
24 def test_load_as_string(self):
25 got = strip_2tup(self.cls.load_as_string(self.name))
26 self.assertEquals(got, self.expected)
28 got = strip_2tup(self.cls.load_as_string(self.name, self.filename))
29 self.assertEquals(got, self.expected)
31 def test_load(self):
32 utility = self.cls.load(self.name)
33 got = strip_2tup((utility.proto, utility.impl))
34 self.assertEquals(got, self.expected)
36 required, = utility.requires
37 got = strip_2tup((required.proto, required.impl))
38 self.assertEquals(got, self.required)
40 utility = self.cls.load(self.name, from_file=self.filename)
41 got = strip_2tup((utility.proto, utility.impl))
42 self.assertEquals(got, self.expected)
44 utility = self.cls.load_cached(self.name, from_file=self.filename)
45 got = strip_2tup((utility.proto, utility.impl))
46 self.assertEquals(got, self.expected)
49 class TestTempitaUtilityLoader(TestUtilityLoader):
50 """
51 Test loading UtilityCodes with Tempita substitution
52 """
53 expected_tempita = (TestUtilityLoader.expected[0].replace('{{loader}}', 'Loader'),
54 TestUtilityLoader.expected[1].replace('{{loader}}', 'Loader'))
56 required_tempita = (TestUtilityLoader.required[0].replace('{{loader}}', 'Loader'),
57 TestUtilityLoader.required[1].replace('{{loader}}', 'Loader'))
59 cls = Code.TempitaUtilityCode
61 def test_load_as_string(self):
62 got = strip_2tup(self.cls.load_as_string(self.name, context=self.context))
63 self.assertEquals(got, self.expected_tempita)
65 def test_load(self):
66 utility = self.cls.load(self.name, context=self.context)
67 got = strip_2tup((utility.proto, utility.impl))
68 self.assertEquals(got, self.expected_tempita)
70 required, = utility.requires
71 got = strip_2tup((required.proto, required.impl))
72 self.assertEquals(got, self.required_tempita)
74 utility = self.cls.load(self.name, from_file=self.filename, context=self.context)
75 got = strip_2tup((utility.proto, utility.impl))
76 self.assertEquals(got, self.expected_tempita)
79 class TestCythonUtilityLoader(TestTempitaUtilityLoader):
80 """
81 Test loading CythonUtilityCodes
82 """
84 # Just change the attributes and run the same tests
85 expected = None, "test {{cy_loader}} impl"
86 expected_tempita = None, "test CyLoader impl"
88 required = None, "req {{cy_loader}} impl"
89 required_tempita = None, "req CyLoader impl"
91 context = dict(cy_loader='CyLoader')
93 name = "TestCyUtilityLoader"
94 filename = "TestCyUtilityLoader.pyx"
95 cls = UtilityCode.CythonUtilityCode
97 # Small hack to pass our tests above
98 cls.proto = None
100 test_load = TestUtilityLoader.test_load
101 test_load_tempita = TestTempitaUtilityLoader.test_load