Lenard Lindstrom avatar Lenard Lindstrom committed db1f4e2

move surfarray surface lock test to surfarray_test.py

Comments (0)

Files changed (2)

test/surfarray_test.py

 pygame.init()
 
 
-skip_tests = False
+arraytype = ""
 try:
     import pygame.surfarray
 except ImportError:
-    skip_tests = True
+    pass
 else:
-    if pygame.surfarray.get_arraytype() == 'numpy':
+    arraytype = pygame.surfarray.get_arraytype()
+    if arraytype == 'numpy':
         from numpy import \
              uint8, uint16, uint32, uint64, zeros, float64
-    elif pygame.surfarray.get_arraytype() == 'numeric':
+    elif arraytype == 'numeric':
         from Numeric import \
              UInt8 as uint8, UInt16 as uint16, UInt32 as uint32, zeros, \
              Float64 as float64
     else:
         print ("Unknown array type %s; tests skipped" %
                pygame.surfarray.get_arraytype())
-        skip_tests = True
+        arraytype = ""
 
 def unsigned(i):
     return 0xffffffff & i
     def _make_array2d(self, dtype):
         return zeros(self.surf_size, dtype)
 
+    def setUp(self):
+        if arraytype:
+            pygame.surfarray.use_arraytype(arraytype)
+
     def test_array2d(self):
-        if skip_tests:
+        if not arraytype:
             return
 
         sources = [self._make_src_surface(8),
         self.fail() 
 
     def test_blit_array(self):
-        if skip_tests:
+        if not arraytype:
             return
 
         # bug 24 at http://pygame.motherhamster.org/bugzilla/
 
         self.fail() 
 
+    def test_surf_lock (self):
+        if not arraytype:
+            return
+
+        sf = pygame.Surface ((5, 5), 0, 32)
+        for atype in pygame.surfarray.get_arraytypes ():
+            pygame.surfarray.use_arraytype (atype)
+            
+            ar = pygame.surfarray.pixels2d (sf)
+            self.assertEquals (sf.get_locked (), True)
+
+            # Numpy uses the Surface's buffer.
+            if atype == "numeric":
+                self.assertEquals (sf.get_locks (), (ar,))
+                
+            sf.unlock ()
+            self.assertEquals (sf.get_locked (), True)
+                
+            del ar
+            self.assertEquals (sf.get_locked (), False)
+            self.assertEquals (sf.get_locks (), ())
+
+        #print "test_surf_lock - end"
+
+
 if __name__ == '__main__':
-    if skip_tests:
+    if not arraytype:
         print "No array package is installed. Cannot run unit tests."
     else:
         unittest.main()

test/surflock_test.py

-__tags__ = ['array']
-
 if __name__ == '__main__':
     import sys
     import os
         self.assertEquals (sf.get_locked (), False)
         self.assertEquals (sf.get_locks (), ())
 
-    def test_surfarray_ref (self):
-        sf = pygame.Surface ((5, 5), 32)
-        for atype in pygame.surfarray.get_arraytypes ():
-            pygame.surfarray.use_arraytype (atype)
-            
-            ar = pygame.surfarray.pixels2d (sf)
-            self.assertEquals (sf.get_locked (), True)
-
-            # Numpy uses the Surface's buffer.
-            if atype == "numeric":
-                self.assertEquals (sf.get_locks (), (ar,))
-
-            sf.unlock ()
-            self.assertEquals (sf.get_locked (), True)
-
-            del ar
-            self.assertEquals (sf.get_locked (), False)
-            self.assertEquals (sf.get_locks (), ())
-
-        #print "test_surfarray_ref - end"
 
 if __name__ == '__main__':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.