[Python-checkins] r62460 - python/branches/tlee-ast-optimize/Lib/test/test_optimizer.py
thomas.lee
python-checkins at python.org
Tue Apr 22 15:33:33 CEST 2008
Author: thomas.lee
Date: Tue Apr 22 15:33:33 2008
New Revision: 62460
Log:
Use a dict for constant attribute lookups.
Modified:
python/branches/tlee-ast-optimize/Lib/test/test_optimizer.py
Modified: python/branches/tlee-ast-optimize/Lib/test/test_optimizer.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_optimizer.py (original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_optimizer.py Tue Apr 22 15:33:33 2008
@@ -90,14 +90,14 @@
("13|7", 15)
)
+ attrmap = {
+ int: 'n',
+ str: 's'
+ }
+
for code, expected in tests:
ast = self.compileast(code)
- if type(expected) is int:
- actual = ast.body[0].value.n
- elif type(expected) is str:
- actual = ast.body[0].value.s
- else:
- raise Exception("Unexpected value: %s" % (expected,))
+ actual = getattr(ast.body[0].value, attrmap[type(expected)])
self.assertEqual(expected, actual)
def test_binop_fold_num_with_variable(self):
More information about the Python-checkins
mailing list