[pypy-svn] r9456 - in pypy/dist/pypy/translator: . test

pedronis at codespeak.net pedronis at codespeak.net
Wed Feb 23 16:28:33 CET 2005


Author: pedronis
Date: Wed Feb 23 16:28:33 2005
New Revision: 9456

Modified:
   pypy/dist/pypy/translator/genc.py
   pypy/dist/pypy/translator/test/snippet.py
   pypy/dist/pypy/translator/test/test_ctrans.py
Log:
added test about global inst with __init__ set attributes



Modified: pypy/dist/pypy/translator/genc.py
==============================================================================
--- pypy/dist/pypy/translator/genc.py	(original)
+++ pypy/dist/pypy/translator/genc.py	Wed Feb 23 16:28:33 2005
@@ -247,7 +247,8 @@
             content.sort()
             for key, value in content:
                 if self.should_translate_attr(instance, key):
-                    yield '%s.%s = %s' % (name, key, self.nameof(value))
+                    line = '%s.%s = %s' % (name, key, self.nameof(value))
+                    yield line
         if hasattr(instance,'__reduce_ex__'):
             import copy_reg
             reduced = instance.__reduce_ex__()
@@ -445,7 +446,7 @@
         print >> f, self.C_HEADER
 
         # function implementations
-        while self.pendingfunctions:
+        while self.pendingfunctions or self.latercode:
             func = self.pendingfunctions.pop()
             self.gen_cfunction(func)
             # collect more of the latercode after each function

Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py	(original)
+++ pypy/dist/pypy/translator/test/snippet.py	Wed Feb 23 16:28:33 2005
@@ -814,3 +814,15 @@
   return (a,a1,b,b1)
 
 
+# constant instances with __init__ vs. __new__
+
+class Thing1:
+
+    def __init__(self):
+        self.thingness = 1
+
+thing1 = Thing1()
+
+def one_thing1():
+    return thing1
+

Modified: pypy/dist/pypy/translator/test/test_ctrans.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_ctrans.py	(original)
+++ pypy/dist/pypy/translator/test/test_ctrans.py	Wed Feb 23 16:28:33 2005
@@ -193,6 +193,10 @@
         assert l == [3, 'c', 8, 11, 'h', 9]
         assert result == ([3, 'c'], [9], [11, 'h'])
 
+    def test_global_const_w_init(self):
+        fn = self.build_cfunc(snippet.one_thing1)
+        assert fn().thingness == 1
+
 class TestTypedTestCase:
 
     def getcompiled(self, func):
@@ -292,3 +296,4 @@
         assert result == list('abc')
         result = fn(l, 2**64)
         assert result == list('abc')
+        



More information about the Pypy-commit mailing list