Commits

Anonymous committed 1825f10

Added an instantiation hook for xxxTypes that need instantiation before inspection to gen_stubs.py. Added in stubs to cdrom_test.py

Comments (0)

Files changed (3)

test/cdrom_test.py

 
         self.assert_(test_not_implemented()) 
 
+class CDTypeTest(unittest.TestCase):
+    def test_eject(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.eject:
+
+          # CD.eject(): return None
+          # eject or open the cdrom drive
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_all(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_all:
+
+          # CD.get_all(): return [(audio, start, end, lenth), ...]
+          # get all track information
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_busy(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_busy:
+
+          # CD.get_busy(): return bool
+          # true if the drive is playing audio
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_current(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_current:
+
+          # CD.get_current(): return track, seconds
+          # the current audio playback position
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_empty(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_empty:
+
+          # CD.get_empty(): return bool
+          # False if a cdrom is in the drive
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_id(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_id:
+
+          # CD.get_init(): return bool
+          # true if this cd device initialized
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_init(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_init:
+
+          # CD.get_init(): return bool
+          # true if this cd device initialized
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_name(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_name:
+
+          # CD.get_name(): return name
+          # the system name of the cdrom drive
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_numtracks(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_numtracks:
+
+          # CD.get_numtracks(): return count
+          # the number of tracks on the cdrom
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_paused(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_paused:
+
+          # CD.get_paused(): return bool
+          # true if the drive is paused
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_track_audio(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_track_audio:
+
+          # CD.get_track_audio(track): return bool
+          # true if the cdrom track has audio data
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_track_length(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_track_length:
+
+          # CD.get_track_length(track): return seconds
+          # length of a cdrom track
+
+        self.assert_(test_not_implemented()) 
+
+    def test_get_track_start(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.get_track_start:
+
+          # CD.get_track_start(track): return seconds
+          # start time of a cdrom track
+
+        self.assert_(test_not_implemented()) 
+
+    def test_init(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.init:
+
+          # CD.init(): return None
+          # initialize a cdrom drive for use
+
+        self.assert_(test_not_implemented()) 
+
+    def test_pause(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.pause:
+
+          # CD.pause(): return None
+          # temporarily stop audio playback
+
+        self.assert_(test_not_implemented()) 
+
+    def test_play(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.play:
+
+          # CD.init(): return None
+          # initialize a cdrom drive for use
+
+        self.assert_(test_not_implemented()) 
+
+    def test_quit(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.quit:
+
+          # CD.quit(): return None
+          # uninitialize a cdrom drive for use
+
+        self.assert_(test_not_implemented()) 
+
+    def test_resume(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.resume:
+
+          # CD.resume(): return None
+          # unpause audio playback
+
+        self.assert_(test_not_implemented()) 
+
+    def test_stop(self):
+
+        # __doc__ (as of 2008-07-02) for pygame.cdrom.CD.stop:
+
+          # CD.stop(): return None
+          # stop audio playback
+
+        self.assert_(test_not_implemented()) 
+
+
 
 ################################################################################
 

test/color_test.py

         
     def test_Color_type_works_for_Surface_get_and_set_colorkey(self):
         s = pygame.Surface((32, 32))
-        for r, g, b, a in pygame.color.THECOLORS.itervalues():
-            c = pygame.Color(r,g,b,a)
+        
+        c = pygame.Color(33, 22, 11, 255)
+        s.set_colorkey(c)
 
-            s.set_colorkey(c)
+        get_r, get_g, get_b, get_a = s.get_colorkey()
 
-            get_r, get_g, get_b, get_a = s.get_colorkey()
-
-            self.assert_(get_r == c.r)
-            self.assert_(get_g == c.g)
-            self.assert_(get_b == c.b)
-            self.assert_(get_a == c.a)
+        self.assert_(get_r == c.r)
+        self.assert_(get_g == c.g)
+        self.assert_(get_b == c.b)
+        self.assert_(get_a == c.a)
 
 ########## HSLA, HSVA, CMY, I1I2I3 ALL ELEMENTS WITHIN SPECIFIED RANGE #########
 

test/util/gen_stubs.py

 
 sys.path.append( abspath(normpath( join(dirname(__file__), '../') )) )
 
-################################################################################
-
-ROOT_PACKAGE = 'pygame'
-
 #################################### IGNORES ###################################
 
 # pygame.sprite.Sprite.__module__ = 'pygame.sprite' 
 }
 
 # Types that need instantiating before inspection
-INSTANTIATE = (
-    pygame.event.Event,
-    pygame.cdrom.CD,
-    pygame.joystick.Joystick,
-    pygame.time.Clock,
-    pygame.mixer.Channel,
-    pygame.movie.Movie,
-    pygame.mask.Mask,
-    pygame.display.Info,
-)
+MUST_INSTANTIATE = {
+    pygame.cdrom.CDType          :  (pygame.cdrom.CD, (1,)),
+
+    # pygame.event.Event       :  None,
+    # pygame.joystick.Joystick :  None,
+    # pygame.time.Clock        :  (),
+    # pygame.mixer.Channel     :  None,
+    # pygame.movie.Movie       :  None,
+    # pygame.mask.Mask         :  None,
+    # pygame.display.Info      :  None,
+}
+
+if MUST_INSTANTIATE:
+    pygame.init()
+
+def get_instance(type_):
+    helper = MUST_INSTANTIATE.get(type_)
+    if callable(helper): return helper()
+    helper, arg = helper
+
+    try:
+        return helper(*arg)
+    except:
+        "FAILED TO CREATE INSTANCE OF %s" % type_
+        return type_
 
 ##################################### TODO #####################################
 
 """
 
-1)
-
-    Test
-
-2)
-
-    Properties
+Test
     
-    Helper functions that return objects, ie time.Clock() etc
+More instances
 
 """
 
     )
 
 def is_public(obj_name):
+    try: obj_name += ''
+    except TypeError: obj_name = obj_name.__name__
     return not obj_name.startswith(('__','_'))
 
 def is_test(f):
     callables = [x for x in publics if callable(x)]
     
     if check_where_defined:
-        callables = [ c for c in callables if ROOT_PACKAGE in c.__module__ 
-                        and (c not in REAL_HOMES or REAL_HOMES[c] is obj) ]
+        callables = (c for c in callables if ( 'pygame' in c.__module__ or 
+                    ('__builtin__' == c.__module__ and isclass(c)) )
+                    and REAL_HOMES.get(c) in (None, obj))
 
     if if_of:
         callables = [x for x in callables if if_of(x)] # isclass, ismethod etc
         return '.' + TC[:TC.index('Type')]
 
 def names_of(*args):
-    return tuple(map(lambda o: o.__name__, args))
+    return tuple(map(lambda o: getattr(o, "__name__", str(o)), args))
 
 def callable_name(module, c, class_=None):
     if class_:
 def module_stubs(module):
     stubs = {}
     all_callables = get_callables(module, check_where_defined = True)
+
     classes = set(c for c in all_callables if isclass(c))
+    
+    for class_ in classes:
+        base_type = class_          # eg cdrom.CD has no __name__
+        
+        if class_ in MUST_INSTANTIATE: 
+            class_ = get_instance(class_)
+            
+        get_set = (m[1] for m in getmembers(class_, isgetsetdescriptor))
+        get_set = set(c for c in get_set if is_public(c))
 
-    for class_ in classes:
-        callables = (m[1] for m in getmembers(class_, isgetsetdescriptor))
-        callables = set(c for c in callables if is_public(c.__name__))
         stubs.update (
-            make_stubs(callables ^ get_callables(class_), module, class_) 
+            make_stubs(get_set ^ get_callables(class_), module, base_type) 
         )
 
     stubs.update(make_stubs(all_callables - classes, module))
     if not sys.argv[1:]: 
         sys.exit(opt_parser.print_help())
 
-    root = args and args[0] or ROOT_PACKAGE
-    if not root.startswith(ROOT_PACKAGE):
-        root = '%s.%s' % (ROOT_PACKAGE, root)
+    root = args and args[0] or 'pygame'
+    if not root.startswith('pygame'):
+        root = '%s.%s' % ('pygame', root)
 
     stubs, tested = get_stubs(root)