| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 import test.test_support | 1 import test.test_support |
| 2 compiler = test.test_support.import_module('compiler', deprecated=True) | 2 compiler = test.test_support.import_module('compiler', deprecated=True) |
| 3 from compiler.ast import flatten | 3 from compiler.ast import flatten |
| 4 import os, sys, time, unittest | 4 import os, sys, time, unittest |
| 5 from random import random | 5 from random import random |
| 6 from StringIO import StringIO | 6 from StringIO import StringIO |
| 7 | 7 |
| 8 # How much time in seconds can pass before we print a 'Still working' message. | 8 # How much time in seconds can pass before we print a 'Still working' message. |
| 9 _PRINT_WORKING_MSG_INTERVAL = 5 * 60 | 9 _PRINT_WORKING_MSG_INTERVAL = 5 * 60 |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 'def f():\n' | 158 'def f():\n' |
| 159 ' with TrivialContext() as tc:\n' | 159 ' with TrivialContext() as tc:\n' |
| 160 ' return 1\n' | 160 ' return 1\n' |
| 161 'result = f()', | 161 'result = f()', |
| 162 '<string>', | 162 '<string>', |
| 163 'exec' ) | 163 'exec' ) |
| 164 dct = {'TrivialContext': TrivialContext} | 164 dct = {'TrivialContext': TrivialContext} |
| 165 exec c in dct | 165 exec c in dct |
| 166 self.assertEquals(dct.get('result'), 1) | 166 self.assertEquals(dct.get('result'), 1) |
| 167 | 167 |
| 168 def testWithMult(self): | |
| 169 events = [] | |
| 170 class Ctx: | |
| 171 def __init__(self, n): | |
| 172 self.n = n | |
| 173 def __enter__(self): | |
| 174 events.append(self.n) | |
| 175 def __exit__(self, *args): | |
| 176 pass | |
| 177 c = compiler.compile('from __future__ import with_statement\n' | |
| 178 'def f():\n' | |
| 179 ' with Ctx(1) as tc, Ctx(2) as tc2:\n' | |
| 180 ' return 1\n' | |
| 181 'result = f()', | |
| 182 '<string>', | |
| 183 'exec' ) | |
| 184 dct = {'Ctx': Ctx} | |
| 185 exec c in dct | |
| 186 self.assertEquals(dct.get('result'), 1) | |
|
Benjamin
2009/05/02 18:22:06
Why using .get() here?
Georg
2009/05/02 18:48:00
Following the above example. Probably to not get
| |
| 187 self.assertEquals(events, [1, 2]) | |
| 188 | |
| 168 def testGlobal(self): | 189 def testGlobal(self): |
| 169 code = compiler.compile('global x\nx=1', '<string>', 'exec') | 190 code = compiler.compile('global x\nx=1', '<string>', 'exec') |
| 170 d1 = {'__builtins__': {}} | 191 d1 = {'__builtins__': {}} |
| 171 d2 = {} | 192 d2 = {} |
| 172 exec code in d1, d2 | 193 exec code in d1, d2 |
| 173 # x should be in the globals dict | 194 # x should be in the globals dict |
| 174 self.assertEquals(d1.get('x'), 1) | 195 self.assertEquals(d1.get('x'), 1) |
| 175 | 196 |
| 176 def testPrintFunction(self): | 197 def testPrintFunction(self): |
| 177 c = compiler.compile('from __future__ import print_function\n' | 198 c = compiler.compile('from __future__ import print_function\n' |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 273 |
| 253 ############################################################################### | 274 ############################################################################### |
| 254 | 275 |
| 255 def test_main(): | 276 def test_main(): |
| 256 global TEST_ALL | 277 global TEST_ALL |
| 257 TEST_ALL = test.test_support.is_resource_enabled("compiler") | 278 TEST_ALL = test.test_support.is_resource_enabled("compiler") |
| 258 test.test_support.run_unittest(CompilerTest) | 279 test.test_support.run_unittest(CompilerTest) |
| 259 | 280 |
| 260 if __name__ == "__main__": | 281 if __name__ == "__main__": |
| 261 test_main() | 282 test_main() |
| OLD | NEW |