Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 96

Show
Ignore:
Timestamp:
11/17/05 08:11:28
Author:
fumanchu
Message:

Lots of changes to the test suite. Partially fixes #23.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/__init__.py

    r95 r96  
    1 """Dejavu is an Object-Relational Mapper. This is version 1.3 beta 2. 
     1"""Dejavu is an Object-Relational Mapper. 
    22 
    33Persisted objects are called "Units", and are served into Sandboxes within 
     
    4949REDISTRIBUTION OF THIS SOFTWARE. 
    5050""" 
     51 
     52__version__ =  "1.3 beta 2" 
     53 
    5154 
    5255import ConfigParser 
  • trunk/storage/__init__.py

    r95 r96  
    99except ImportError: 
    1010    import pickle 
     11 
     12from dejavu import logic 
    1113 
    1214 
     
    232234            expr = logic.Expression(lambda x: True) 
    233235         
    234         lock = self._get_lock(unitClass) 
    235         try: 
    236             cache = self._caches[unitClass] 
     236        lock = self._get_lock(cls) 
     237        try: 
     238            cache = self._caches[cls] 
    237239            seen = [] 
    238240             
     
    253255                index_of_id = fields.index("ID") 
    254256                 
    255                 for row in self.nextstore.view(unitClass, fields, expr): 
     257                for row in self.nextstore.view(cls, fields, expr): 
    256258                    if row[index_of_id] not in cache: 
    257259                        if "ID" not in attrs: 
  • trunk/test/test_analysis.py

    r95 r96  
     1import datetime 
    12import unittest 
    2 import datetime 
    3 import analysis 
     3 
     4from dejavu import analysis 
    45 
    56 
     
    6566 
    6667 
    67 def run_tests(): 
    68     try: 
    69         unittest.main(__name__) 
    70     except SystemExit: 
    71         # unittest.main normally raises SystemExit when complete. 
    72         pass 
     68if __name__ == "__main__": 
     69    unittest.main(__name__) 
    7370 
    74 if __name__ == "__main__": 
    75     run_tests() 
    76  
  • trunk/test/test_codewalk.py

    r95 r96  
    1 import sys 
    2 import unittest 
    3  
    4 from dejavu import codewalk 
    5 nums = codewalk.numeric_opcodes 
    6  
    71import datetime 
    82try: 
     
    104except ImportError: 
    115    fixedpoint = None 
     6import sys 
     7import unittest 
     8 
     9from dejavu import codewalk 
     10nums = codewalk.numeric_opcodes 
    1211 
    1312amount = 5 
     
    208207 
    209208 
    210 def run_tests(): 
    211     try: 
    212         unittest.main(__name__) 
    213     except SystemExit: 
    214         # unittest.main normally raises SystemExit when complete. 
    215         pass 
    216  
    217209if __name__ == "__main__": 
    218     run_tests(
    219  
     210    unittest.main(__name__
     211 
  • trunk/test/test_containers.py

    r95 r96  
     1import operator 
    12import unittest 
    2 import operator 
    33from dejavu import containers 
    44 
     
    160160 
    161161 
    162 def run_tests(): 
    163     try: 
    164         unittest.main(__name__) 
    165     except SystemExit: 
    166         # unittest.main normally raises SystemExit when complete. 
    167         pass 
     162if __name__ == "__main__": 
     163    unittest.main(__name__) 
    168164 
    169 if __name__ == "__main__": 
    170     run_tests() 
    171  
  • trunk/test/test_dejavu.py

    r95 r96  
     1import datetime 
    12import unittest 
    2 import datetime 
    33 
    44import dejavu 
    55from dejavu import zoo, storage 
    6 zoo.arena.add_store("default", "storage.CachingProxy") 
     6zoo.arena.add_store("default", "dejavu.storage.CachingProxy") 
    77 
    88 
     
    115115 
    116116 
    117 def run_tests(): 
    118     try: 
    119         unittest.main(__name__) 
    120     except SystemExit: 
    121         # unittest.main normally raises SystemExit when complete. 
    122         pass 
     117if __name__ == "__main__": 
     118    unittest.main(__name__) 
    123119 
    124 if __name__ == "__main__": 
    125     run_tests() 
    126  
  • trunk/test/test_logic.py

    r95 r96  
    11import datetime 
     2import pickle 
    23import sys 
    34import unittest 
     
    89nums = logic.codewalk.numeric_opcodes 
    910 
    10 import pickle 
    1111 
    1212class ExpressionTests(unittest.TestCase): 
     
    209209 
    210210 
    211 def run_tests(): 
    212     try: 
    213         unittest.main(__name__) 
    214     except SystemExit: 
    215         # unittest.main normally raises SystemExit when complete. 
    216         pass 
    217  
    218211if __name__ == "__main__": 
    219     run_tests(
    220  
     212    unittest.main(__name__
     213 
  • trunk/test/test_storemsaccess.py

    r95 r96  
    22the Access SM will crash python.""" 
    33 
    4 import zoo_fixture 
    54 
    6 def run_tests(): 
    7     # Microsoft Access 
    8     opts = {u'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zoo.mdb;", 
    9             u'Expanded Columns': "Animal.PreviousZoos:int", 
    10             } 
    11     zoo_fixture.run_tests("dejavu.storage.storeado.StorageManagerADO_MSAccess", opts) 
     5SM_class = "dejavu.storage.storeado.StorageManagerADO_MSAccess" 
     6opts = {u'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zoo.mdb;", 
     7        u'Expanded Columns': "Animal.PreviousZoos:int", 
     8        } 
     9 
    1210 
    1311if __name__ == "__main__": 
    14     run_tests() 
     12    import test 
     13    test.run_zoo(SM_class, opts) 
    1514 
  • trunk/test/test_storemysql.py

    r95 r96  
    1 import zoo_fixture 
    21 
    3 def run_tests(): 
    4     pword = raw_input("Password for the root user:") 
    5     opts = {"host": "localhost", 
    6             "db": "dejavu_test", 
    7             "user": "root", 
    8             "passwd": pword, 
    9             } 
    10     zoo_fixture.run_tests("dejavu.storage.storemysql.StorageManagerMySQL", opts) 
     2 
     3opts = {"host": "localhost", 
     4        "db": "dejavu_test", 
     5        "user": "root", 
     6        "passwd": "", 
     7        } 
     8if opts['passwd'] == "": 
     9    opts['passwd'] = raw_input("Enter the password for the MySQL '%s' user:" 
     10                               % opts['user']) 
     11SM_class = "dejavu.storage.storemysql.StorageManagerMySQL" 
    1112 
    1213 
    1314if __name__ == "__main__": 
    14     run_tests() 
     15    import test 
     16    test.run_zoo(SM_class, opts) 
    1517 
  • trunk/test/test_storeodbc.py

    r95 r96  
    1 import zoo_fixture 
    21 
    32def create_access_db(): 
     
    76    cat.Create("PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zooodbc.mdb;") 
    87 
     8create_access_db() 
    99 
    10 def run_tests(): 
    11     create_access_db() 
    12      
    13     # Once again, we find that the first param must be repeated 
    14     # in the connection string. Not sure why. 
    15     opts = {u'Connect': ("Provider=MSDASQL;" 
    16                          "Driver={Microsoft Access Driver (*.mdb)};" 
    17                          "DBQ=zooodbc.mdb;Provider=MSDASQL;"), 
    18             u'Expanded Columns': "Animal.PreviousZoos:int", 
    19             } 
    20      
     10# Once again, we find that the first param must be repeated 
     11# in the connection string. Not sure why. 
     12opts = {u'Connect': ("Provider=MSDASQL;" 
     13                     "Driver={Microsoft Access Driver (*.mdb)};" 
     14                     "DBQ=zooodbc.mdb;Provider=MSDASQL;"), 
     15        u'Expanded Columns': "Animal.PreviousZoos:int", 
     16        } 
     17SM_class = "dejavu.storage.storeodbc.StorageManagerODBC" 
     18 
     19 
     20if __name__ == "__main__": 
     21    import test 
    2122    try: 
    22         zoo_fixture.run_tests("dejavu.storage.storeodbc.StorageManagerODBC", opts) 
     23        test.run_zoo(SM_class, opts) 
    2324    finally: 
    2425        try: 
     
    2728            print "Could not remove database." 
    2829 
    29  
    30 if __name__ == "__main__": 
    31     run_tests() 
    32  
  • trunk/test/test_storepypgsql.py

    r95 r96  
    1 import zoo_fixture 
    21 
    3 def run_tests(): 
    4     pword = raw_input("Password for the postgres user:") 
    5     opts = {u'Connect': ("host=localhost dbname=dejavu_test " 
    6                          "user=postgres password=%s" % pword), 
    7             } 
    8     zoo_fixture.run_tests("dejavu.storage.storepypgsql.StorageManagerPgSQL", opts) 
     2user = "postgres" 
     3passwd = "" 
     4 
     5if passwd == "": 
     6    passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 
     7 
     8opts = {u'Connect': ("host=localhost dbname=dejavu_test " 
     9                     "user=%s password=%s" % (user, passwd)), 
     10        } 
     11SM_class = "dejavu.storage.storepypgsql.StorageManagerPgSQL" 
     12 
     13del user, passwd 
    914 
    1015 
    1116if __name__ == "__main__": 
    12     run_tests() 
     17    import test 
     18    test.run_zoo(SM_class, opts) 
    1319 
  • trunk/test/test_storeshelve.py

    r95 r96  
    77 
    88import os 
    9 import zoo_fixture 
    109 
    11 def run_tests(): 
    12     opts = {u'Path': os.getcwd()} 
    13      
    14     zoo_fixture.run_tests("dejavu.storage.storeshelve.StorageManagerShelve", opts) 
    15  
     10opts = {u'Path': os.getcwd()} 
     11SM_class = "dejavu.storage.storeshelve.StorageManagerShelve" 
    1612 
    1713 
    1814if __name__ == "__main__": 
    19     run_tests() 
    20  
     15    import test 
     16    test.run_zoo(SM_class, opts) 
  • trunk/test/test_storesqlite.py

    r95 r96  
    1 import zoo_fixture 
    21 
    3 def run_tests(): 
    4     opts = {"Database": "sqlite_zoo_test"} 
    5     zoo_fixture.run_tests("dejavu.storage.storesqlite.StorageManagerSQLite", opts) 
     2SM_class = "dejavu.storage.storesqlite.StorageManagerSQLite" 
     3opts = {"Database": "sqlite_zoo_test"} 
    64 
    75 
    86if __name__ == "__main__": 
    9     run_tests() 
     7    import test 
     8    test.run_zoo(SM_class, opts) 
    109 
  • trunk/test/test_storesqlserver.py

    r95 r96  
    1 import zoo_fixture 
    21 
    3 def run_tests(): 
    4     opts = {u'Connect': ("Provider=SQLOLEDB.1; Integrated Security=SSPI; " 
    5                          "Initial Catalog=dejavu_test; " 
    6                          "Data Source=REDROVER\\"), 
    7             u'Expanded Columns': "Animal.PreviousZoos:int", 
    8             } 
    9     zoo_fixture.run_tests("dejavu.storage.storeado.StorageManagerADO_SQLServer", opts) 
     2opts = {u'Connect': ("Provider=SQLOLEDB.1; Integrated Security=SSPI; " 
     3                     "Initial Catalog=dejavu_test; " 
     4                     "Data Source=REDROVER\\"), 
     5        u'Expanded Columns': "Animal.PreviousZoos:int", 
     6        } 
     7SM_class = "dejavu.storage.storeado.StorageManagerADO_SQLServer" 
    108 
    119 
    1210if __name__ == "__main__": 
    13     run_tests() 
     11    import test 
     12    test.run_zoo(SM_class, opts) 
    1413 
  • trunk/test/zoo_fixture.py

    r95 r96  
    1 """Unit tests for Storage Managers. 
    2  
    3 Don't run this directly; call run_tests() from a script for a specific 
    4 Storage Manager, setting up and tearing down that SM as needed. 
    5 See test_store*.py in this directory. 
    6 """ 
    7  
     1"""Test fixture for Storage Managers.""" 
     2 
     3import datetime 
     4import threading 
    85import unittest 
    9 import threading 
    10 import datetime 
    11 import dejavu 
    12 from dejavu import logic, zoo 
     6 
     7try: 
     8    import decimal 
     9except ImportError: 
     10    decimal = None 
    1311 
    1412try: 
     
    1715    fixedpoint = None 
    1816 
     17import dejavu 
     18from dejavu import logic 
     19from dejavu import Unit, UnitProperty, associate 
     20from dejavu.test import tools 
     21 
     22 
     23class Zoo(Unit): 
     24    Name = UnitProperty() 
     25    Founded = UnitProperty(datetime.date) 
     26    Opens = UnitProperty(datetime.time) 
     27    LastEscape = UnitProperty(datetime.datetime) 
     28     
     29    if fixedpoint: 
     30        Admission = UnitProperty(fixedpoint.FixedPoint) 
     31    else: 
     32        Admission = UnitProperty(float) 
     33 
     34 
     35class EscapeProperty(UnitProperty): 
     36    def __set__(self, unit, value): 
     37        UnitProperty.__set__(self, unit, value) 
     38        z = unit.first(Zoo) 
     39        if z: 
     40            z.LastEscape = unit.LastEscape 
     41 
     42 
     43class Animal(Unit): 
     44    Name = UnitProperty() 
     45    ZooID = UnitProperty(int, index=True) 
     46    Legs = UnitProperty(int) 
     47    PreviousZoos = UnitProperty(list) 
     48    LastEscape = EscapeProperty(datetime.datetime) 
     49    Lifespan = UnitProperty(float, hints={'bytes': 4}) 
     50    Mother = UnitProperty(int) 
     51     
     52    def in_first_zoo(self): 
     53        return (self.PreviousZoo and self.PreviousZoo[0] == self.ZooID) 
     54associate(Zoo, 'ID', Animal, 'ZooID') 
     55associate(Animal, 'ID', Animal, 'Mother') 
     56 
     57 
     58class Exhibit(Unit): 
     59    # Make this a string to help test vs unicode. 
     60    Name = UnitProperty(str) 
     61    ZooID = UnitProperty(int) 
     62    Animals = UnitProperty(list) 
     63    PettingAllowed = UnitProperty(bool) 
     64    if decimal: 
     65        Acreage = UnitProperty(decimal.Decimal) 
     66    else: 
     67        Acreage = UnitProperty(float) 
     68associate(Zoo, 'ID', Exhibit, 'ZooID') 
     69 
    1970 
    2071class ZooTests(unittest.TestCase): 
    2172     
    2273    def test_0_populate(self): 
    23         box = zoo.arena.new_sandbox() 
     74        box = arena.new_sandbox() 
    2475         
    2576        # Notice this also tests that: a Unit which is only 
    2677        # dirtied via __init__ is still saved. 
    27         WAP = zoo.Zoo(Name = 'Wild Animal Park', 
     78        WAP = Zoo(Name = 'Wild Animal Park', 
    2879                      Founded = datetime.date(2000, 1, 1), 
    2980                      # 59 can give rounding errors with divmod, which 
     
    3586        box.memorize(WAP) 
    3687         
    37         SDZ = zoo.Zoo(Name = 'San Diego Zoo', 
     88        SDZ = Zoo(Name = 'San Diego Zoo', 
    3889                      # This early date should play havoc with a number 
    3990                      # of implementations. 
     
    4495        box.memorize(SDZ) 
    4596         
    46         Biodome = zoo.Zoo(Name = u'Montr\xe9al Biod\xf4me', 
     97        Biodome = Zoo(Name = u'Montr\xe9al Biod\xf4me', 
    4798                          Founded = datetime.date(1992, 6, 19), 
    4899                          Opens = datetime.time(9, 0, 0), 
     
    51102        box.memorize(Biodome) 
    52103         
    53         seaworld = zoo.Zoo(Name = 'Sea_World', 
     104        seaworld = Zoo(Name = 'Sea_World', 
    54105                           Admission = "60", 
    55106                           ) 
     
    57108         
    58109        # Animals 
    59         leopard = zoo.Animal(Name='Leopard', Legs=4, Lifespan=73.5) 
     110        leopard = Animal(Name='Leopard', Legs=4, Lifespan=73.5) 
    60111        self.assertEqual(leopard.PreviousZoos, None) 
    61112        box.memorize(leopard) 
     
    63114        leopard.LastEscape = datetime.datetime(2004, 12, 21, 8, 15, 0) 
    64115         
    65         box.memorize(zoo.Animal(Name='Slug', Legs=1, Lifespan=.75)) 
    66         tiger = zoo.Animal(Name='Tiger', Legs=4) 
     116        box.memorize(Animal(Name='Slug', Legs=1, Lifespan=.75)) 
     117        tiger = Animal(Name='Tiger', Legs=4) 
    67118        box.memorize(tiger) 
    68         box.memorize(zoo.Animal(Name='Lion', Legs=4)) 
    69         box.memorize(zoo.Animal(Name='Bear', Legs=4)) 
     119        box.memorize(Animal(Name='Lion', Legs=4)) 
     120        box.memorize(Animal(Name='Bear', Legs=4)) 
    70121        # Notice that ostrich.PreviousZoos is [], whereas leopard is None. 
    71         box.memorize(zoo.Animal(Name='Ostrich', Legs=2, PreviousZoos=[], 
     122        box.memorize(Animal(Name='Ostrich', Legs=2, PreviousZoos=[], 
    72123                                Lifespan=103.2)) 
    73         box.memorize(zoo.Animal(Name='Centipede', Legs=100)) 
    74          
    75         emp = zoo.Animal(Name='Emperor Penguin', Legs=2) 
     124        box.memorize(Animal(Name='Centipede', Legs=100)) 
     125         
     126        emp = Animal(Name='Emperor Penguin', Legs=2) 
    76127        box.memorize(emp) 
    77         adelie = zoo.Animal(Name='Adelie Penguin', Legs=2) 
     128        adelie = Animal(Name='Adelie Penguin', Legs=2) 
    78129        box.memorize(adelie) 
    79130         
    80131        seaworld.add(emp, adelie) 
    81132         
    82         millipede = zoo.Animal(Name='Millipede', Legs=1000000) 
     133        millipede = Animal(Name='Millipede', Legs=1000000) 
    83134        millipede.PreviousZoos = [WAP.ID] 
    84135        box.memorize(millipede) 
     
    87138         
    88139        # Add a mother and child to test relationships 
    89         bai_yun = zoo.Animal(Name='Ape', Legs=2) 
     140        bai_yun = Animal(Name='Ape', Legs=2) 
    90141        box.memorize(bai_yun) 
    91         hua_mei = zoo.Animal(Name='Ape', Legs=2, Mother=bai_yun.ID) 
     142        hua_mei = Animal(Name='Ape', Legs=2, Mother=bai_yun.ID) 
    92143        box.memorize(hua_mei) 
    93144         
    94145        # Exhibits 
    95         pe = zoo.Exhibit(Name = 'The Penguin Encounter', 
     146        pe = Exhibit(Name = 'The Penguin Encounter', 
    96147                         ZooID = seaworld.ID, 
    97148                         Animals = [emp.ID, adelie.ID], 
     
    101152        box.memorize(pe) 
    102153         
    103         tr = zoo.Exhibit(Name = 'Tiger River', 
     154        tr = Exhibit(Name = 'Tiger River', 
    104155                         ZooID = SDZ.ID, 
    105156                         Animals = [tiger.ID], 
     
    112163     
    113164    def test_1_Object_Properties(self): 
    114         box = zoo.arena.new_sandbox() 
     165        box = arena.new_sandbox() 
    115166         
    116167        # Zoos 
    117         WAP = box.unit(zoo.Zoo, Name='Wild Animal Park') 
     168        WAP = box.unit(Zoo, Name='Wild Animal Park') 
    118169        self.assertNotEqual(WAP, None) 
    119170        self.assertEqual(WAP.Founded, datetime.date(2000, 1, 1)) 
     
    124175        self.assertEqual(str(WAP.Admission), "4.95") 
    125176         
    126         SDZ = box.unit(zoo.Zoo, Founded=datetime.date(1835, 9, 13)) 
     177        SDZ = box.unit(Zoo, Founded=datetime.date(1835, 9, 13)) 
    127178        self.assertNotEqual(SDZ, None) 
    128179        self.assertEqual(SDZ.Founded, datetime.date(1835, 9, 13)) 
     
    131182        self.assertEqual(float(SDZ.Admission), 0) 
    132183         
    133         Biodome = box.unit(zoo.Zoo, Name = u'Montr\xe9al Biod\xf4me') 
     184        Biodome = box.unit(Zoo, Name = u'Montr\xe9al Biod\xf4me') 
    134185        self.assertNotEqual(Biodome, None) 
    135186        self.assertEqual(Biodome.Name, u'Montr\xe9al Biod\xf4me') 
     
    140191         
    141192        if fixedpoint: 
    142             seaworld = box.unit(zoo.Zoo, Admission = fixedpoint.FixedPoint(60)) 
     193            seaworld = box.unit(Zoo, Admission = fixedpoint.FixedPoint(60)) 
    143194        else: 
    144             seaworld = box.unit(zoo.Zoo, Admission = float(60)) 
     195            seaworld = box.unit(Zoo, Admission = float(60)) 
    145196        self.assertNotEqual(seaworld, None) 
    146197        self.assertEqual(seaworld.Name, u'Sea_World') 
    147198         
    148199        # Animals 
    149         leopard = box.unit(zoo.Animal, Name='Leopard') 
     200        leopard = box.unit(Animal, Name='Leopard') 
    150201        self.assertEqual(leopard.Name, 'Leopard') 
    151202        self.assertEqual(leopard.Legs, 4) 
     
    156207                         datetime.datetime(2004, 12, 21, 8, 15, 0)) 
    157208         
    158         ostrich = box.unit(zoo.Animal, Name='Ostrich') 
     209        ostrich = box.unit(Animal, Name='Ostrich') 
    159210        self.assertEqual(ostrich.Name, 'Ostrich') 
    160211        self.assertEqual(ostrich.Legs, 2) 
     
    163214        self.assertEqual(ostrich.LastEscape, None) 
    164215         
    165         millipede = box.unit(zoo.Animal, Legs=1000000) 
     216        millipede = box.unit(Animal, Legs=1000000) 
    166217        self.assertEqual(millipede.Name, 'Millipede') 
    167218        self.assertEqual(millipede.Legs, 1000000) 
     
    171222         
    172223        # Exhibits 
    173         exes = box.recall(zoo.Exhibit) 
     224        exes = box.recall(Exhibit) 
    174225        self.assertEqual(len(exes), 2) 
    175226        if exes[0].Name == 'The Penguin Encounter': 
     
    192243     
    193244    def test_2_Expressions(self): 
    194         box = zoo.arena.new_sandbox() 
    195          
    196         def matches(lam, cls=zoo.Animal): 
     245        box = arena.new_sandbox() 
     246         
     247        def matches(lam, cls=Animal): 
    197248            # We flush_all to ensure a DB hit each time. 
    198249            box.flush_all() 
    199250            return len(box.recall(cls, logic.Expression(lam))) 
    200251         
    201         zoos = box.recall(zoo.Zoo) 
     252        zoos = box.recall(Zoo) 
    202253        self.assertEqual(zoos[0].dirty(), False) 
    203254        self.assertEqual(len(zoos), 4) 
     
    237288        # Test now(), today(), year() 
    238289        self.assertEqual(matches(lambda x: x.Founded != None 
    239                                  and x.Founded < dejavu.today(), zoo.Zoo), 3) 
     290                                 and x.Founded < dejavu.today(), Zoo), 3) 
    240291        self.assertEqual(matches(lambda x: x.LastEscape == dejavu.now()), 0) 
    241292        self.assertEqual(matches(lambda x: dejavu.year(x.LastEscape) == 2004), 1) 
     
    249300        # Test wildcards in LIKE. 
    250301        box.flush_all() 
    251         units = box.recall(zoo.Zoo, logic.Expression(lambda x: "_" in x.Name)) 
     302        units = box.recall(Zoo, logic.Expression(lambda x: "_" in x.Name)) 
    252303        self.assertEqual(len(units), 1) 
    253304         
     
    260311                             ) 
    261312        e.bind_args(Year=2004) 
    262         units = box.recall(zoo.Animal, e) 
     313        units = box.recall(Animal, e) 
    263314        self.assertEqual(len(units), 1) 
    264315     
    265316    def test_3_Aggregates(self): 
    266         box = zoo.arena.new_sandbox() 
     317        box = arena.new_sandbox() 
    267318         
    268319        # views 
    269         legs = [x[0] for x in box.view(zoo.Animal, ['Legs'])] 
     320        legs = [x[0] for x in box.view(Animal, ['Legs'])] 
    270321        legs.sort() 
    271322        self.assertEqual(legs, [1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 100, 1000000]) 
     
    283334                    'Ape': None, 
    284335                    } 
    285         for name, lifespan in box.view(zoo.Animal, ['Name', 'Lifespan']): 
     336        for name, lifespan in box.view(Animal, ['Name', 'Lifespan']): 
    286337            if expected[name] is None: 
    287338                self.assertEqual(lifespan, None) 
     
    290341         
    291342        # distinct 
    292         legs = box.distinct(zoo.Animal, ['Legs']) 
     343        legs = box.distinct(Animal, ['Legs']) 
    293344        legs.sort() 
    294345        self.assertEqual(legs, [1, 2, 4, 100, 1000000]) 
     
    296347        # This may raise a warning on some DB's. 
    297348        f = logic.Expression(lambda x: x.Name == 'Lion') 
    298         escapees = box.distinct(zoo.Animal, ['Legs'], f) 
     349        escapees = box.distinct(Animal, ['Legs'], f) 
    299350        self.assertEqual(escapees, [4]) 
    300351     
    301352    def test_4_Multiselect(self): 
    302         box = zoo.arena.new_sandbox() 
     353        box = arena.new_sandbox() 
    303354        zooed_animals = [(z, a) for z, a in 
    304                          box.multirecall((zoo.Zoo, logic.filter(Name='San Diego Zoo')), 
    305                                          (zoo.Animal, None))] 
    306         SDZ = box.unit(zoo.Zoo, Name='San Diego Zoo') 
     355                         box.multirecall((Zoo, logic.filter(Name='San Diego Zoo')), 
     356                                         (Animal, None))] 
     357        SDZ = box.unit(Zoo, Name='San Diego Zoo') 
    307358        self.assertEqual(len(zooed_animals), 2) 
    308359        aid = 0 
     
    315366        # no matches for the initial class. 
    316367        zooed_animals = [(z, a) for z, a in 
    317                          box.multirecall((zoo.Zoo, logic.filter(Name='San Diego Zoo')), 
    318                                          (zoo.Animal, logic.filter(Name='Leopard')))] 
     368                         box.multirecall((Zoo, logic.filter(Name='San Diego Zoo')), 
     369                                         (Animal, logic.filter(Name='Leopard')))] 
    319370        self.assertEqual(len(zooed_animals), 0) 
    320371     
     
    324375            # Notice we only do reads in this thread, not writes, since 
    325376            # the order of thread execution can not be guaranteed. 
    326             box = zoo.arena.new_sandbox() 
    327             quadrupeds = box.recall(zoo.Animal, f) 
     377            box = arena.new_sandbox() 
     378            quadrupeds = box.recall(Animal, f) 
    328379            self.assertEqual(len(quadrupeds), 4) 
    329380         
     
    339390    def test_6_Editing(self): 
    340391        # Edit 
    341         box = zoo.arena.new_sandbox() 
    342         SDZ = box.unit(zoo.Zoo, Name='San Diego Zoo') 
     392        box = arena.new_sandbox() 
     393        SDZ = box.unit(Zoo, Name='San Diego Zoo') 
    343394        SDZ.Name = 'The San Diego Zoo' 
    344395        SDZ.Founded = datetime.date(1900, 1, 1) 
     
    348399         
    349400        # Test edits 
    350         box = zoo.arena.new_sandbox() 
    351         SDZ = box.unit(zoo.Zoo, Name='The San Diego Zoo') 
     401        box = arena.new_sandbox() 
     402        SDZ = box.unit(Zoo, Name='The San Diego Zoo') 
    352403        self.assertEqual(SDZ.Name, 'The San Diego Zoo') 
    353404        self.assertEqual(SDZ.Founded, datetime.date(1900, 1, 1)) 
     
    360411         
    361412        # Change it back 
    362         box = zoo.arena.new_sandbox() 
    363         SDZ = box.unit(zoo.Zoo, Name='The San Diego Zoo') 
     413        box = arena.new_sandbox() 
     414        SDZ = box.unit(Zoo, Name='The San Diego Zoo') 
    364415        SDZ.Name = 'San Diego Zoo' 
    365416        SDZ.Founded = datetime.date(1835, 9, 13) 
     
    369420         
    370421        # Test re-edits 
    371         box = zoo.arena.new_sandbox() 
    372         SDZ = box.unit(zoo.Zoo, Name='San Diego Zoo') 
     422        box = arena.new_sandbox() 
     423        SDZ = box.unit(Zoo, Name='San Diego Zoo') 
    373424        self.assertEqual(SDZ.Name, 'San Diego Zoo') 
    374425        self.assertEqual(SDZ.Founded, datetime.date(1835, 9, 13)) 
     
    380431     
    381432    def test_7_Iteration(self): 
    382         box = zoo.arena.new_sandbox() 
     433        box = arena.new_sandbox() 
    383434         
    384435        # Test box.unit inside of xrecall 
    385         for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
    386             mother = box.unit(zoo.Animal, ID=ape.Mother) 
     436        for ape in box.xrecall(Animal, logic.filter(Name='Ape')): 
     437            mother = box.unit(Animal, ID=ape.Mother) 
    387438            if ape.ID == 11: 
    388439                self.assertEqual(mother, None) 
     
    391442         
    392443        # Test recall inside of xrecall 
    393         for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
     444        for ape in box.xrecall(Animal, logic.filter(Name='Ape')): 
    394445            children = 0 
    395             for child in box.recall(zoo.Animal, logic.filter(Mother=ape.ID)): 
     446            for child in box.recall(Animal, logic.filter(Mother=ape.ID)): 
    396447                children += 1 
    397448            if ape.ID == 11: 
     
    401452         
    402453        # Test far associations inside of xrecall 
    403         for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
    404             mother = ape.first(zoo.Animal) 
     454        for ape in box.xrecall(Animal, logic.filter(Name='Ape')): 
     455            mother = ape.first(Animal) 
    405456            if ape.ID == 11: 
    406457                self.assertEqual(mother, None) 
     
    409460 
    410461 
    411 def setup_SM(SM_class, opts): 
    412     """setup_SM(SM_class, opts). Set up storage for Zoo classes.""" 
    413     zoo.arena.add_store('testSM', SM_class, opts) 
    414      
    415     for cls in (zoo.Animal, zoo.Zoo, zoo.Exhibit): 
    416         zoo.arena.create_storage(cls) 
     462arena = dejavu.Arena() 
     463 
     464def init(): 
     465    global arena 
     466    arena = dejavu.Arena() 
     467 
     468def setup(SM_class, opts): 
     469    """setup(SM_class, opts). Set up storage for Zoo classes.""" 
     470    global arena 
     471    arena.add_store('testSM', SM_class, opts) 
     472    arena.register_all(globals()) 
     473     
     474    for cls in (Animal, Zoo, Exhibit): 
     475        arena.create_storage(cls) 
    417476 
    418477def teardown(): 
    419     zoo.arena.shutdown() 
    420     for store in zoo.arena.stores.values(): 
     478    """Tear down storage for Zoo classes.""" 
     479    global arena 
     480    arena.shutdown() 
     481    for store in arena.stores.values(): 
    421482        try: 
    422483            store.drop_database() 
    423484        except (AttributeError, NotImplementedError): 
    424485            pass 
    425     zoo.arena.stores = {} 
    426     zoo.arena.defaultStore = None 
    427  
    428 def run_tests(SM_class, opts, profile=True): 
    429     import traceback 
     486    arena.stores = {} 
     487    arena.defaultStore = None 
     488 
     489def run(SM_class, opts): 
     490    """Run the zoo fixture.""" 
    430491    try: 
    431         try: 
    432             setup_SM(SM_class, opts) 
    433             if profile: 
    434                 import hotshot 
    435                 prof = hotshot.Profile("zoo_fixture.prof") 
    436                 prof.runcall(unittest.main, __name__) 
    437             else: 
    438                 unittest.main(__name__) 
    439         except SystemExit: 
    440             # unittest.main normally raises SystemExit when complete. 
    441             pass 
    442         except: 
    443             traceback.print_exc() 
    444             print 
     492        setup(SM_class, opts) 
     493        suite = unittest.TestLoader().loadTestsFromTestCase(ZooTests) 
     494        tools.djvTestRunner.run(suite) 
    445495    finally: 
    446496        teardown()