Changeset 96
- Timestamp:
- 11/17/05 08:11:28
- Files:
-
- trunk/__init__.py (modified) (2 diffs)
- trunk/storage/__init__.py (modified) (3 diffs)
- trunk/test/__init__.py (added)
- trunk/test/test.py (added)
- trunk/test/test_analysis.py (modified) (2 diffs)
- trunk/test/test_codewalk.py (modified) (3 diffs)
- trunk/test/test_containers.py (modified) (2 diffs)
- trunk/test/test_dejavu.py (modified) (2 diffs)
- trunk/test/test_logic.py (modified) (3 diffs)
- trunk/test/test_storage.py (deleted)
- trunk/test/test_storeburned.py (added)
- trunk/test/test_storecaching.py (added)
- trunk/test/test_storemsaccess.py (modified) (1 diff)
- trunk/test/test_storemysql.py (modified) (1 diff)
- trunk/test/test_storeodbc.py (modified) (3 diffs)
- trunk/test/test_storeproxy.py (added)
- trunk/test/test_storepypgsql.py (modified) (1 diff)
- trunk/test/test_storeshelve.py (modified) (1 diff)
- trunk/test/test_storesqlite.py (modified) (1 diff)
- trunk/test/test_storesqlserver.py (modified) (1 diff)
- trunk/test/tools.py (added)
- trunk/test/zoo.py (deleted)
- trunk/test/zoo_fixture.py (modified) (33 diffs)
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. 2 2 3 3 Persisted objects are called "Units", and are served into Sandboxes within … … 49 49 REDISTRIBUTION OF THIS SOFTWARE. 50 50 """ 51 52 __version__ = "1.3 beta 2" 53 51 54 52 55 import ConfigParser trunk/storage/__init__.py
r95 r96 9 9 except ImportError: 10 10 import pickle 11 12 from dejavu import logic 11 13 12 14 … … 232 234 expr = logic.Expression(lambda x: True) 233 235 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] 237 239 seen = [] 238 240 … … 253 255 index_of_id = fields.index("ID") 254 256 255 for row in self.nextstore.view( unitClass, fields, expr):257 for row in self.nextstore.view(cls, fields, expr): 256 258 if row[index_of_id] not in cache: 257 259 if "ID" not in attrs: trunk/test/test_analysis.py
r95 r96 1 import datetime 1 2 import unittest 2 import datetime 3 import analysis3 4 from dejavu import analysis 4 5 5 6 … … 65 66 66 67 67 def run_tests(): 68 try: 69 unittest.main(__name__) 70 except SystemExit: 71 # unittest.main normally raises SystemExit when complete. 72 pass 68 if __name__ == "__main__": 69 unittest.main(__name__) 73 70 74 if __name__ == "__main__":75 run_tests()76 trunk/test/test_codewalk.py
r95 r96 1 import sys2 import unittest3 4 from dejavu import codewalk5 nums = codewalk.numeric_opcodes6 7 1 import datetime 8 2 try: … … 10 4 except ImportError: 11 5 fixedpoint = None 6 import sys 7 import unittest 8 9 from dejavu import codewalk 10 nums = codewalk.numeric_opcodes 12 11 13 12 amount = 5 … … 208 207 209 208 210 def run_tests():211 try:212 unittest.main(__name__)213 except SystemExit:214 # unittest.main normally raises SystemExit when complete.215 pass216 217 209 if __name__ == "__main__": 218 run_tests()219 210 unittest.main(__name__) 211 trunk/test/test_containers.py
r95 r96 1 import operator 1 2 import unittest 2 import operator3 3 from dejavu import containers 4 4 … … 160 160 161 161 162 def run_tests(): 163 try: 164 unittest.main(__name__) 165 except SystemExit: 166 # unittest.main normally raises SystemExit when complete. 167 pass 162 if __name__ == "__main__": 163 unittest.main(__name__) 168 164 169 if __name__ == "__main__":170 run_tests()171 trunk/test/test_dejavu.py
r95 r96 1 import datetime 1 2 import unittest 2 import datetime3 3 4 4 import dejavu 5 5 from dejavu import zoo, storage 6 zoo.arena.add_store("default", " storage.CachingProxy")6 zoo.arena.add_store("default", "dejavu.storage.CachingProxy") 7 7 8 8 … … 115 115 116 116 117 def run_tests(): 118 try: 119 unittest.main(__name__) 120 except SystemExit: 121 # unittest.main normally raises SystemExit when complete. 122 pass 117 if __name__ == "__main__": 118 unittest.main(__name__) 123 119 124 if __name__ == "__main__":125 run_tests()126 trunk/test/test_logic.py
r95 r96 1 1 import datetime 2 import pickle 2 3 import sys 3 4 import unittest … … 8 9 nums = logic.codewalk.numeric_opcodes 9 10 10 import pickle11 11 12 12 class ExpressionTests(unittest.TestCase): … … 209 209 210 210 211 def run_tests():212 try:213 unittest.main(__name__)214 except SystemExit:215 # unittest.main normally raises SystemExit when complete.216 pass217 218 211 if __name__ == "__main__": 219 run_tests()220 212 unittest.main(__name__) 213 trunk/test/test_storemsaccess.py
r95 r96 2 2 the Access SM will crash python.""" 3 3 4 import zoo_fixture5 4 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) 5 SM_class = "dejavu.storage.storeado.StorageManagerADO_MSAccess" 6 opts = {u'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zoo.mdb;", 7 u'Expanded Columns': "Animal.PreviousZoos:int", 8 } 9 12 10 13 11 if __name__ == "__main__": 14 run_tests() 12 import test 13 test.run_zoo(SM_class, opts) 15 14 trunk/test/test_storemysql.py
r95 r96 1 import zoo_fixture2 1 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 3 opts = {"host": "localhost", 4 "db": "dejavu_test", 5 "user": "root", 6 "passwd": "", 7 } 8 if opts['passwd'] == "": 9 opts['passwd'] = raw_input("Enter the password for the MySQL '%s' user:" 10 % opts['user']) 11 SM_class = "dejavu.storage.storemysql.StorageManagerMySQL" 11 12 12 13 13 14 if __name__ == "__main__": 14 run_tests() 15 import test 16 test.run_zoo(SM_class, opts) 15 17 trunk/test/test_storeodbc.py
r95 r96 1 import zoo_fixture2 1 3 2 def create_access_db(): … … 7 6 cat.Create("PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zooodbc.mdb;") 8 7 8 create_access_db() 9 9 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. 12 opts = {u'Connect': ("Provider=MSDASQL;" 13 "Driver={Microsoft Access Driver (*.mdb)};" 14 "DBQ=zooodbc.mdb;Provider=MSDASQL;"), 15 u'Expanded Columns': "Animal.PreviousZoos:int", 16 } 17 SM_class = "dejavu.storage.storeodbc.StorageManagerODBC" 18 19 20 if __name__ == "__main__": 21 import test 21 22 try: 22 zoo_fixture.run_tests("dejavu.storage.storeodbc.StorageManagerODBC", opts)23 test.run_zoo(SM_class, opts) 23 24 finally: 24 25 try: … … 27 28 print "Could not remove database." 28 29 29 30 if __name__ == "__main__":31 run_tests()32 trunk/test/test_storepypgsql.py
r95 r96 1 import zoo_fixture2 1 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) 2 user = "postgres" 3 passwd = "" 4 5 if passwd == "": 6 passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 7 8 opts = {u'Connect': ("host=localhost dbname=dejavu_test " 9 "user=%s password=%s" % (user, passwd)), 10 } 11 SM_class = "dejavu.storage.storepypgsql.StorageManagerPgSQL" 12 13 del user, passwd 9 14 10 15 11 16 if __name__ == "__main__": 12 run_tests() 17 import test 18 test.run_zoo(SM_class, opts) 13 19 trunk/test/test_storeshelve.py
r95 r96 7 7 8 8 import os 9 import zoo_fixture10 9 11 def run_tests(): 12 opts = {u'Path': os.getcwd()} 13 14 zoo_fixture.run_tests("dejavu.storage.storeshelve.StorageManagerShelve", opts) 15 10 opts = {u'Path': os.getcwd()} 11 SM_class = "dejavu.storage.storeshelve.StorageManagerShelve" 16 12 17 13 18 14 if __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_fixture2 1 3 def run_tests(): 4 opts = {"Database": "sqlite_zoo_test"} 5 zoo_fixture.run_tests("dejavu.storage.storesqlite.StorageManagerSQLite", opts) 2 SM_class = "dejavu.storage.storesqlite.StorageManagerSQLite" 3 opts = {"Database": "sqlite_zoo_test"} 6 4 7 5 8 6 if __name__ == "__main__": 9 run_tests() 7 import test 8 test.run_zoo(SM_class, opts) 10 9 trunk/test/test_storesqlserver.py
r95 r96 1 import zoo_fixture2 1 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) 2 opts = {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 } 7 SM_class = "dejavu.storage.storeado.StorageManagerADO_SQLServer" 10 8 11 9 12 10 if __name__ == "__main__": 13 run_tests() 11 import test 12 test.run_zoo(SM_class, opts) 14 13 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 3 import datetime 4 import threading 8 5 import unittest 9 import threading 10 import datetime 11 import dejavu 12 from dejavu import logic, zoo 6 7 try: 8 import decimal 9 except ImportError: 10 decimal = None 13 11 14 12 try: … … 17 15 fixedpoint = None 18 16 17 import dejavu 18 from dejavu import logic 19 from dejavu import Unit, UnitProperty, associate 20 from dejavu.test import tools 21 22 23 class 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 35 class 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 43 class 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) 54 associate(Zoo, 'ID', Animal, 'ZooID') 55 associate(Animal, 'ID', Animal, 'Mother') 56 57 58 class 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) 68 associate(Zoo, 'ID', Exhibit, 'ZooID') 69 19 70 20 71 class ZooTests(unittest.TestCase): 21 72 22 73 def test_0_populate(self): 23 box = zoo.arena.new_sandbox()74 box = arena.new_sandbox() 24 75 25 76 # Notice this also tests that: a Unit which is only 26 77 # dirtied via __init__ is still saved. 27 WAP = zoo.Zoo(Name = 'Wild Animal Park',78 WAP = Zoo(Name = 'Wild Animal Park', 28 79 Founded = datetime.date(2000, 1, 1), 29 80 # 59 can give rounding errors with divmod, which … … 35 86 box.memorize(WAP) 36 87 37 SDZ = zoo.Zoo(Name = 'San Diego Zoo',88 SDZ = Zoo(Name = 'San Diego Zoo', 38 89 # This early date should play havoc with a number 39 90 # of implementations. … … 44 95 box.memorize(SDZ) 45 96 46 Biodome = zoo.Zoo(Name = u'Montr\xe9al Biod\xf4me',97 Biodome = Zoo(Name = u'Montr\xe9al Biod\xf4me', 47 98 Founded = datetime.date(1992, 6, 19), 48 99 Opens = datetime.time(9, 0, 0), … … 51 102 box.memorize(Biodome) 52 103 53 seaworld = zoo.Zoo(Name = 'Sea_World',104 seaworld = Zoo(Name = 'Sea_World', 54 105 Admission = "60", 55 106 ) … … 57 108 58 109 # Animals 59 leopard = zoo.Animal(Name='Leopard', Legs=4, Lifespan=73.5)110 leopard = Animal(Name='Leopard', Legs=4, Lifespan=73.5) 60 111 self.assertEqual(leopard.PreviousZoos, None) 61 112 box.memorize(leopard) … … 63 114 leopard.LastEscape = datetime.datetime(2004, 12, 21, 8, 15, 0) 64 115 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) 67 118 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)) 70 121 # 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=[], 72 123 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) 76 127 box.memorize(emp) 77 adelie = zoo.Animal(Name='Adelie Penguin', Legs=2)128 adelie = Animal(Name='Adelie Penguin', Legs=2) 78 129 box.memorize(adelie) 79 130 80 131 seaworld.add(emp, adelie) 81 132 82 millipede = zoo.Animal(Name='Millipede', Legs=1000000)133 millipede = Animal(Name='Millipede', Legs=1000000) 83 134 millipede.PreviousZoos = [WAP.ID] 84 135 box.memorize(millipede) … … 87 138 88 139 # 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) 90 141 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) 92 143 box.memorize(hua_mei) 93 144 94 145 # Exhibits 95 pe = zoo.Exhibit(Name = 'The Penguin Encounter',146 pe = Exhibit(Name = 'The Penguin Encounter', 96 147 ZooID = seaworld.ID, 97 148 Animals = [emp.ID, adelie.ID], … … 101 152 box.memorize(pe) 102 153 103 tr = zoo.Exhibit(Name = 'Tiger River',154 tr = Exhibit(Name = 'Tiger River', 104 155 ZooID = SDZ.ID, 105 156 Animals = [tiger.ID], … … 112 163 113 164 def test_1_Object_Properties(self): 114 box = zoo.arena.new_sandbox()165 box = arena.new_sandbox() 115 166 116 167 # Zoos 117 WAP = box.unit( zoo.Zoo, Name='Wild Animal Park')168 WAP = box.unit(Zoo, Name='Wild Animal Park') 118 169 self.assertNotEqual(WAP, None) 119 170 self.assertEqual(WAP.Founded, datetime.date(2000, 1, 1)) … … 124 175 self.assertEqual(str(WAP.Admission), "4.95") 125 176 126 SDZ = box.unit( zoo.Zoo, Founded=datetime.date(1835, 9, 13))177 SDZ = box.unit(Zoo, Founded=datetime.date(1835, 9, 13)) 127 178 self.assertNotEqual(SDZ, None) 128 179 self.assertEqual(SDZ.Founded, datetime.date(1835, 9, 13)) … … 131 182 self.assertEqual(float(SDZ.Admission), 0) 132 183 133 Biodome = box.unit( zoo.Zoo, Name = u'Montr\xe9al Biod\xf4me')184 Biodome = box.unit(Zoo, Name = u'Montr\xe9al Biod\xf4me') 134 185 self.assertNotEqual(Biodome, None) 135 186 self.assertEqual(Biodome.Name, u'Montr\xe9al Biod\xf4me') … … 140 191 141 192 if fixedpoint: 142 seaworld = box.unit( zoo.Zoo, Admission = fixedpoint.FixedPoint(60))193 seaworld = box.unit(Zoo, Admission = fixedpoint.FixedPoint(60)) 143 194 else: 144 seaworld = box.unit( zoo.Zoo, Admission = float(60))195 seaworld = box.unit(Zoo, Admission = float(60)) 145 196 self.assertNotEqual(seaworld, None) 146 197 self.assertEqual(seaworld.Name, u'Sea_World') 147 198 148 199 # Animals 149 leopard = box.unit( zoo.Animal, Name='Leopard')200 leopard = box.unit(Animal, Name='Leopard') 150 201 self.assertEqual(leopard.Name, 'Leopard') 151 202 self.assertEqual(leopard.Legs, 4) … … 156 207 datetime.datetime(2004, 12, 21, 8, 15, 0)) 157 208 158 ostrich = box.unit( zoo.Animal, Name='Ostrich')209 ostrich = box.unit(Animal, Name='Ostrich') 159 210 self.assertEqual(ostrich.Name, 'Ostrich') 160 211 self.assertEqual(ostrich.Legs, 2) … … 163 214 self.assertEqual(ostrich.LastEscape, None) 164 215 165 millipede = box.unit( zoo.Animal, Legs=1000000)216 millipede = box.unit(Animal, Legs=1000000) 166 217 self.assertEqual(millipede.Name, 'Millipede') 167 218 self.assertEqual(millipede.Legs, 1000000) … … 171 222 172 223 # Exhibits 173 exes = box.recall( zoo.Exhibit)224 exes = box.recall(Exhibit) 174 225 self.assertEqual(len(exes), 2) 175 226 if exes[0].Name == 'The Penguin Encounter': … … 192 243 193 244 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): 197 248 # We flush_all to ensure a DB hit each time. 198 249 box.flush_all() 199 250 return len(box.recall(cls, logic.Expression(lam))) 200 251 201 zoos = box.recall( zoo.Zoo)252 zoos = box.recall(Zoo) 202 253 self.assertEqual(zoos[0].dirty(), False) 203 254 self.assertEqual(len(zoos), 4) … … 237 288 # Test now(), today(), year() 238 289 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) 240 291 self.assertEqual(matches(lambda x: x.LastEscape == dejavu.now()), 0) 241 292 self.assertEqual(matches(lambda x: dejavu.year(x.LastEscape) == 2004), 1) … … 249 300 # Test wildcards in LIKE. 250 301 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)) 252 303 self.assertEqual(len(units), 1) 253 304 … … 260 311 ) 261 312 e.bind_args(Year=2004) 262 units = box.recall( zoo.Animal, e)313 units = box.recall(Animal, e) 263 314 self.assertEqual(len(units), 1) 264 315 265 316 def test_3_Aggregates(self): 266 box = zoo.arena.new_sandbox()317 box = arena.new_sandbox() 267 318 268 319 # views 269 legs = [x[0] for x in box.view( zoo.Animal, ['Legs'])]320 legs = [x[0] for x in box.view(Animal, ['Legs'])] 270 321 legs.sort() 271 322 self.assertEqual(legs, [1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 100, 1000000]) … … 283 334 'Ape': None, 284 335 } 285 for name, lifespan in box.view( zoo.Animal, ['Name', 'Lifespan']):336 for name, lifespan in box.view(Animal, ['Name', 'Lifespan']): 286 337 if expected[name] is None: 287 338 self.assertEqual(lifespan, None) … … 290 341 291 342 # distinct 292 legs = box.distinct( zoo.Animal, ['Legs'])343 legs = box.distinct(Animal, ['Legs']) 293 344 legs.sort() 294 345 self.assertEqual(legs, [1, 2, 4, 100, 1000000]) … … 296 347 # This may raise a warning on some DB's. 297 348 f = logic.Expression(lambda x: x.Name == 'Lion') 298 escapees = box.distinct( zoo.Animal, ['Legs'], f)349 escapees = box.distinct(Animal, ['Legs'], f) 299 350 self.assertEqual(escapees, [4]) 300 351 301 352 def test_4_Multiselect(self): 302 box = zoo.arena.new_sandbox()353 box = arena.new_sandbox() 303 354 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') 307 358 self.assertEqual(len(zooed_animals), 2) 308 359 aid = 0 … … 315 366 # no matches for the initial class. 316 367 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')))] 319 370 self.assertEqual(len(zooed_animals), 0) 320 371 … … 324 375 # Notice we only do reads in this thread, not writes, since 325 376 # 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) 328 379 self.assertEqual(len(quadrupeds), 4) 329 380 … … 339 390 def test_6_Editing(self): 340 391 # 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') 343 394 SDZ.Name = 'The San Diego Zoo' 344 395 SDZ.Founded = datetime.date(1900, 1, 1) … … 348 399 349 400 # 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') 352 403 self.assertEqual(SDZ.Name, 'The San Diego Zoo') 353 404 self.assertEqual(SDZ.Founded, datetime.date(1900, 1, 1)) … … 360 411 361 412 # 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') 364 415 SDZ.Name = 'San Diego Zoo' 365 416 SDZ.Founded = datetime.date(1835, 9, 13) … … 369 420 370 421 # 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') 373 424 self.assertEqual(SDZ.Name, 'San Diego Zoo') 374 425 self.assertEqual(SDZ.Founded, datetime.date(1835, 9, 13)) … … 380 431 381 432 def test_7_Iteration(self): 382 box = zoo.arena.new_sandbox()433 box = arena.new_sandbox() 383 434 384 435 # 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) 387 438 if ape.ID == 11: 388 439 self.assertEqual(mother, None) … … 391 442 392 443 # 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')): 394 445 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)): 396 447 children += 1 397 448 if ape.ID == 11: … … 401 452 402 453 # 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) 405 456 if ape.ID == 11: 406 457 self.assertEqual(mother, None) … … 409 460 410 461 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) 462 arena = dejavu.Arena() 463 464 def init(): 465 global arena 466 arena = dejavu.Arena() 467 468 def 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) 417 476 418 477 def 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(): 421 482 try: 422 483 store.drop_database() 423 484 except (AttributeError, NotImplementedError): 424 485 pass 425 zoo.arena.stores = {}426 zoo.arena.defaultStore = None427 428 def run _tests(SM_class, opts, profile=True):429 import traceback486 arena.stores = {} 487 arena.defaultStore = None 488 489 def run(SM_class, opts): 490 """Run the zoo fixture.""" 430 491 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) 445 495 finally: 446 496 teardown()
