Commits

akalias  committed c2cfb3b

Some more init tests

  • Participants
  • Parent commits 9ac1d3f

Comments (0)

Files changed (3)

File test/base_test.py

     global quit_called
     quit_called = quit_called + 1
 
+
+quit_hook_ran = 0
+def quit_hook():
+    global quit_hook_ran
+    quit_hook_ran = 1
+
 class BaseModuleTest(unittest.TestCase):
     def testAutoInit(self):
         pygame.init()
           # pygame.get_error(): return errorstr
           # get the current error message
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(test_not_implemented())
 
     def test_get_sdl_byteorder(self):
 
           # pygame.get_sdl_byteorder(): return int
           # get the byte order of SDL
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(pygame.get_sdl_byteorder() + 1) 
 
     def test_get_sdl_version(self):
 
           # pygame.get_sdl_version(): return major, minor, patch
           # get the version number of SDL
 
-        self.assert_(test_not_implemented()) 
+        self.assert_( len(pygame.get_sdl_version()) == 3) 
 
     def test_init(self):
+        return
 
         # __doc__ (as of 2008-06-25) for pygame.base.init:
 
 
         self.assert_(test_not_implemented()) 
 
-    def test_quit(self):
+    def not_init_assertions(self):
+        self.assert_(not pygame.display.get_init())
+        self.assert_(not pygame.mixer.get_init())
+        self.assert_(not pygame.font.get_init())
+        
+        self.assertRaises(pygame.error, pygame.scrap.get)
+        
+        # pygame.cdrom
+        # pygame.joystick
 
+    def init_assertions(self):
+        self.assert_(pygame.display.get_init())
+        self.assert_(pygame.mixer.get_init())
+        self.assert_(pygame.font.get_init())
+
+    def test_quit__and_init(self):
         # __doc__ (as of 2008-06-25) for pygame.base.quit:
 
           # pygame.quit(): return None
           # uninitialize all pygame modules
+        
+        # Make sure everything is not init
+        self.not_init_assertions()
+    
+        # Initiate it 
+        pygame.init()
+        
+        # Check
+        self.init_assertions()
 
-        self.assert_(test_not_implemented()) 
+        # Quit
+        pygame.quit()
+        
+        # All modules have quit
+        self.not_init_assertions()
 
     def test_register_quit(self):
 
 
           # register_quit(callable): return None
           # register a function to be called when pygame quits
+        
+        self.assert_(not quit_hook_ran)
 
-        self.assert_(test_not_implemented()) 
+        pygame.init()
+        pygame.register_quit(quit_hook)
+        pygame.quit()
+
+        self.assert_(quit_hook_ran)
 
     def test_segfault(self):
 

File test/time_test.py

 import test_utils, unittest
 from test_utils import test_not_implemented
 
+import pygame, time
+
+Clock = pygame.time.Clock
+
 ################################################################################
 
-class ClockTypeTest(unittest.TestCase):    
+class ClockTypeTest(unittest.TestCase):
+    def test_construction(self):
+        c = Clock()
+        self.assert_(c, "Clock can be constructed")
+    
     def test_get_fps(self):
-
+        self.assert_(test_not_implemented())
+        return
+        
         # __doc__ (as of 2008-07-03) for pygame.time.Clock.get_fps:
 
           # Clock.get_fps(): return float
           # compute the clock framerate
 
-        self.assert_(test_not_implemented()) 
+        delay_per_frame = 1 / 100.0
 
-    def test_get_rawtime(self):
+        c = Clock()
 
-        # __doc__ (as of 2008-07-03) for pygame.time.Clock.get_rawtime:
+        for f in range(100):
+            c.tick()
+            time.sleep(delay_per_frame)
 
-          # Clock.get_rawtime(): return milliseconds
-          # actual time used in the previous tick
-
-        self.assert_(test_not_implemented()) 
-
-    def test_get_time(self):
-
-        # __doc__ (as of 2008-07-03) for pygame.time.Clock.get_time:
-
-          # Clock.get_time(): return milliseconds
-          # time used in the previous tick
-
-        self.assert_(test_not_implemented()) 
+        self.assert_(99.0 < c.get_fps() < 101.0)
 
     def test_tick(self):
+        self.assert_(test_not_implemented())
+        return
 
         # __doc__ (as of 2008-07-03) for pygame.time.Clock.tick:
 
           # Clock.tick(framerate=0): return milliseconds
           # control timer events
           # update the clock
+        
+        collection = []
+        c = Clock()
 
-        self.assert_(test_not_implemented()) 
+        c.tick()
+        for i in range(100):
+            time.sleep(0.005)
+            collection.append(c.tick())
 
+        for outlier in [min(collection), max(collection)]:
+            if outlier != 5: collection.remove(outlier)
+
+        self.assert_(sum(collection) / len(collection) == 5)
+
+
+    def test_get_rawtime(self):
+        # __doc__ (as of 2008-07-03) for pygame.time.Clock.get_rawtime:
+
+          # Clock.get_rawtime(): return milliseconds
+          # actual time used in the previous tick
+
+        self.assert_(test_not_implemented())
+
+    def test_get_time(self):
+        
+        # __doc__ (as of 2008-07-03) for pygame.time.Clock.get_time:
+
+          # Clock.get_time(): return milliseconds
+          # time used in the previous tick
+
+        self.assert_(test_not_implemented())
+        return
+        
+        c = Clock()
+        c.tick()                    #between   here 
+        time.sleep(0.02)         
+                                                     #get_time()
+        c.tick()                    #          here
+
+        time.sleep(0.02)
+        
+        self.assert_(20 <= c.get_time() <= 30)
+        
     def test_tick_busy_loop(self):
 
         # __doc__ (as of 2008-07-03) for pygame.time.Clock.tick_busy_loop:
           # pygame.time.set_timer(eventid, milliseconds): return None
           # repeatedly create an event on the event queue
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(test_not_implemented())
 
     def test_wait(self):
 

File test/transform_test.py

 
         ################################################################  
 
+    def test_threshold__honors_individual_color_thresholds(self):
+        ################################################################  
+        pass
+            
+                
+        ################################################################  
 
     def test_threshold__surface(self):
         """