Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1198 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

PATCH DBTest barfs when using Genshi, because inspect.isclass sucks

Reported by: winjer Owned by: anonymous
Priority: normal Milestone: 1.0.2
Component: Tests Version: 1.0b2
Severity: major Keywords:
Cc:

Description

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)

Attachments

1198.patch Download (1.1 KB) - added by kuffs 12 years ago.
Requested patch against trunk

Change History

comment:1 Changed 12 years ago by jorge.vargas

  • Summary changed from DBTest barfs when using Genshi, because inspect.isclass sucks to PATCH DBTest barfs when using Genshi, because inspect.isclass sucks
  • Milestone set to 2.0

comment:2 Changed 12 years ago by alberto

  • Component changed from genshi to TurboGears
  • Milestone changed from 2.0 to 1.0b3

This should better be fixed for 1.0b3 IMO. Could you provide those patches as an attachment so they're easier to apply? Thanks :)

Alberto

comment:3 Changed 12 years ago by alberto

  • Milestone changed from 1.0b3 to 1.1

comment:4 Changed 12 years ago by jorge.vargas

  • Component changed from TurboGears to tests
  • Milestone changed from 1.1 to 1.0.2

ups sorry for setting that for 2.0, guess we'll have to write the patches.

Changed 12 years ago by kuffs

Requested patch against trunk

comment:5 Changed 12 years ago by alberto

  • Status changed from new to closed
  • Resolution set to fixed

Applied at [2835] Thanks :)

Alberto

Note: See TracTickets for help on using tickets.