Ticket #1764: r1764.ken.patch

File r1764.ken.patch, 2.3 kB (added by kskuhlman, 2 years ago)

Modified version to make classes discoverable by automated doc utils

  • setup.py

    old new  
    3333] 
    3434 
    3535sqlobject = [ 
    36     "SQLObject >= 0.7.1", 
     36    "SQLObject >= 0.8.0", 
    3737] 
    3838 
    3939exp = ["TGFastData"] 
  • turbogears/testutil.py

    old new  
    275275    return output, response 
    276276 
    277277 
    278 class DBTest(unittest.TestCase): 
     278class AbstractDBTest(unittest.TestCase): 
     279    """A database enabled unit testing class. 
    279280 
     281    Creates and destroys your database before and after each unit test.  You must set the  
     282    model attribute in order for this class to function correctly. 
     283    """ 
    280284    model = None 
    281285 
     286    def setUp(self): 
     287        raise NotImplementedError() 
     288 
     289    def tearDown(self): 
     290        raise NotImplementedError() 
     291 
     292class DBTestSO(AbstractDBTest): 
    282293    def _get_soClasses(self): 
    283294        try: 
    284295            return [self.model.__dict__[x] for x in self.model.soClasses] 
     
    289300        if not self.model: 
    290301            self.model = get_model() 
    291302            if not self.model: 
    292                 raise "Unable to run database tests without a model" 
    293  
     303                raise Exception("Unable to run database tests without a model") 
    294304        for item in self._get_soClasses(): 
    295305            if isinstance(item, types.TypeType) and issubclass(item, 
    296306                sqlobject.SQLObject) and item != sqlobject.SQLObject \ 
     
    305315                and item != InheritableSQLObject: 
    306316                item.dropTable(ifExists=True, cascade=True) 
    307317 
     318class DBTestSA(AbstractDBTest): 
     319    def setUp(self): 
     320        database.get_engine() 
     321        database.metadata.create_all() 
     322 
     323    def tearDown(self): 
     324        database.metadata.drop_all() 
     325 
     326 
     327#Determine which class to use for "DBTest".  Setup & teardown should behave  
     328#simularly regardless of which ORM you choose. 
     329if config.get("sqlobject.dburi"): 
     330    DBTest = DBTestSO 
     331elif config.get("sqlalchemy.dburi"): 
     332    DBTest = DBTestSA 
     333else: 
     334    raise Exception("Unable to find sqlalchemy or sqlobject dburi") 
     335 
     336 
    308337def unmount(): 
    309338    """Remove an application from the object traversal tree.""" 
    310339    # There's no clean way to remove a subtree under CP2, so the only use case