#1198: DBTest barfs when using Genshi, because inspect.isclass sucks
--------------------+-------------------------------------------------------
 Reporter:  winjer  |       Owner:  anonymous
     Type:  defect  |      Status:  new      
 Priority:  normal  |   Milestone:           
Component:  genshi  |     Version:  1.0b2    
 Severity:  major   |    Keywords:           
--------------------+-------------------------------------------------------
 The DBTest database table dropping/creation routines barf when you use
 Genshi, because inspect.isclass doesn't work as one might hope.  In fact,
 inspect.isclass sucks:

 {{{
 Python 2.4.4c1 (#2, Oct 11 2006, 20:00:03)
 [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import inspect
 >>> class A: pass
 ...
 >>> a = A()
 >>> inspect.isclass(a)
 False
 >>> a.__bases__ = None
 >>> inspect.isclass(a)
 True
 }}}

 This means that:

 {{{
 Python 2.4.4c1 (#2, Oct 11 2006, 20:00:03)
 [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> from genshi.builder import ElementFactory
 >>> f = ElementFactory()
 >>> import inspect
 >>> inspect.isclass(f)
 True
 >>> import sqlobject
 >>> issubclass(f, sqlobject.SQLObject)
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 TypeError: issubclass() arg 1 must be a class
 }}}

 Here is a patch against 1.0b2 that does what I think you intend:

 {{{
 Index: turbogears/testutil.py
 ===================================================================
 --- turbogears/testutil.py      (revision 2202)
 +++ turbogears/testutil.py      (working copy)
 @@ -1,3 +1,4 @@
 +import types
  import inspect
  import logging
  import unittest
 @@ -88,7 +89,7 @@
                  raise "Unable to run database tests without a model"

          for item in self.model.__dict__.values():
 -            if inspect.isclass(item) and issubclass(item,
 +            if isinstance(item, types.TypeType) and issubclass(item,
                  sqlobject.SQLObject) and item != sqlobject.SQLObject \
                  and item != InheritableSQLObject:
                  item.createTable(ifNotExists=True)
 @@ -96,7 +97,7 @@
      def tearDown(self):
          database.rollback_all()
          for item in self.model.__dict__.values():
 -            if inspect.isclass(item) and issubclass(item,
 +            if isinstance(item, types.TypeType) and issubclass(item,
                  sqlobject.SQLObject) and item != sqlobject.SQLObject \
                  and item != InheritableSQLObject:
                  item.dropTable(ifExists=True)
 }}}

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1198>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to