[pypy-svn] r41033 - pypy/dist/pypy/tool/build/test

guido at codespeak.net guido at codespeak.net
Thu Mar 22 13:16:41 CET 2007


Author: guido
Date: Thu Mar 22 13:16:39 2007
New Revision: 41033

Modified:
   pypy/dist/pypy/tool/build/test/test_compileoption.py
Log:
Added test that uses a combined config in an actual translation.


Modified: pypy/dist/pypy/tool/build/test/test_compileoption.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_compileoption.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_compileoption.py	Thu Mar 22 13:16:39 2007
@@ -1,3 +1,4 @@
+import py
 from pypy.tool.build.compileoption import combine_config
 from pypy.config.config import OptionDescription, BoolOption, IntOption, \
                                ArbitraryOption, FloatOption, ChoiceOption, \
@@ -14,3 +15,38 @@
     assert isinstance(combined, Config)
     assert combined.foo == False
     assert combined.bar == False
+
+def test_annotator_folding():
+    from pypy.translator.interactive import Translation
+
+    gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
+    gcgroup = OptionDescription('gc', '', [gcoption])
+    descr1 = OptionDescription('pypy', '', [gcgroup])
+    c1 = Config(descr1)
+
+    foooption = IntOption('foo', 'foo', default=0)
+    descr2 = OptionDescription('foo', '', [foooption])
+    c2 = Config(descr2)
+
+    config = combine_config(c1, c2, 'pypy')
+    
+    def f(x):
+        if config.gc.name == 'ref':
+            return x + 1
+        else:
+            return 'foo'
+
+    t = Translation(f)
+    t.rtype([int])
+    
+    block = t.context.graphs[0].startblock
+    assert len(block.exits[0].target.operations) == 0
+    assert len(block.operations) == 1
+    assert len(block.exits) == 1
+    assert block.operations[0].opname == 'int_add'
+
+    assert config._freeze_()
+    # does not raise, since it does not change the attribute
+    config.gc.name = "ref"
+    py.test.raises(TypeError, 'config.gc.name = "framework"')
+



More information about the Pypy-commit mailing list