diff options
Diffstat (limited to 'libbe/storage/util/properties.py')
-rw-r--r-- | libbe/storage/util/properties.py | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/libbe/storage/util/properties.py b/libbe/storage/util/properties.py index 77c0162..4aa3ce6 100644 --- a/libbe/storage/util/properties.py +++ b/libbe/storage/util/properties.py @@ -415,7 +415,7 @@ if libbe.TESTING == True: @doc_property("A fancy property") def x(): return {} - self.failUnless(Test.x.__doc__ == "A fancy property", + self.assertTrue(Test.x.__doc__ == "A fancy property", Test.x.__doc__) def testLocalProperty(self): class Test(object): @@ -424,11 +424,11 @@ if libbe.TESTING == True: def x(): return {} t = Test() - self.failUnless(t.x == None, str(t.x)) + self.assertTrue(t.x == None, str(t.x)) t.x = 'z' # the first set initializes ._LOCAL_value - self.failUnless(t.x == 'z', str(t.x)) - self.failUnless("_LOCAL_value" in dir(t), dir(t)) - self.failUnless(t._LOCAL_value == 'z', t._LOCAL_value) + self.assertTrue(t.x == 'z', str(t.x)) + self.assertTrue("_LOCAL_value" in dir(t), dir(t)) + self.assertTrue(t._LOCAL_value == 'z', t._LOCAL_value) def testSettingsProperty(self): class Test(object): @Property @@ -438,11 +438,11 @@ if libbe.TESTING == True: def __init__(self): self.settings = {} t = Test() - self.failUnless(t.x == None, str(t.x)) + self.assertTrue(t.x == None, str(t.x)) t.x = 'z' # the first set initializes ._LOCAL_value - self.failUnless(t.x == 'z', str(t.x)) - self.failUnless("attr" in t.settings, t.settings) - self.failUnless(t.settings["attr"] == 'z', t.settings["attr"]) + self.assertTrue(t.x == 'z', str(t.x)) + self.assertTrue("attr" in t.settings, t.settings) + self.assertTrue(t.settings["attr"] == 'z', t.settings["attr"]) def testDefaultingLocalProperty(self): class Test(object): @Property @@ -450,15 +450,15 @@ if libbe.TESTING == True: @local_property(name="DEFAULT", null=5) def x(): return {} t = Test() - self.failUnless(t.x == 5, str(t.x)) + self.assertTrue(t.x == 5, str(t.x)) t.x = 'x' - self.failUnless(t.x == 'y', str(t.x)) + self.assertTrue(t.x == 'y', str(t.x)) t.x = 'y' - self.failUnless(t.x == 'y', str(t.x)) + self.assertTrue(t.x == 'y', str(t.x)) t.x = 'z' - self.failUnless(t.x == 'z', str(t.x)) + self.assertTrue(t.x == 'z', str(t.x)) t.x = 5 - self.failUnless(t.x == 5, str(t.x)) + self.assertTrue(t.x == 5, str(t.x)) def testCheckedLocalProperty(self): class Test(object): @Property @@ -468,13 +468,13 @@ if libbe.TESTING == True: def __init__(self): self._CHECKED_value = 'x' t = Test() - self.failUnless(t.x == 'x', str(t.x)) + self.assertTrue(t.x == 'x', str(t.x)) try: t.x = None e = None - except ValueCheckError, e: + except ValueCheckError as e: pass - self.failUnless(type(e) == ValueCheckError, type(e)) + self.assertTrue(type(e) == ValueCheckError, type(e)) def testTwoCheckedLocalProperties(self): class Test(object): @Property @@ -493,18 +493,18 @@ if libbe.TESTING == True: try: t.x = 'a' e = None - except ValueCheckError, e: + except ValueCheckError as e: pass - self.failUnless(type(e) == ValueCheckError, type(e)) + self.assertTrue(type(e) == ValueCheckError, type(e)) t.x = 'x' t.x = 'y' t.x = 'z' try: t.a = 'x' e = None - except ValueCheckError, e: + except ValueCheckError as e: pass - self.failUnless(type(e) == ValueCheckError, type(e)) + self.assertTrue(type(e) == ValueCheckError, type(e)) t.a = 'a' t.a = 'b' t.a = 'c' @@ -517,13 +517,13 @@ if libbe.TESTING == True: def __init__(self): self._CHECKED_value = 'x' t = Test() - self.failUnless(t.x == 'x', str(t.x)) + self.assertTrue(t.x == 'x', str(t.x)) try: t.x = None e = None - except ValueCheckError, e: + except ValueCheckError as e: pass - self.failUnless(type(e) == ValueCheckError, type(e)) + self.assertTrue(type(e) == ValueCheckError, type(e)) def testCachedLocalProperty(self): class Gen(object): def __init__(self): @@ -537,30 +537,30 @@ if libbe.TESTING == True: @local_property(name="CACHED") def x(): return {} t = Test() - self.failIf("_CACHED_cache" in dir(t), + self.assertFalse("_CACHED_cache" in dir(t), getattr(t, "_CACHED_cache", None)) - self.failUnless(t.x == 1, t.x) - self.failUnless(t.x == 1, t.x) - self.failUnless(t.x == 1, t.x) + self.assertTrue(t.x == 1, t.x) + self.assertTrue(t.x == 1, t.x) + self.assertTrue(t.x == 1, t.x) t.x = 8 - self.failUnless(t.x == 8, t.x) - self.failUnless(t.x == 8, t.x) + self.assertTrue(t.x == 8, t.x) + self.assertTrue(t.x == 8, t.x) t._CACHED_cache = False # Caching is off, but the stored value val = t.x # is 8, not the initVal (None), so we - self.failUnless(val == 8, val) # get 8. + self.assertTrue(val == 8, val) # get 8. t._CACHED_value = None # Now we've set the stored value to None val = t.x # so future calls to fget (like this) - self.failUnless(val == 2, val) # will call the generator every time... + self.assertTrue(val == 2, val) # will call the generator every time... val = t.x - self.failUnless(val == 3, val) + self.assertTrue(val == 3, val) val = t.x - self.failUnless(val == 4, val) + self.assertTrue(val == 4, val) t._CACHED_cache = True # We turn caching back on, and get - self.failUnless(t.x == 1, str(t.x)) # the original cached value. + self.assertTrue(t.x == 1, str(t.x)) # the original cached value. del t._CACHED_cached_value # Removing that value forces a - self.failUnless(t.x == 5, str(t.x)) # single cache-regenerating call - self.failUnless(t.x == 5, str(t.x)) # to the genenerator, after which - self.failUnless(t.x == 5, str(t.x)) # we get the new cached value. + self.assertTrue(t.x == 5, str(t.x)) # single cache-regenerating call + self.assertTrue(t.x == 5, str(t.x)) # to the genenerator, after which + self.assertTrue(t.x == 5, str(t.x)) # we get the new cached value. def testPrimedLocalProperty(self): class Test(object): def prime(self): @@ -573,23 +573,23 @@ if libbe.TESTING == True: self.settings={} self.primeVal = "initialized" t = Test() - self.failIf("_PRIMED_prime" in dir(t), + self.assertFalse("_PRIMED_prime" in dir(t), getattr(t, "_PRIMED_prime", None)) - self.failUnless(t.x == "initialized", t.x) + self.assertTrue(t.x == "initialized", t.x) t.x = 1 - self.failUnless(t.x == 1, t.x) + self.assertTrue(t.x == 1, t.x) t.x = None - self.failUnless(t.x == "initialized", t.x) + self.assertTrue(t.x == "initialized", t.x) t._PRIMED_prime = True t.x = 3 - self.failUnless(t.x == "initialized", t.x) + self.assertTrue(t.x == "initialized", t.x) t._PRIMED_prime = False t.x = 3 - self.failUnless(t.x == 3, t.x) + self.assertTrue(t.x == 3, t.x) # test unprimableVal t.x = None t.primeVal = None - self.failUnless(t.x == 2, t.x) + self.assertTrue(t.x == 2, t.x) def testChangeHookLocalProperty(self): class Test(object): def _hook(self, old, new): @@ -602,14 +602,14 @@ if libbe.TESTING == True: def x(): return {} t = Test() t.x = 1 - self.failUnless(t.old == None, t.old) - self.failUnless(t.new == 1, t.new) + self.assertTrue(t.old == None, t.old) + self.assertTrue(t.new == 1, t.new) t.x = 1 - self.failUnless(t.old == None, t.old) - self.failUnless(t.new == 1, t.new) + self.assertTrue(t.old == None, t.old) + self.assertTrue(t.new == 1, t.new) t.x = 2 - self.failUnless(t.old == 1, t.old) - self.failUnless(t.new == 2, t.new) + self.assertTrue(t.old == 1, t.old) + self.assertTrue(t.new == 2, t.new) def testChangeHookMutableProperty(self): class Test(object): def _hook(self, old, new): @@ -624,45 +624,45 @@ if libbe.TESTING == True: t = Test() t.hook_calls = 0 t.x = [] - self.failUnless(t.old == None, t.old) - self.failUnless(t.new == [], t.new) - self.failUnless(t.hook_calls == 1, t.hook_calls) + self.assertTrue(t.old == None, t.old) + self.assertTrue(t.new == [], t.new) + self.assertTrue(t.hook_calls == 1, t.hook_calls) a = t.x a.append(5) t.x = a - self.failUnless(t.old == [], t.old) - self.failUnless(t.new == [5], t.new) - self.failUnless(t.hook_calls == 2, t.hook_calls) + self.assertTrue(t.old == [], t.old) + self.assertTrue(t.new == [5], t.new) + self.assertTrue(t.hook_calls == 2, t.hook_calls) t.x = [] - self.failUnless(t.old == [5], t.old) - self.failUnless(t.new == [], t.new) - self.failUnless(t.hook_calls == 3, t.hook_calls) + self.assertTrue(t.old == [5], t.old) + self.assertTrue(t.new == [], t.new) + self.assertTrue(t.hook_calls == 3, t.hook_calls) # now append without reassigning. this doesn't trigger the # change, since we don't ever set t.x, only get it and mess # with it. It does, however, update our t.new, since t.new = # t.x and is not a static copy. t.x.append(5) - self.failUnless(t.old == [5], t.old) - self.failUnless(t.new == [5], t.new) - self.failUnless(t.hook_calls == 3, t.hook_calls) + self.assertTrue(t.old == [5], t.old) + self.assertTrue(t.new == [5], t.new) + self.assertTrue(t.hook_calls == 3, t.hook_calls) # however, the next t.x get _will_ notice the change... a = t.x - self.failUnless(t.old == [], t.old) - self.failUnless(t.new == [5], t.new) - self.failUnless(t.hook_calls == 4, t.hook_calls) + self.assertTrue(t.old == [], t.old) + self.assertTrue(t.new == [5], t.new) + self.assertTrue(t.hook_calls == 4, t.hook_calls) t.x.append(6) # this append(6) is not noticed yet - self.failUnless(t.old == [], t.old) - self.failUnless(t.new == [5,6], t.new) - self.failUnless(t.hook_calls == 4, t.hook_calls) + self.assertTrue(t.old == [], t.old) + self.assertTrue(t.new == [5,6], t.new) + self.assertTrue(t.hook_calls == 4, t.hook_calls) # this append(7) is not noticed, but the t.x get causes the # append(6) to be noticed t.x.append(7) - self.failUnless(t.old == [5], t.old) - self.failUnless(t.new == [5,6,7], t.new) - self.failUnless(t.hook_calls == 5, t.hook_calls) + self.assertTrue(t.old == [5], t.old) + self.assertTrue(t.new == [5,6,7], t.new) + self.assertTrue(t.hook_calls == 5, t.hook_calls) a = t.x # now the append(7) is noticed - self.failUnless(t.old == [5,6], t.old) - self.failUnless(t.new == [5,6,7], t.new) - self.failUnless(t.hook_calls == 6, t.hook_calls) + self.assertTrue(t.old == [5,6], t.old) + self.assertTrue(t.new == [5,6,7], t.new) + self.assertTrue(t.hook_calls == 6, t.hook_calls) suite = unittest.TestLoader().loadTestsFromTestCase(DecoratorTests) |