Commits

Anonymous committed 785b822

Renamed some rect_test.py tests to match stub generator scheme

  • Participants
  • Parent commits 0c9c0de

Comments (0)

Files changed (2)

test/rect_test.py

         self.assertEqual( (abs(r.width),abs(r.height)), r2.size )
         self.assertEqual( (-2,-4), r2.topleft )
 
-    def testSetLeft( self ):
+    def test_left( self ):
         """Changing the left attribute moves the rect and does not change
            the rect's width
         """
         self.assertEqual( new_left, r.left )
         self.assertEqual( Rect(new_left,2,3,4), r )
     
-    def testSetRight( self ):
+    def test_right( self ):
         """Changing the right attribute moves the rect and does not change
            the rect's width
         """
         self.assertEqual( expected_left, r.left )
         self.assertEqual( old_width, r.width )
        
-    def testSetTop( self ):
+    def test_top( self ):
         """Changing the top attribute moves the rect and does not change
            the rect's width
         """
         self.assertEqual( Rect(1,new_top,3,4), r )
         self.assertEqual( new_top, r.top )
     
-    def testSetBottom( self ):
+    def test_bottom( self ):
         """Changing the bottom attribute moves the rect and does not change
            the rect's height
         """
         self.assertEqual( expected_top, r.top )
         self.assertEqual( old_height, r.height )
     
-    def testSetCenterX( self ):
+    def test_centerx( self ):
         """Changing the centerx attribute moves the rect and does not change
            the rect's width
         """
         self.assertEqual( expected_left, r.left )
         self.assertEqual( old_width, r.width )
     
-    def testSetCenterY( self ):
+    def test_centery( self ):
         """Changing the centerx attribute moves the rect and does not change
            the rect's width
         """
         self.assertEqual( expected_top, r.top )
         self.assertEqual( old_height, r.height )
     
-    def testSetTopLeft( self ):
+    def test_topleft( self ):
         """Changing the topleft attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( new_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
         
-    def testSetBottomLeft( self ):
+    def test_bottomleft( self ):
         """Changing the bottomleft attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetTopRight( self ):
+    def test_topright( self ):
         """Changing the bottomleft attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetBottomRight( self ):
+    def test_bottomright( self ):
         """Changing the bottomright attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetCenter( self ):
+    def test_center( self ):
         """Changing the center attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetMidLeft( self ):
+    def test_midleft( self ):
         """Changing the midleft attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetMidRight( self ):
+    def test_midright( self ):
         """Changing the midright attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetMidTop( self ):
+    def test_midtop( self ):
         """Changing the midtop attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetMidBottom( self ):
+    def test_midbottom( self ):
         """Changing the midbottom attribute moves the rect and does not change
            the rect's size
         """
         self.assertEqual( expected_topleft, r.topleft )
         self.assertEqual( old_size, r.size )
     
-    def testSetWidth( self ):
+    def test_width( self ):
         "Changing the width resizes the rect from the top-left corner"
         r = Rect( 1, 2, 3, 4 )
         new_width = 10
         self.assertEqual( old_height, r.height )
         self.assertEqual( old_topleft, r.topleft )
     
-    def testSetHeight( self ):
+    def test_height( self ):
         "Changing the height resizes the rect from the top-left corner"
         r = Rect( 1, 2, 3, 4 )
         new_height = 10
         self.assertEqual( old_width, r.width )
         self.assertEqual( old_topleft, r.topleft )
     
-    def testSetSize( self ):
+    def test_size( self ):
         "Changing the size resizes the rect from the top-left corner"
         r = Rect( 1, 2, 3, 4 )
         new_size = (10,20)

test/util/gen_stubs.py

 
 #################################### IGNORES ###################################
 
+# Anything not wanted to be stubbed, such as aliases, or redundancies
+
+IGNORES = set([
+
+    pygame.rect.Rect.h,           pygame.rect.Rect.w,
+    pygame.rect.Rect.x,           pygame.rect.Rect.y,
+
+    pygame.color.Color.a,         pygame.color.Color.b,
+    pygame.color.Color.g,         pygame.color.Color.r,
+    
+    # Ignore by class: all methods and getter setters cut from root
+    
+    # pygame.sprite.AbstractGroup,
+
+    pygame.sprite.LayeredUpdates,
+    pygame.sprite.LayeredDirty,
+    pygame.sprite.OrderedUpdates,
+    pygame.sprite.GroupSingle,
+    pygame.sprite.RenderUpdates,
+    pygame.sprite.Group,
+])
+
 # pygame.sprite.Sprite.__module__ = 'pygame.sprite' 
 # pygame.sprite.Rect.__module__   = 'pygame'
 
