[pypy-svn] r47881 - pypy/dist/pypy/lang/smalltalk/test

akuhn at codespeak.net akuhn at codespeak.net
Thu Oct 25 02:11:30 CEST 2007


Author: akuhn
Date: Thu Oct 25 02:11:30 2007
New Revision: 47881

Modified:
   pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
Log:
using setup_module(module) in test/test_miniimage.py

Modified: pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py	Thu Oct 25 02:11:30 2007
@@ -1,95 +1,100 @@
 # ----- mini.image productline -------------------------------
 #       NOT relying on order of methods
-#       one big method to rule them all
+#       using setup_module(module) now
 import py
 from pypy.lang.smalltalk import squeakimage as sq
 from pypy.lang.smalltalk import model as sqm
 from pypy.lang.smalltalk import constants as sqc
 from pypy.lang.smalltalk import interpreter as sqi
 
+# lazy initialization of test data, ie ImageReader and Float class
 
-mini_image = py.magic.autopath().dirpath().dirpath().join('mini.image')
-
-def test_miniimageexists():
-    assert mini_image.check(dir=False)
-
-def get_miniimage():
+def setup_module(module):
+    global mini_image
+    global reader
+    global image
+    mini_image = py.magic.autopath().dirpath().dirpath().join('mini.image')
+    reader = open_miniimage()
+    reader.initialize()
+    image = sq.SqueakImage()
+    image.from_reader(get_reader())
+    
+def open_miniimage():
     return sq.ImageReader(sq.Stream(mini_image.open()))
 
-def create_squeakimage():
-    example = get_miniimage()
-    example.initialize()
+def get_reader():
+    return reader
     
-    image = sq.SqueakImage()
-    image.from_reader(example)
+def get_image():
     return image
+    
+def get_float_class():
+    image = get_image()
+    return image.special(sqc.SO_FLOAT_CLASS)
+     
+# ------ tests ------------------------------------------
+        
+def test_miniimageexists():
+    assert mini_image.check(dir=False)
 
 def test_read_header():
-    example = get_miniimage()
-    example.read_header()
-    assert example.endofmemory == 0x93174
-    assert example.oldbaseaddress == 0x6649000
-    assert example.specialobjectspointer == 0x6668380
+    reader = open_miniimage()
+    reader.read_header()
+    assert reader.endofmemory == 0x93174
+    assert reader.oldbaseaddress == 0x6649000
+    assert reader.specialobjectspointer == 0x6668380
 
 def test_read_all_header(): 
-    example = get_miniimage()
-    example.read_header()
-    next = example.stream.peek()
+    reader = open_miniimage()
+    reader.read_header()
+    next = reader.stream.peek()
     assert next != 0 #expects object header, which must not be 0x00000000 
       
-def test_readimage_productline():
-    example = get_miniimage()
-    example.read_header()
-    objects = example.read_body()
+      
+      
+def test_number_of_objects():
+    image = get_image()
+    objects = image.objects
     assert len(objects) > 0
     assert 15000 < len(objects) < 16000 
     
-    # at end of file
-    # py.test.raises(IndexError, lambda: example.stream.next())
-    
-    # all pointers are valid
-    for each in example.chunks.itervalues():
+def test_all_pointers_are_valid():
+    reader = get_reader()
+    for each in reader.chunks.itervalues():
         if each.format < 5: 
             for pointer in each.data:
                 if (pointer & 1) != 1:
-                    assert pointer in example.chunks   
+                    assert pointer in reader.chunks   
     
-    # there are 31 compact classes
-    example.init_compactclassesarray()
-    assert len(example.compactclasses) == 31
     
-    example.init_g_objects()
-    
-    example.init_w_objects() 
-
-    example.fillin_w_objects() 
-    
-    image = sq.SqueakImage()
-    
-    image.from_reader(example)    
+def test_there_are_31_compact_classes():
+    reader = get_reader()
+    assert len(reader.compactclasses) == 31
     
+def test_invariant():
+    image = get_image()
     for each in image.objects:
         each.invariant()
     
-    w_float_class = image.special(sqc.SO_FLOAT_CLASS)
-    
+def test_float_class_size():
+    w_float_class = get_float_class()
     assert w_float_class.size() == 9
-    
+
+def test_float_class_name():
+    w_float_class = get_float_class()
     w_float_class_name = w_float_class.fetch(6)
-    
     assert isinstance(w_float_class_name, sqm.W_BytesObject)
-    
     assert w_float_class_name.bytes == list("Float")
     
+def test_str_w_object():
+    w_float_class = get_float_class()
     assert str(w_float_class) == "Float class"
-    
     assert str(w_float_class.getclass()) == "a Metaclass" # yes, with article here.
-
     assert str(w_float_class.getclass().getclass()) == "Metaclass class"
 
 
 def test_lookup_abs_in_integer(int=10):
-    image = create_squeakimage()
+    image = get_image()
     amethod = None
 
     w_smallint_class = image.special(sqc.SO_SMALLINTEGER_CLASS)
@@ -112,5 +117,5 @@
             return e.object
 
 def test_lookup_neg_abs_in_integer():
-    py.test.fail("TOFIX methodlookup 'negated' fails in mirror SmallInteger")
+    py.test.skip("TOFIX methodlookup 'negated' fails in mirror SmallInteger")
     test_lookup_abs_in_integer(-3)



More information about the Pypy-commit mailing list