PageRenderTime 390ms CodeModel.GetById 161ms app.highlight 199ms RepoModel.GetById 12ms app.codeStats 1ms

/test/suite_0.py

http://pickled-object-database.googlecode.com/
Python | 1962 lines | 1317 code | 598 blank | 47 comment | 264 complexity | d439f8693c2f5e2b861cb4d1e2429043 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1import sys
   2import os
   3import unittest
   4import inspect
   5import figleaf
   6import figleaf.annotate_html
   7import shutil
   8import exceptions
   9import sqlite3
  10
  11class Tester(unittest.TestCase):
  12
  13    org_modules = set(sys.modules.copy().keys())
  14
  15    @classmethod
  16    def reporter_start(cls, use_figleaf = True):
  17        if use_figleaf:
  18            cls.figleaf_dir = inspect.getabsfile(sys.modules[__name__]).split('.')[-2].split(os.sep)[-1]
  19            if os.path.isdir(cls.figleaf_dir):
  20                shutil.rmtree(cls.figleaf_dir, ignore_errors = True)
  21            os.mkdir(cls.figleaf_dir)
  22            figleaf.start()
  23        
  24        cls.figleaf_use = use_figleaf
  25        
  26    @classmethod
  27    def reporter_stop(cls, viewer = None):
  28        if cls.figleaf_use:
  29            figleaf.stop()
  30            figleaf.annotate_html.report_as_html(figleaf.get_info(), directory = cls.figleaf_dir, exclude_patterns = [], files_list = {})
  31            print "\n\nWrote figleaf report to '" + cls.figleaf_dir + "' . . . "
  32            
  33        import pod
  34        print "\n\nUsing pod module:\n\t'" + inspect.getabsfile(pod) +"'"
  35
  36    @classmethod
  37    def run_test(cls, test):
  38        unittest.TextTestRunner(verbosity=2).run(unittest.defaultTestLoader.loadTestsFromTestCase(test))
  39
  40    def __le__(self, item):
  41        if 'first_equals_item' in self.__dict__:
  42            self.assertEqual(self.first_equals_item, item)
  43            del self.__dict__['first_equals_item']
  44        else:
  45            self.first_equals_item = item
  46    
  47    def __eq__(self, item):
  48        if not isinstance(item, (list, tuple)):
  49            item = tuple(item)
  50        self.assertEqual(item[0], item[1])
  51    
  52    def setUp(self):
  53        self.filename = 'suite_0.sqlite3.db'
  54
  55    def clear_mod_imports(self):
  56        new_modules = set(sys.modules.copy().keys()) - Tester.org_modules
  57        for key in new_modules:
  58            del sys.modules[key]
  59
  60    def tearDown(self):
  61        self.clear_mod_imports()
  62        if os.path.isfile(self.filename):
  63            #os.remove(self.filename)
  64            pass
  65 
  66    class raises(object):
  67    
  68        def __init__(self, *args):
  69            self.exceptions = tuple(args)
  70            
  71        def __call__(self, fn):
  72
  73            excepted = False
  74            
  75            try:
  76                fn()
  77            except self.exceptions:
  78                excepted = True
  79            
  80            if excepted is False:
  81                raise exceptions.AssertionError, "Exceptions not raised: " + str(self.exceptions)
  82                
  83""" THE BASICS """            
  84class Basics(Tester):
  85  
  86    def test_basics(self):
  87        self.basic_section_0()
  88        self.clear_mod_imports()
  89        self.basic_section_1()        
  90        self.clear_mod_imports()
  91        
  92    def basic_section_0(self):
  93        import pod
  94        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
  95        
  96        class Person(pod.Object):
  97            pass
  98        
  99        class Punk(Person):
 100            pass
 101        
 102        class Email(pod.Object):
 103            ctime = pod.typed.TimeCreate()
 104        
 105        email_0 = Email(title = 'FYI',      age = 1)
 106        email_1 = Email(title = 'GO HOME',  age = 2)
 107        email_2 = Email(title = 'HI',       age = 3.3)
 108        
 109        Person(name = 'Fred',  age = 32,     emails = [email_0, email_1])
 110        Person(name = 'Hsing', age = 35.3,   emails = [])
 111        Person(name = 'Joan',  age = 22.3,   emails = [email_2])
 112        
 113        Punk(name = 'Mred',  age = 12,     emails = [email_0, email_1])
 114        Punk(name = 'Xsing', age = 15.3,   emails = [email_0, email_1, email_2])
 115        Punk(name = 'Yoan',  age = 12.3,   emails = [email_2])
 116
 117        self <= [peep.name for peep in Person.where.age == 32]
 118        self <= ['Fred']
 119
 120        self <= [peep.name for peep in Person.where.name[1:3] == 're']
 121        self <= ['Fred', 'Mred']
 122
 123        self <= [peep.name for peep in (Person.where.name[-3:-1] == 're') | (Person.where.age == 35.3)]
 124        self <= ['Fred', 'Hsing', 'Mred']
 125
 126        self <= [peep.name for peep in Person.where.emails == [email_2]]
 127        self <= ['Joan', 'Yoan']
 128
 129        self <= [peep.name for peep in Person.where.age < 25]
 130        self <= ['Joan', 'Mred', 'Xsing', 'Yoan']
 131
 132        self <= [peep.name for peep in (Person.where.emails == [email_2]) & (Person.where.age < 25)]
 133        self <= ['Joan', 'Yoan']
 134        
 135        self <= [peep.name for peep in (Person.where.emails == [email_2]) & (Person.where.age < 10)]
 136        self <= []
 137        
 138        self <= Email.get_count()
 139        self <= 3
 140
 141        self <= Person.get_count()
 142        self <= 6
 143
 144        self <= Person.get_count(child_classes = False)
 145        self <= 3
 146
 147        self <= Punk.get_count(child_classes = False)
 148        self <= 3
 149
 150        self <= [email.title for email in Email.ctime.younger_than(days = 1)]
 151        self <= ['FYI', 'GO HOME', 'HI']
 152
 153        import time
 154        time.sleep(1)
 155        
 156        self <= [email.title for email in Email.ctime.older_than(seconds = 1)]
 157        self <= ['FYI', 'GO HOME', 'HI']
 158
 159        db.commit(close = True)
 160        
 161    def basic_section_1(self):
 162        import pod
 163        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
 164        
 165        class Person(pod.Object):
 166            name   = pod.typed.String()
 167            age    = pod.typed.Int(index = True)
 168            alive  = pod.typed.Boolean()
 169            boss   = pod.typed.PodObject()
 170            emails = pod.typed.Object() 
 171        
 172        class Punk(Person):
 173            weight = pod.typed.Float()
 174        
 175        class Email(pod.Object):
 176            ctime = pod.typed.TimeCreate()
 177        
 178        email_0 = Email(title = 'FYI',      age = 1)
 179        email_1 = Email(title = 'GO HOME',  age = 2)
 180        email_2 = Email(title = 'HI',       age = 3.3)
 181        
 182        boss = Person(name = 'Don', age = 55, emails = [email_0, email_1], random = 'FOO')
 183        Person(name = 'Fred',  age = 32,      emails = [email_0, email_1], boss = boss, random = 'FOO')
 184        Person(name = 'Hsing', age = 35.3,    emails = [], boss = boss, random = 10.0)
 185        Person(name = 'Joan',  age = 22.3,    emails = [email_2], boss = boss, random = 20.0)
 186        
 187        Punk(name = 'Mred',  age = 12,     weight = 30.1, emails = [email_0, email_1], boss = boss, random = 30.0)
 188        Punk(name = 'Xsing', age = 15.3,   weight = 40.1, emails = [email_0, email_1, email_2], boss = boss, random = 10.0)
 189        Punk(name = 'Yoan',  age = 12.3,   weight = 50.1, emails = [email_2], boss = None, random = 11.3, some_attr = [10, 20, 30])
 190
 191        db.commit(clear_cache = False)
 192        
 193        self <= [peep.name for peep in (Person.age > 10) & (Person.where.random < 24.0)]
 194        self <= ['Hsing', 'Joan', 'Xsing', 'Yoan']
 195
 196        self <= [peep.name for peep in (Person.age > 10) | (Person.where.random < 24.0)]
 197        self <= ['Don', 'Fred', 'Hsing', 'Joan', 'Mred', 'Xsing', 'Yoan']
 198
 199        self <= [peep.name for peep in ((Person.age > 90) & (Person.where.random < 12.0)) | (Person.boss == boss)]
 200        self <= ['Fred', 'Hsing', 'Joan', 'Mred', 'Xsing']
 201
 202        self <= [peep.name for peep in (Person.alive == None) & (Person.where.random == 'FOO')]
 203        self <= ['Don', 'Fred']
 204        
 205        for peep in Person.name[1:4] == 'red':
 206            peep.alive = True
 207        
 208        self <= [(peep.alive, peep.name) for peep in (Person.alive == True)]
 209        self <= [(True, 'Fred'), (True, 'Mred')]
 210        
 211        self <= [(peep.alive, peep.random) for peep in (Person.alive == True) & (Person.where.random > 25)]
 212        self <= [(True, 'FOO'), (True, 30.0)]
 213
 214        self <= [(peep.alive, peep.name, peep.random) for peep in (Person.alive == True) & (Person.where.random > 25)  | (Person.where.some_attr)]
 215        self <= [(True, 'Fred', 'FOO'), (True, 'Mred', 30.0), (None, 'Yoan', 11.300000000000001)]
 216
 217        self <= [(peep.name, peep.age) for peep in Person.age == 32]
 218        self <= [('Fred', 32)]
 219
 220        self <= [peep.name for peep in Person.name[1:3] == 're']
 221        self <= ['Fred', 'Mred']
 222
 223        self <= [(peep.name, peep.age) for peep in (Person.name[-3:-1] == 're') | (Person.age == 35)]  # We made this int, so type convert
 224        self <= [('Fred', 32), ('Hsing', 35.299999999999997), ('Mred', 12)]
 225        
 226        self <= [(peep.name,len(peep.emails)) for peep in Person.emails == [email_2]]
 227        self <= [('Joan', 1), ('Yoan', 1)]
 228
 229        self <= [(peep.name, peep.age) for peep in Person.age < 25]
 230        self <= [('Joan', 22.300000000000001), ('Mred', 12), ('Xsing', 15.300000000000001), ('Yoan', 12.300000000000001)]
 231
 232        self <= [(peep.name,len(peep.emails),peep.age) for peep in (Person.emails == [email_2]) & (Person.age < 25)]
 233        self <= [('Joan', 1, 22.300000000000001), ('Yoan', 1, 12.300000000000001)]
 234        
 235        self <= [peep.name for peep in (Person.emails == [email_2]) & (Person.age < 10)]
 236        self <= []
 237        
 238        self <= Email.get_count()
 239        self <= 3
 240
 241        self <= Person.get_count()
 242        self <= 7
 243
 244        self <= Person.get_count(child_classes = False)
 245        self <= 4
 246
 247        self <= Punk.get_count(child_classes = False)
 248        self <= 3
 249
 250        self <= [email.title for email in Email.ctime.younger_than(days = 1)]
 251        self <= ['FYI', 'GO HOME', 'HI']
 252
 253        import time
 254        time.sleep(1)
 255        
 256        self <= [email.title for email in Email.ctime.older_than(seconds = 1)]
 257        self <= ['FYI', 'GO HOME', 'HI']
 258
 259        db.commit(close = True)
 260 
 261    """ QUICK EXAMPLE """     
 262    def test_quick_example_db(self):
 263        self.quick_example(clear_cache = True)
 264        
 265    def test_quick_example_cache(self):
 266        self.quick_example(clear_cache = False)
 267
 268    def quick_example(self, clear_cache):
 269        import pod
 270
 271        db = pod.Db(file = self.filename, remove = True)  # First, make a connection to the database . . . 
 272        
 273        class Person(pod.Object):  # Now, any object that descends from pod.Object will be stored to last opened database connection. 
 274             
 275            def __init__(self, name, age, best_friend = None, **kwargs):
 276                pod.Object.__init__(self, **kwargs)
 277                self.name    = name
 278                self.age     = age
 279                self.friends = set()   # An attribute can be of any type, including collections
 280                if best_friend:
 281                    self.add_friend(friend = best_friend, best = True)
 282             
 283            def add_friend(self, friend, best = False):
 284                self.friends.add(friend)
 285                friend.friends.add(self)
 286                if best:
 287                    self.best_friend   = friend  # A member can even be another pod object. 
 288                    friend.best_friend = self
 289        
 290        # Now, add a class Tycoon that descends from Person . . . 
 291        class Tycoon(Person):
 292             
 293            # Below, we add columns in order to allow faster raw SQL queries.  
 294            # You don't need to do this -- it just makes querying on that attribute faster. 
 295            # Add an SQL index for even faster querying at expense of slower insertion into db. 
 296            age          = pod.typed.Int(index = False)
 297            catch_phrase = pod.typed.String(index = True)
 298            yachts       = pod.typed.Object(index = True)
 299        
 300        # Let's add another class that descends directly from pod.Object . . .
 301        class Yacht(pod.Object):
 302            owner        = pod.typed.Object(index = True)
 303        
 304        # Now, add some Person, Tycoon, and Yacht objects to the database . . . 
 305        fred   = Person(name = 'Fred',   age = 20, some_random_attr = 'foo')
 306        frank  = Person(name = 'Frank',  age = 80, some_other_random_attr = ['bar', 'baz'])
 307        don    = Tycoon(name = 'Don',    age = 63, best_friend = fred,  catch_phrase = "You're fired!")
 308        george = Tycoon(name = 'George', age = 61, best_friend = frank, catch_phrase = "I guarantee it") 
 309        george.yachts = [Yacht(owner = george, name = 'The One That Got Away'), Yacht(owner = george, name = 'The Trickle Downer')] 
 310        
 311        # Now, commit this transaction. You can also call db.rollback() to cancel this transaction. 
 312        db.commit(clear_cache = clear_cache)  
 313        
 314        # Now, get some objects out of the db.        
 315        if clear_cache:
 316            # Since the comparison is based upon the Python "id", this should fail as the query will return new objects.
 317            self.assertNotEqual(set((fred, frank, don, george)), set(peep for peep in Person))
 318            self.assertEqual(set((o.name, o.age) for o in (fred, frank, don, george)), set((peep.name, peep.age) for peep in Person))
 319            self.assertNotEqual(set((fred, frank)), set(peep for peep in Person if peep.name[0] == 'F'))
 320            self.assertEqual(set((o.name, o.age) for o in (fred, frank)), set((peep.name, peep.age) for peep in Person if peep.name[0] == 'F'))
 321        else:
 322            # Since the comparison is based upon the Python "id", this should succeed as the query will return the same objects.
 323            self.assertEqual(set((fred, frank, don, george)), set(peep for peep in Person))
 324            self.assertEqual(set((fred, frank)), set(peep for peep in Person if peep.name[0] == 'F'))
 325        
 326        # Or, if we added a column to the class header, we can query much more efficiently using sqlite3. 
 327        for tyke in Tycoon.catch_phrase == "You're fired!": 
 328            self.assertEqual(tyke.name, 'Don')
 329            self.assertEqual(tyke.age, 63)
 330            self.assertEqual(tyke.best_friend.name, 'Fred')
 331        
 332        # You can even query on pod objects . . .
 333        for exp, yacht in zip(george.yachts, Yacht.owner == george):
 334            self.assertEqual(yacht.owner.name, exp.owner.name)
 335            self.assertEqual(yacht.name, exp.name)
 336                
 337        # Or, for full SQL control, use a query object on any defined columns: 
 338        query = pod.Query(select = Tycoon.age, 
 339                          where = (Tycoon.age < 62) | Tycoon.catch_phrase.startswith("Yo"),      
 340                          order_by = Tycoon.age.desc(), 
 341                          limit = 2)
 342        
 343        if clear_cache:
 344            query_results = [o for o in query]
 345            self.assertNotEqual([don, george], query_results)
 346            expect = [(o.name, o.age, o.catch_phrase, o.best_friend.name) for o in (don, george)]
 347            actual = [(o.name, o.age, o.catch_phrase, o.best_friend.name) for o in query_results]
 348            self.assertEqual(expect, actual)
 349        else:
 350            self.assertEqual([don, george], [o for o in query])
 351              
 352        # Just like regular Python objects, you can add attributes on the fly . . . 
 353        don.another_random_attr = ['foo', 'bar', 'baz']
 354        
 355        # Now, commit the 'another_random_attr' change . . . 
 356        db.commit(clear_cache = clear_cache)
 357        
 358        query = pod.Query(select = Tycoon.age, where = Tycoon.age == 63)
 359
 360        if clear_cache:
 361            query_results = [o for o in query]
 362            self.assertEqual(len(query_results), 1)
 363            q = query_results[0]
 364            self.assertNotEqual(don, q)
 365            expect = [don.name, don.age, don.catch_phrase, don.best_friend.name, don.another_random_attr]
 366            actual = [q.name, q.age, q.catch_phrase, q.best_friend.name, q.another_random_attr]
 367            self.assertEqual(expect, actual)
 368        else:
 369            self.assertEqual([don], [o for o in query])
 370                
 371        # Finally, all Db instances and all pod.Object classes contain a 'store' attribute which can be used exactly like a shelve.  Each 'store' is separate from all others . . .  
 372        Tycoon.store.main_tycoon  = george 
 373        
 374        db.commit(clear_cache = clear_cache)
 375        
 376        # The store is useful for storing pointers to objects you want access to later on
 377        for yacht in Yacht.owner == Tycoon.store.main_tycoon: 
 378            self.assertEqual(yacht.owner.name, 'George')
 379  
 380        db.commit(clear_cache = clear_cache, close = True)
 381
 382    """ FRONT PAGE EXAMPLE """       
 383    def test_front_page_db(self):
 384        self.front_page(clear_cache = True)
 385
 386    def test_front_page_cache(self):
 387        self.front_page(clear_cache = False)
 388
 389    def front_page(self, clear_cache):
 390        import pod
 391        import models_front
 392        db = pod.Db(file = self.filename, remove = True, attach = [models_front, pod.set])
 393        
 394        hsing  = models_front.Person(name = 'Hsing',    some_attr = 'foo')                    # Now, add some Person, Tycoon, and WorkerBee objects to 
 395        helen  = models_front.Person(name = 'Helen',    some_other_attr = ['bar', 'baz'])     # the database . . . 
 396    
 397        don    = models_front.Tycoon(name = 'Don',      age = 63, catch_phrase = "You're fired!")
 398        george = models_front.Tycoon(name = 'George',   age = 61, catch_phrase = "I guarantee it") 
 399        
 400        bruce  = models_front.WorkerBee(name = 'Bruce', age = 40, boss = don, random_attr = 10.23)
 401        azhar  = models_front.WorkerBee(name = 'Azhar', age = 40, boss = george, random_attr = {'key': ['value', (1, 2, 3)]})
 402        
 403        self.assertEqual(set([peep.name for peep in models_front.Person]),    set(['Hsing', 'Don', 'Bruce', 'Azhar', 'Helen', 'George']))
 404        self.assertEqual(set([peep.name for peep in models_front.Tycoon]),    set(['Don', 'George']))
 405        self.assertEqual(set([peep.name for peep in models_front.WorkerBee]), set(['Bruce', 'Azhar']))
 406        
 407        db.commit(clear_cache = clear_cache, close = False)  
 408        
 409        class Yacht(pod.Object):                                             
 410            name         = pod.typed.String(index = False)                      
 411            length       = pod.typed.Float(index = True)                        
 412            awards       = pod.typed.Object(index = True)                         
 413            owner        = pod.typed.Object(index = True)                       
 414                                                                              
 415            def __init__(self, owner, **kwargs):
 416                pod.Object.__init__(self, **kwargs)
 417                self.owner = owner
 418                self.owner.yachts.append(self)
 419                self.photos = []                                                 
 420             
 421        db.attach(Yacht)
 422             
 423        Yacht(owner = george, name = 'The Trickle Downer', length = 40.5)
 424        Yacht(owner = george, name = 'The TARP Runner',    length = 42.1, some_random_attr = 'foo')
 425        Yacht(owner = george, name = 'Mr. Pickles',        length = 45.1, some_random_attr = 'foo')
 426    
 427        self.assertEqual(set([yacht.owner.name for yacht in Yacht.name == 'The Trickle Downer']), set(['George', 'George']))                                                                                                       
 428
 429        self.assertEqual(set([yacht.owner.name for yacht in Yacht.owner == george]), set(['George', 'George']))                                                                                                       
 430    
 431        query = pod.Query(select = Yacht.name | Yacht.length,                    # Or, for full SQL control, use a query object on any defined 
 432                          where = (Yacht.length < 41) | (Yacht.length == 42.1),  # typed.  Conditionals are chained together with '|' or '&'. 
 433                          order_by = Yacht.length.desc(), 
 434                          limit = 2)
 435        
 436        self.assertEqual([yacht.length for yacht in query], [42.100000000000001, 40.5])
 437        
 438    
 439        db.commit(close = True)
 440
 441""" THE EXTENED TEST """            
 442class Extended(Tester):
 443  
 444    def test_mutables(self):
 445
 446        self.mutants_0()
 447        self.clear_mod_imports()
 448        self.mutants_1()
 449        self.clear_mod_imports()
 450    
 451    def mutants_0(self):
 452        
 453        import pod
 454        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
 455        
 456        class Person(pod.Object):
 457            pass
 458        
 459        class Place(pod.Object):
 460            pass
 461        
 462        peep  = Person()
 463        place = Place()
 464        
 465        peep.mutant  = [1, 2, 3]
 466        place.mutant = peep.mutant
 467        place.name   = 'Fred'
 468        
 469        peep.mutant[2] = 'HI'
 470        
 471        db.commit(close = True)
 472
 473    def mutants_1(self):
 474
 475        import pod
 476        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 477        
 478        class Person(pod.Object):
 479            pass
 480        
 481        class Place(pod.Object):
 482            pass
 483        
 484        place = (Place.where.name == 'Fred').get_one()
 485        
 486        self <= place.mutant[2]
 487        self <= 'HI'
 488        
 489        db.commit(close = True)
 490
 491    def test_features(self):
 492
 493        self.feature_is_in()
 494        self.clear_mod_imports()
 495    
 496    def feature_is_in(self):
 497        
 498        import pod
 499        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
 500        
 501        class Person(pod.Object):
 502            age = pod.typed.Int(index = True)
 503                
 504        class Punk(Person):
 505            pass
 506        
 507        class Poet(Person):
 508            pass
 509        
 510        peep  = Person(name = 'Fred', age = 20)
 511        peep  = Punk(name = 'Tony', age = 30)
 512        peep  = Poet(name = 'Erza', age = 21)
 513
 514        self <= set([peep.age for peep in Person.age.is_in([20, 30])])
 515        self <= set([20, 30])
 516        
 517        self <= set([peep.name for peep in Person.where.name.is_in(['Fred'])])
 518        self <= set(['Fred'])
 519
 520        self <= set([peep.name for peep in Person.age.is_in([20, 30]) | Person.where.name.is_in(['Fred'])])
 521        self <= set(['Tony', 'Fred'])
 522        
 523        self <= set([peep.name for peep in Person.age.is_in([20, 30]) & Person.where.name.is_in(['Fred'])])
 524        self <= set(['Fred'])
 525        
 526        db.commit(close = True)
 527
 528""" NoSave Undefined Deleted """            
 529class NoSaveUndefinedDeleted(Tester):
 530    
 531    def test_nosave_undefined_deleted(self):
 532        self.nsud_0()
 533        self.clear_mod_imports()
 534        self.nsud_undefined_error()
 535        self.clear_mod_imports()
 536        self.nsud_check_if_exists_0()
 537        self.clear_mod_imports()
 538        self.nsud_check_if_exists_1()
 539        self.clear_mod_imports()        
 540        self.nsud_undefined_no_error()
 541        self.clear_mod_imports()
 542        self.nsud_delete_attr()
 543        self.clear_mod_imports()
 544        self.nsud_deleted_attr_access()
 545        self.clear_mod_imports()
 546    
 547    def nsud_0(self):
 548
 549        import pod
 550        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
 551        
 552        class Person(pod.Object):
 553            age      = pod.typed.Int()
 554            is_alive = pod.typed.Object() 
 555            
 556        class Skater(Person):
 557            weight = pod.typed.Float()
 558
 559        class Email(pod.Object):
 560            title = pod.typed.String()
 561        
 562        class Temp(pod.NoSave):
 563            
 564            def __init__(self, doit):
 565                self.doit = doit
 566        
 567        e0 = Email(title = 'HI')
 568        e1 = Email(title = 'BYE')
 569            
 570        t0 = Temp(doit = True)
 571        t1 = Temp(doit = False)
 572            
 573        self <= t0.get_full_id()
 574        self <= "0:0"
 575            
 576        p0 = Person(age = 32, weight = 204, random = '10', is_alive = True, attr = False, t0 = t0, e0 = e0, e1 = e1, es = [e0, e1])
 577        p1 = Person(age = 16, weight = 134, random = '5',  is_alive = False, attr = None, t1 = t1, e0 = e0, p0 = p0)
 578
 579        s0 = Skater(age = 10, weight = 204, random = '10', is_alive = None, attr = True, p0 = p0, p1 = p1, e0 = e0, e1 = e1, es = [e0, e1])
 580        s1 = Skater(age = 20, weight = 134, random = '5',  is_alive = False, attr = None, p0 = p0, p1 = p1)
 581        
 582        db.commit()
 583
 584        self <= p0.t0.__class__
 585        self <= Temp
 586
 587        self <= [peep.age for peep in (Person.is_alive == True) | (Person.where.is_alive == False)]
 588        self <= [32, 16, 20]
 589
 590        self <= [peep.age for peep in (Person.where.attr == None) | (Person.where.attr == True)]
 591        self <= [16, 10, 20]
 592        
 593        db.commit(close = True)
 594  
 595    def nsud_undefined_error(self):
 596
 597        import pod
 598        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 599        
 600        class Person(pod.Object):
 601            age      = pod.typed.Int()
 602            is_alive = pod.typed.Object() 
 603            
 604        self <= len([peep for peep in Person]) 
 605        self <= 2
 606
 607        p0 = [peep for peep in Person][0]
 608        p1 = [peep for peep in Person][1]
 609
 610        self <= p1.p0
 611        self <= p0
 612
 613        self <= p0.e0.get_full_id()
 614        self <= p1.e0.get_full_id()
 615
 616        self <= p0.e0
 617        self <= p1.e0
 618     
 619        # Make sure Undefined instances are still same reference 
 620        self <= p0.es
 621        self <= [p0.e0, p0.e1]
 622                
 623        self.assertRaises(pod.core.PodObjectUndefined, getattr, p0.e0, 'title')
 624        self.assertRaises(pod.core.PodObjectUndefined, getattr, p0.e1, 'title')
 625        
 626        self <= p0.t0
 627        self <= None
 628
 629        self <= p1.t1
 630        self <= None
 631        
 632        db.commit(close = True)
 633         
 634    def nsud_undefined_no_error(self):
 635
 636        import pod
 637        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 638        
 639        class Person(pod.Object):
 640            age      = pod.typed.Int()
 641            is_alive = pod.typed.Object() 
 642            
 643        self <= len([peep for peep in Person]) 
 644        self <= 2
 645
 646        p0 = [peep for peep in Person][0]
 647        p1 = [peep for peep in Person][1]
 648
 649        self <= p1.p0
 650        self <= p0
 651
 652        self <= p0.e0.get_full_id()
 653        self <= p1.e0.get_full_id()
 654
 655        self <= p0.e0
 656        self <= p1.e0
 657     
 658        # Make sure Undefined instances are still same reference 
 659        self <= p0.es
 660        self <= [p0.e0, p0.e1]
 661                
 662                
 663        class Email(pod.Object):
 664            title = pod.typed.String()
 665        
 666        self <= p0.e0.title
 667        self <= 'HI'
 668
 669        p0.e1.title = 'ADIOS'
 670        
 671        self <= p0.e1.title
 672        self <= 'ADIOS'
 673        
 674        db.commit(close = True)
 675    
 676    def nsud_check_if_exists_0(self):
 677
 678        import pod
 679        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 680        
 681        class Person(pod.Object):
 682            age      = pod.typed.Int()
 683            is_alive = pod.typed.Object() 
 684            
 685        self <= len([peep for peep in Person]) 
 686        self <= 2
 687
 688        p0 = [peep for peep in Person][0]
 689        p1 = [peep for peep in Person][1]
 690
 691        self <= p1.p0
 692        self <= p0
 693
 694        self <= p0.e0.get_full_id()
 695        self <= p1.e0.get_full_id()
 696
 697        self <= p0.e0
 698        self <= p1.e0
 699
 700        @Tester.raises(pod.core.PodObjectUndefined)
 701        def fn():
 702            self <= p0.e0.title
 703            self <= None
 704        
 705        db.commit(close = True)
 706        
 707    def nsud_check_if_exists_1(self):
 708
 709        import pod
 710        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 711        
 712        class Person(pod.Object):
 713            age      = pod.typed.Int()
 714            is_alive = pod.typed.Object() 
 715            
 716        self <= len([peep for peep in Person]) 
 717        self <= 2
 718
 719        p0 = [peep for peep in Person][0]
 720        p1 = [peep for peep in Person][1]
 721
 722        self <= p1.p0
 723        self <= p0
 724
 725        self <= p0.e0.get_full_id()
 726        self <= p1.e0.get_full_id()
 727
 728        self <= p0.e0
 729        self <= p1.e0
 730
 731        @Tester.raises(pod.core.PodObjectUndefined)
 732        def fn():
 733            self <= getattr(p0.e0, 'no_attr', None)
 734            self <= None
 735        
 736        db.commit(close = True)
 737        
 738    def nsud_delete_attr(self):
 739
 740        import pod
 741        db = pod.Db(file = self.filename, remove = False, very_chatty = True)
 742        
 743        class Person(pod.Object):
 744            age      = pod.typed.Int()
 745            is_alive = pod.typed.Object() 
 746            
 747        class Skater(Person):
 748            weight = pod.typed.Float()
 749
 750        class Email(pod.Object):
 751            title = pod.typed.String()
 752                
 753        p0 = pod.Query(where = Person, limit = 1).get_one()
 754        
 755        self <= [p0.e0, p0.e1]
 756        self <= p0.es
 757
 758        p1 = [peep for peep in Person][1]
 759
 760        self <= p0.e0
 761        self <= p1.e0
 762                
 763        # set e0 to have a mutable . . . 
 764        p0.e0.a_list = [10, 20, 30]
 765                        
 766        for e in p0.es:
 767            e.delete()
 768        
 769        self <= [e for e in Email]
 770        self <= []
 771        
 772        self <= object.__getattribute__(p0.e0, '__class__')
 773        self <= pod.core.Deleted
 774
 775        self <= [p0.e0, p0.e1]
 776        self <= p0.es
 777                    
 778        self.assertRaises(pod.core.PodObjectDeleted, getattr, p0.e0, 'title')
 779        self.assertRaises(pod.core.PodObjectDeleted, getattr, p0.e1, 'title')
 780        
 781        @Tester.raises(pod.core.PodObjectDeleted)
 782        def fn():
 783            p0.e0.name = 'Fred'
 784                                        
 785        p1 = [peep for peep in Person][1]
 786
 787        self <= p0.e0
 788        self <= p1.e0
 789        
 790        db.commit(close = True)
 791
 792    def nsud_deleted_attr_access(self):
 793
 794        import pod
 795        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 796        
 797        class Person(pod.Object):
 798            age      = pod.typed.Int()
 799            is_alive = pod.typed.Object() 
 800            
 801        class Skater(Person):
 802            weight = pod.typed.Float()
 803
 804        class Email(pod.Object):
 805            title = pod.typed.String()
 806        
 807        p0 = pod.Query(where = Person, limit = 1).get_one()
 808
 809        self <= object.__getattribute__(p0.e0, '__class__')
 810        self <= Email
 811        
 812        @Tester.raises(pod.core.PodObjectDeleted)
 813        def fn():   
 814            p0.e0.title                                 # This function call a typed attribute, so throws error in load_attr_from_db
 815
 816        @Tester.raises(pod.core.PodObjectDeleted)
 817        def fn():   
 818            getattr(p0.e1, 'some_random_attr', None)    # This function calls a dynamic attribute, so throws error in inst_check_if_exists
 819                            
 820       
 821        self <= object.__getattribute__(p0.e0, '__class__')
 822        self <= Email
 823        self <= object.__getattribute__(p0.e1, '__class__')
 824        self <= Email
 825        
 826        self <= p0.es
 827        self <= [None, None]
 828                   
 829        @Tester.raises(pod.core.PodObjectDeleted)
 830        def fn():
 831            p0.e0.title
 832
 833        @Tester.raises(pod.core.PodObjectDeleted)
 834        def fn():
 835            p0.e0['title']
 836
 837        @Tester.raises(pod.core.PodObjectDeleted)
 838        def fn():
 839            p0.e0.full_load()
 840                                               
 841        db.commit(close = True)
 842
 843""" RAW COLLECTIONS """    
 844class Collections(Tester): 
 845           
 846    def test_collections(self):
 847        # list
 848        self.col_list_section_0()
 849        self.clear_mod_imports()
 850        self.col_list_section_1()
 851        self.clear_mod_imports()
 852        self.col_list_section_2()
 853        self.clear_mod_imports()
 854        self.col_list_section_3()
 855        self.clear_mod_imports()
 856        
 857        # dict
 858        self.col_dict_section()
 859        self.clear_mod_imports()
 860        
 861        # set
 862        self.col_set_section()
 863        self.clear_mod_imports()
 864        self.col_all_section()
 865        
 866    def col_list_section_0(self):
 867        import pod
 868        import pod.list
 869        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
 870                
 871        self <= [i for i in pod.list.List]
 872        self <= []
 873        
 874        a_list = pod.list.List()        
 875        self.assertRaises(IndexError, a_list.__getitem__, 0)
 876        
 877        class Person(pod.Object):
 878            pass
 879        
 880        peep = Person()
 881        
 882        b_list = pod.list.List([1, 2, 'k', {'peep': peep}, peep])
 883        
 884        self <= [i for i in b_list]
 885        self <= [1, 2, 'k', {'peep': peep}, peep]
 886        
 887        c_list = pod.list.List([0, 1, 2, 3, 4, 5, 6])
 888        c_list.append(7)
 889        c_list.extend([8, 9])
 890        
 891        self <= [i for i in c_list]
 892        self <= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 893
 894        self <= (2 in c_list)
 895        self <= True
 896        
 897        self <= ('2' in c_list)
 898        self <= False
 899
 900        c_list.remove(4)
 901        self <= [i for i in c_list]
 902        self <= [0, 1, 2, 3, 5, 6, 7, 8, 9]
 903
 904        c_list.insert(4, 4)
 905        self <= [i for i in c_list]
 906        self <= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 907        
 908        c_list.reverse()
 909        self <= [i for i in c_list]
 910        self <= [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
 911
 912        c_list.reverse()
 913        self <= [i for i in c_list]
 914        self <= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 915        
 916        self <= c_list[4]
 917        self <= 4
 918
 919        self <= c_list[-2]
 920        self <= 8
 921
 922        self <= c_list[3:]
 923        self <= [3, 4, 5, 6, 7, 8, 9]
 924
 925        self <= c_list[3::2]
 926        self <= [3, 5, 7, 9]
 927        
 928        self <= c_list[3:8:3]
 929        self <= [3, 6]
 930        
 931        self <= c_list[-3:-8:-1]
 932        self <= [7, 6, 5, 4, 3]
 933        
 934        self <= c_list[-3:-8:-2]
 935        self <= [7, 5, 3]
 936        
 937        self <= len(c_list)
 938        self <= 10
 939
 940        c_list.clear()
 941        self <= [i for i in c_list]
 942        self <= []
 943        
 944        db.commit(close = True)
 945        
 946    def col_list_section_1(self):
 947        import pod
 948        import pod.list
 949        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 950        
 951        a_list = pod.list.List(name = 'A_LIST')        
 952        self.assertRaises(IndexError, a_list.__getitem__, 0)
 953        
 954        class Person(pod.Object):
 955            pass
 956        
 957        peep = Person()
 958        
 959        a_list.append(peep)
 960        a_list.append(peep)
 961        
 962        self <= a_list.copy()
 963        self <= [peep, peep]
 964        
 965        a_list.remove(peep)       
 966        self <= a_list.copy()
 967        self <= [peep]
 968
 969        self <= a_list.pop()
 970        self <= peep
 971
 972        self <= a_list.copy()
 973        self <= []
 974        
 975        a_list.append('you_know_it')
 976        a_list.append({10: 20})
 977        a_list.append(10)
 978
 979        db.commit(close = True)
 980    
 981    def col_list_section_2(self):
 982        
 983        import pod
 984        import pod.list
 985        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
 986        
 987        e_list = pod.list.List()    
 988        
 989        self <= len(e_list)
 990        self <= 0
 991        
 992        e_list.append(10)
 993        e_list.append(20)
 994        e_list.append(e_list)
 995
 996        self <= e_list[5:4]
 997        self <= []
 998        
 999        @Tester.raises(pod.list.PodListError)
1000        def fn():
1001            e_list[[10]]
1002            
1003        e_list[0] = 20
1004        e_list[1] = 10
1005        
1006        self <= [e for e in e_list]
1007        self <= [20, 10, e_list]
1008        
1009        some_list = [1, 2, 3]
1010        some_list[0:2] = [30,40]
1011        
1012        self <= some_list
1013        self <= [30, 40, 3]
1014        
1015        e_list[0:2] = [30, 40]
1016        
1017        self <= [e for e in e_list]
1018        self <= [30, 40, e_list]
1019
1020        del e_list[0]
1021        del e_list[0:2]
1022
1023        self <= [e for e in e_list]
1024        self <= []
1025            
1026        self <= e
1027        self <= e_list
1028            
1029        e_list.append(10)
1030        e_list[0] = 'hi'
1031        
1032        self <= e_list.copy()
1033        self <= ['hi']
1034        
1035        @Tester.raises(pod.list.PodListError)
1036        def fn():
1037            e.remove('10')
1038        
1039        e.remove('hi')
1040        
1041        self <= e.copy()
1042        self <= []
1043
1044        e.append(10)
1045        e.append(20)
1046        e.append(10)
1047        e.append(e_list)
1048        
1049        self <= e.count(10)
1050        self <= 2
1051
1052        self <= e.count(20)
1053        self <= 1
1054
1055        self <= e.count(e_list)        
1056        self <= 1
1057        
1058        self <= e.count(30)
1059        self <= 0
1060        
1061        e.remove(e_list)
1062        e.sort()
1063        
1064        self <= e.copy()
1065        self <= [10, 10, 20]
1066        
1067        self <= e.index(10)
1068        self <= 0
1069        
1070        self <= e.index(20)
1071        self <= 2
1072        
1073        
1074        @Tester.raises(pod.list.PodListError)
1075        def fn():
1076            e.index(50)
1077        
1078        # NOW DELETE
1079        e_list.delete()
1080        
1081        @Tester.raises(pod.core.PodObjectDeleted)
1082        def fn():
1083            for e in e_list.__iter__():
1084                print e
1085
1086        db.commit(close = True)
1087
1088    def col_list_section_3(self):
1089        import pod
1090        import pod.list
1091
1092        db = pod.Db(file = self.filename, remove = False, very_chatty = False)
1093        
1094        a_list = (pod.list.List.where.name == 'A_LIST').get_one()     
1095        
1096        self <= a_list.copy()
1097        self <= ['you_know_it', {10: 20}, 10]
1098
1099        db.commit(close = True)
1100
1101    def col_dict_section(self):
1102        import pod
1103        import pod.dict
1104        db = pod.Db(file = self.filename, remove = False)
1105        
1106        a_dict = pod.dict.Dict(dict = {10: 20}, name = 'A_DICT')
1107        b_dict = pod.dict.Dict(dict = {20: 20}, name = 'B_DICT')
1108        
1109        self.assertRaises(KeyError, a_dict.__getitem__, 'no_key')
1110        
1111        a_dict['some_key'] = [10, 20, 30]
1112
1113        self <= a_dict.copy()
1114        self <= {10: 20, 'some_key': [10, 20, 30]}
1115        
1116        a_dict[10] = '10'
1117        
1118        self <= a_dict.keys()
1119        self <= [10, 'some_key']
1120        
1121        a_dict.update({'10': 10})
1122
1123        self <= a_dict.items()
1124        self <= [(10, '10'), ('some_key', [10, 20, 30]), ('10', 10)]
1125
1126        self <= a_dict.values()
1127        self <= ['10', [10, 20, 30], 10]
1128        
1129        a_dict.clear()
1130        self <= a_dict.copy()
1131        self <= {}
1132        
1133        a_dict['foo'] = 'bar'
1134        self <= a_dict.copy()
1135        self <= {'foo': 'bar'}
1136
1137        self <= len(a_dict)
1138        self <= 1
1139        
1140        self <= ('foo' in a_dict)
1141        self <= True
1142        
1143        self <= ('you' in a_dict)
1144        self <= False
1145        
1146        a_dict['me'] = a_dict
1147        a_dict['b']  = 3
1148        
1149        self <= set([key for key in a_dict])
1150        self <= set(['me', 'foo', 'b'])
1151        
1152        self <= set([key for key in a_dict.iterkeys()])
1153        self <= set(['me', 'foo', 'b'])
1154        
1155        self <= a_dict.get('foo', 10)
1156        self <= 'bar'
1157        
1158        self <= a_dict.get('you')
1159        self <= None
1160
1161        self <= a_dict.get('moo', a_dict)
1162        self <= a_dict
1163        
1164        del a_dict['me']
1165        
1166        self <= set([key for key in a_dict.itervalues()])
1167        self <= set([3, 'bar'])
1168        
1169        a_dict.setdefault('foo', 20)
1170
1171        self <= set([key for key in a_dict.itervalues()])
1172        self <= set([3, 'bar'])
1173                
1174        a_dict.setdefault('moo', 30)
1175        
1176        self <= set([key for key in a_dict.itervalues()])
1177        self <= set([3, 'bar', 30])
1178        
1179        del a_dict['moo']
1180        del a_dict['b']
1181        
1182        @Tester.raises(KeyError)
1183        def fn():
1184            del a_dict['asdf']
1185        @Tester.raises(pod.dict.PodDictError)
1186        def fn():
1187            a_dict.fromkeys()
1188        @Tester.raises(pod.dict.PodDictError)
1189        def fn():
1190            a_dict.has_key()
1191        @Tester.raises(pod.dict.PodDictError)
1192        def fn():
1193            a_dict.pop('key')
1194        @Tester.raises(pod.dict.PodDictError)
1195        def fn():
1196            a_dict.popitem()
1197
1198        db.commit(close = True)
1199
1200    def col_set_section(self):
1201        import pod
1202        import pod.set
1203        db = pod.Db(file = self.filename, remove = False)
1204        
1205        a_set = pod.set.Set(set = [1, 2, 3], name = 'A_SET')
1206        b_set = pod.set.Set(set = [123, 342, 234])
1207
1208        self  <=  a_set.copy()
1209        self  <=  set([1, 2, 3])
1210
1211        self  <=  [i for i in a_set]
1212        self  <=  [1, 2, 3]
1213        
1214        a_set.add(2)
1215        
1216        self  <=  [i for i in a_set]
1217        self  <=  [1, 2, 3]
1218
1219        a_set.remove(2)
1220        
1221        self  <=  [i for i in a_set]
1222        self  <=  [1, 3]
1223                
1224        class Person(pod.Object):
1225            pass
1226        
1227        peep_0 = Person()
1228        peep_1 = Person()
1229        
1230        a_set.add(peep_0)
1231        a_set.add(peep_1)
1232        a_set.add(peep_0)
1233        a_set.add(peep_1)
1234        a_set.add(peep_0)
1235        a_set.add(peep_1)
1236        
1237        self  <=  [i for i in a_set]
1238        self  <=  [1, 3, peep_0, peep_1]
1239        
1240        a_set.remove(peep_0)
1241
1242        self  <=  [i for i in a_set]
1243        self  <=  [1, 3, peep_1]
1244
1245        a_set.add(peep_0)
1246
1247        self  <=  [i for i in a_set]
1248        self  <=  [1, 3, peep_1, peep_0]
1249
1250        self  <=  a_set | (10, peep_0)
1251        self  <=  set([peep_0, 1, 10, 3, peep_1])
1252
1253        self  <=  a_set & (3, 10, peep_1)
1254        self  <=  set([3, peep_1])
1255        
1256        self.assertRaises(KeyError, a_set.remove, 20)
1257        a_set.discard(20)
1258        a_set.discard(peep_1)
1259
1260        self  <=  [i for i in a_set]
1261        self  <=  [1, 3, peep_0]
1262        
1263        a_set.remove(peep_0)
1264
1265        self  <=  [i for i in a_set]
1266        self  <=  [1, 3]
1267        
1268        self  <=  a_set.copy()
1269        self  <=  set([1, 3])
1270        
1271        
1272        c_set = pod.set.Set()
1273
1274        self <= len(c_set)
1275        self <= 0
1276
1277        c_set.add(0)
1278        c_set.add(1)
1279        c_set.add(1)
1280        c_set.add(c_set)
1281        c_set.add(self)
1282
1283        d_set = pod.set.Set()
1284
1285        self <= len(d_set)
1286        self <= 0
1287
1288        d_set.add(0)
1289        d_set.add(1)
1290        d_set.add(1)
1291        d_set.add(c_set)
1292        d_set.add(self)
1293
1294        # now play with c_set again
1295        
1296        self <= (self in c_set)
1297        self <= True
1298        
1299        self <= ('k' in c_set)
1300        self <= False
1301
1302        c_set.remove(self)
1303        c_set.remove(c_set)
1304                
1305        self <= (self in c_set)
1306        self <= False
1307        
1308        self <= (c_set in c_set)
1309        self <= False
1310        
1311        self <= set([c_set.pop(), c_set.pop()])
1312        self <= set([0, 1])
1313
1314        self <= c_set.copy()
1315        self <= set([])
1316        
1317        
1318        @Tester.raises(KeyError)
1319        def fn():
1320            c_set.pop()
1321
1322        c_set.add(10)
1323        c_set.add(10)
1324        c_set.add(self)
1325        c_set.add(c_set)
1326
1327        c_set.clear()
1328        
1329        self <= c_set.copy()
1330        self <= set()
1331        
1332        e_set = pod.set.Set([1, 2, 3])
1333        x_set = pod.set.Set([1, 2, 3, 4, 5])
1334
1335        self <= (e_set <= x_set)
1336        self <= True
1337
1338        self <= (e_set <= x_set.copy())
1339        self <= True
1340
1341        self <= (e_set < x_set)
1342        self <= True
1343
1344        self <= (e_set < x_set.copy())
1345        self <= True
1346
1347        self <= (e_set < e_set)
1348        self <= False
1349
1350        self <= (e_set < e_set.copy())
1351        self <= False
1352        
1353        """ > """
1354        self <= (e_set > x_set)
1355        self <= False
1356        
1357        self <= (e_set > x_set.copy())
1358        self <= False
1359
1360        self <= (e_set >= x_set)
1361        self <= False
1362        
1363        self <= (e_set >= x_set.copy())
1364        self <= False
1365        
1366        self <= (x_set > e_set)
1367        self <= True
1368        
1369        self <= (x_set > e_set.copy())
1370        self <= True
1371
1372        self <= (x_set >= e_set)
1373        self <= True
1374        
1375        self <= (x_set >= e_set.copy())
1376        self <= True
1377
1378        self <= (x_set >= x_set)
1379        self <= True
1380
1381        self <= (x_set >= x_set.copy())
1382        self <= True
1383
1384        self <= (x_set > x_set)
1385        self <= False
1386
1387        self <= (x_set > x_set.copy())
1388        self <= False 
1389        
1390        """ MINUS """        
1391        self <= (x_set - e_set)
1392        self <= set([4, 5])
1393
1394        self <= (e_set - x_set)
1395        self <= set([])
1396        
1397        """ XOR """
1398        self <= (e_set ^ x_set)
1399        self <= set([4, 5])
1400
1401        self <= (x_set ^ e_set)
1402        self <= set([4, 5])
1403
1404        """ AND OR """
1405        self <= (e_set & x_set)
1406        self <= set([1, 2, 3])
1407        
1408        self <= (e_set & x_set.copy())
1409        self <= set([1, 2, 3])
1410        
1411        self <= (e_set | x_set)
1412        self <= set([1, 2, 3, 4, 5])
1413        
1414        self <= (e_set | x_set.copy())
1415        self <= set([1, 2, 3, 4, 5])
1416
1417        @Tester.raises(pod.set.PodSetError)
1418        def fn():
1419            c_set.isdisjoint(set())
1420
1421        @Tester.raises(pod.set.PodSetError)
1422        def fn():
1423            c_set.intersection_update(set())
1424
1425        @Tester.raises(pod.set.PodSetError)
1426        def fn():
1427            c_set.difference_update(set())
1428        
1429        @Tester.raises(pod.set.PodSetError)
1430        def fn():
1431            c_set.symmetric_difference_update(set())
1432        
1433        db.commit(close = True)
1434
1435        
1436
1437    def col_all_section(self):
1438        import pod
1439        import pod.dict
1440        db = pod.Db(file = self.filename, remove = False)
1441
1442        a_dict = (pod.dict.Dict.where.name == 'A_DICT').get_one()     
1443        
1444        self <= a_dict.values()
1445        self <= ['bar']
1446        
1447        a_dict['baz'] = [10, 20, {'10': '20'}]
1448
1449        self <= a_dict.copy()
1450        self <= {'foo': 'bar', 'baz': [10, 20, {'10': '20'}]}
1451        
1452        db.commit(clear_cache = True)
1453
1454        a_dict = (pod.dict.Dict.where.name == 'A_DICT').get_one()     
1455
1456        self <= a_dict.copy()
1457        self <= {'foo': 'bar', 'baz': [10, 20, {'10': '20'}]}
1458        
1459        temp = a_dict['baz'][2]
1460        self <= temp
1461        self <= {'10': '20'}
1462        
1463        temp['10'] = '10'
1464        self <= temp
1465        self <= {'10': '10'}
1466
1467        self <= a_dict.copy()
1468        self <= {'foo': 'bar', 'baz': [10, 20, {'10': '10'}]}
1469        
1470        temp['10'] = 'FOOBARBAZ'
1471
1472        self <= a_dict.copy()
1473        self <= {'foo': 'bar', 'baz': [10, 20, {'10': 'FOOBARBAZ'}]}
1474
1475        self <= a_dict['baz'][2]
1476        self <= {'10': 'FOOBARBAZ'}
1477
1478        db.commit(clear_cache = True)
1479
1480        a_dict = (pod.dict.Dict.where.name == 'A_DICT').get_one()  
1481        
1482        self <= a_dict.copy()
1483        self <= {'foo': 'bar', 'baz': [10, 20, {'10': 'FOOBARBAZ'}]}
1484
1485        db.commit(close = True)
1486
1487""" TIME MODULES """
1488class Timers(Tester):
1489
1490    def test_time_types(self):
1491        Timer = self.time_create_section(remove = True)
1492        self.time_section_0(Timer)
1493        self.clear_mod_imports()
1494        Timer = self.time_create_section(remove = False)
1495        self.time_section_1(Timer)
1496
1497    def time_create_section(self, remove):
1498 
1499        import pod
1500        import time    # You don't need to import time -- we're just going to use it below for our examples . . . 
1501        
1502        db = pod.Db(file = self.filename, remove = remove)
1503        
1504        class Timer(pod.Object):
1505            
1506            sometime  = pod.typed.Time(date_string = '%Y-%m-%d')
1507            uponatime = pod.typed.Time()
1508            utctime   = pod.typed.Time(local_time = False)
1509            ctime     = pod.typed.TimeCreate()
1510            mtime     = pod.typed.TimeLoad(date_string = '%Y-%m-%d %H:%M:%S')
1511            
1512        t0 = Timer(sometime = '2007-1-15')
1513        t1 = Timer(sometime = '2003-2-25')
1514        t2 = Timer(sometime = '2009-4-27')
1515        t3 = Timer(sometime = '2009-1-11')
1516        
1517        # For the uponatime field, you have to provide a valid UTC time stamp since you didn't set a date_string in the constructor
1518        t0.uponatime = Timer.uponatime.convert_time_to_utc_stamp(value = 2348923, local_time = True)
1519        t1.uponatime = Timer.uponatime.convert_time_to_utc_stamp(value = 324234, local_time = False)
1520        t2.uponatime = Timer.uponatime.convert_time_to_utc_stamp(value = '01/05/2006', date_string = '%d/%m/%Y', local_time = True)
1521        t3.uponatime = Timer.uponatime.convert_time_to_utc_stamp(value = '02/04/2006 12:00:00', date_string = '%d/%m/%Y %H:%M:%S', local_time = True)
1522        
1523        db.commit(clear_cache = True)
1524        
1525        return Timer
1526    
1527    def time_section_0(self, Timer):
1528        
1529        self.assertEqual(Timer.get_count(), 4)
1530        
1531        self.assertEqual(set([t.sometime for t in Timer.sometime.is_date(year = 2009)]), set(['2009-04-27','2009-01-11']))
1532            
1533        self.assertEqual(Timer.sometime.is_date(year = 2009, month = 4).get_one().sometime, '2009-04-27')
1534                
1535        set_one = set([t.sometime for t in Timer.sometime.post_dates(year = 2006) & Timer.sometime.pre_dates(year = 2008)])
1536        set_two = set(['2007-01-15'])
1537
1538        self.assertEquals(set_one, set_two)
1539    
1540        Timer.get_db().commit(close = True)
1541
1542    def time_section_1(self, Timer):
1543        self.assertEqual(Timer.get_count(), 8)
1544        
1545        self.assertEqual(set([t.sometime for t in Timer.sometime.is_date(year = 2009)]), set(['2009-04-27','2009-01-11']))
1546            
1547        self.assertEqual([t.sometime for t in Timer.sometime.is_date(year = 2009, month = 4)], ['2009-04-27', '2009-04-27'])
1548                
1549        list_one = [t.sometime for t in Timer.sometime.post_dates(year = 2006) & Timer.sometime.pre_dates(year = 2008)]
1550        list_two = ['2007-01-15','2007-01-15']
1551
1552        self.assertEquals(list_one, list_two)
1553    
1554        Timer.get_db().commit(close = True)
1555
1556""" RAW QUERIES """
1557class Raw(Tester):         
1558    
1559    def test_raw_query(self):
1560        
1561        import pod
1562
1563        db = pod.Db(file = self.filename, remove = True, very_chatty = False)
1564        
1565        class Person(pod.Object):
1566           name = pod.typed.String()
1567           age  = pod.typed.Int()
1568                
1569        p0 = Person(name = 'Ali', age = 20)
1570        p1 = Person(name = 'Jin', age = 25)
1571        p2 = Person(name = 'Eli', age = 50)
1572        
1573        db.commit()
1574        
1575        self.assertEquals((2*Person.age+1 > 100).get_one().name, 'Eli')
1576        
1577        if pod.db.PY_VERSION_IS_25 is False:
1578            self.assertEquals((pod.fn.replace(Person.name, 'in', 'oe') == 'Joe').get_one().name, 'Jin')
1579            self.assertEquals(set([p.name for p in pod.fn.replace(Person.name, 'li', 'mi').endswith('i')]), set(['Ali', 'Eli']))
1580   

Large files files are truncated, but you can click here to view the full file