-# In [7]: pygame.overlay.Overlay.__name__
-# Out[7]: 'overlay'
-
 # Mapping of callable to module where it's defined
+# Place any object that appears in modules other than it's home in here
 
 REAL_HOMES = {
     pygame.rect.Rect         : pygame.rect,
     pygame.font.get_fonts    : pygame.font,
     pygame.font.match_font   : pygame.font,
 }
-  
+
 MUST_INSTANTIATE = {
-    # BaseType                        # Instance
+    
+    # BaseType / Helper               # (Instantiator / Args) / Callable
 
-    pygame.cdrom.CDType            :  (pygame.cdrom.CD, (1,)),
-    pygame.mixer.ChannelType       :  (pygame.mixer.Channel, (1,)),
+    pygame.cdrom.CDType            :  (pygame.cdrom.CD, (0,)),
+    pygame.mixer.ChannelType       :  (pygame.mixer.Channel, (0,)),
     pygame.time.Clock              :  (pygame.time.Clock, ()),
 
     # pygame.event.Event         :  None,
 
     try:
         return helper(*arg)
-    except:
-        # TODO: raise or not to raise??
-        raw_input("FAILED TO CREATE INSTANCE OF %s" % type_)
+    except Exception, e:
+        raw_input("FAILED TO CREATE INSTANCE OF %s\n%s\n" 
+                  "Press Enter to continue" % (type_, e))
         return type_
 
 ##################################### TODO #####################################
 
 ############################## REGULAR EXPRESSIONS #############################
 
-module_re = re.compile(r"pygame\.([^.]*)\.?")
+module_re = re.compile(r"pygame\.([^.]+)\.?")
 
 #################################### OPTIONS ###################################
 
 opt_parser = OptionParser()
 
 opt_parser.add_option (
-     "-l",  "--list", dest = "list", action = 'store_true',
-     help   = "list only callable names not stubs" )
+     "-l",  "--list", action = 'store_true',
+     help   = "list callable names not stubs" )
+
+opt_parser.add_option (
+     "-t",  "--test_names", action = 'store_true',
+     help   = "list test names not stubs" )
 
 opt_parser.set_usage(
 """
         unitname = unit_name,
     )
 
-    return unit_name, stub
+    return unit_name, (test_name, stub)
 
 def make_stubs(seq, module, class_=None):
     return dict( test_stub(c, module, class_) for c in seq )
 
 def module_stubs(module):
     stubs = {}
-    all_callables = get_callables(module, check_where_defined = True)
+    all_callables = get_callables(module, check_where_defined = True) - IGNORES
     classes = set (
         c for c in all_callables if isclass(c) or c in MUST_INSTANTIATE
     )
             class_ = get_instance(class_)
 
         stubs.update (
-            make_stubs(get_callables(class_), module, base_type)
+            make_stubs(get_callables(class_) - IGNORES, module, base_type)
         )
 
     stubs.update(make_stubs(all_callables - classes, module))
         for test in get_callables(class_, is_test):
             fname = test.__name__[5:].split('__')[0]
             already.append("%s%s.%s" % (mod_name, class_tested, fname))
-    
+
     return already
 
 def already_tested_in_package(package):
 
 ################################################################################
 
-def get_stubs(root):    
+def get_stubs(root):
     module_root = module_re.search(root)
     if module_root:
         module = getattr(pygame, module_root.group(1))
 
     for fname in sorted(s for s in stubs.iterkeys() if s not in tested):
         if not fname.startswith(root): continue  # eg. module.Class
-        print options.list and fname or stubs[fname]
+        test_name, stub = stubs[fname]
+
+        if options.list: print "%s," % fname
+        elif options.test_names: print test_name
+        else: print stub
 
 ################################################################################