예제 #1
0
    def test___int__(self):
        c = KeyCache('KeyCache.__int__')
        self.assertEqual(0, int(c))
        self.assertEqual(None, c.data)

        c.data = 5
        c = KeyCache('KeyCache.__int__')
        self.assertEqual(5, int(c))
예제 #2
0
    def test___int__(self):
        c = KeyCache('KeyCache.__int__')
        self.assertEqual(0, int(c))
        self.assertEqual(None, c.data)

        c.data = 5
        c = KeyCache('KeyCache.__int__')
        self.assertEqual(5, int(c))
예제 #3
0
    def test___nonzero__(self):
        c = KeyCache('KeyCache.__nonzero__')
        self.assertFalse(bool(c))

        c.data = 500
        c = KeyCache('KeyCache.__nonzero__')
        self.assertTrue(bool(c))

        c.data = 0
        self.assertFalse(bool(c))
예제 #4
0
    def test___cmp__(self):
        c = KeyCache('KeyCache.__cmp__')

        self.assertFalse(c == "b")
        self.assertTrue(c < "c")
        self.assertFalse(c > "a")

        c.data = "b"
        c = KeyCache('KeyCache.__cmp__')
        self.assertTrue(c == "b")
        self.assertTrue(c < "c")
        self.assertTrue(c > "a")
예제 #5
0
    def test___cmp__(self):
        c = KeyCache('KeyCache.__cmp__')

        self.assertFalse(c == "b")
        self.assertTrue(c < "c")
        self.assertFalse(c > "a")

        c.data = "b"
        c = KeyCache('KeyCache.__cmp__')
        self.assertTrue(c == "b")
        self.assertTrue(c < "c")
        self.assertTrue(c > "a")
예제 #6
0
    def test_has(self):
        c = KeyCache('KeyCache.khas')
        self.assertFalse(c.has())

        c.data = "bah"
        self.assertTrue(c.has())

        c.clear()
        self.assertFalse(c.has())
예제 #7
0
    def test_has(self):
        c = KeyCache('KeyCache.khas')
        self.assertFalse(c.has())

        c.data = "bah"
        self.assertTrue(c.has())

        c.clear()
        self.assertFalse(c.has())
예제 #8
0
    def test_increment(self):
        c = KeyCache('ktest_increment')
        c.serialize = False
        c += 1

        self.assertEqual(1, c.data)

        c2 = KeyCache('ktest_increment')
        c2.serialize = False
        self.assertEqual(1, int(c2))

        c2.increment(10)
        self.assertEqual(11, int(c2))

        c2.increment(-5)
        self.assertEqual(6, int(c2))

        c3 = KeyCache('ktest_increment')
        c3.serialize = False
        self.assertEqual(6, int(c3))
예제 #9
0
    def test_normalize(self):
        class TKC(KeyCache):
            def normalize(self, val):
                if val is None: val = 0
                return int(val)

        c = KeyCache('KeyCache.normalize')
        self.assertFalse(isinstance(c.data, int))
        self.assertEqual(None, c.data)

        c = TKC('TKC.normalize')
        self.assertTrue(isinstance(c.data, int))
        self.assertEqual(0, c.data)
예제 #10
0
    def test___nonzero__(self):
        c = KeyCache('KeyCache.__nonzero__')
        self.assertFalse(bool(c))

        c.data = 500
        c = KeyCache('KeyCache.__nonzero__')
        self.assertTrue(bool(c))

        c.data = 0
        self.assertFalse(bool(c))
예제 #11
0
    def test_key(self):
        c = KeyCache('kfoo', 'bar')
        self.assertEqual(None, c.data)

        c = KeyCache('kfoo', 'bar')
        self.assertFalse(c.has())
        c.data = "foo"
        self.assertTrue(c.has())

        self.assertEqual("foo", c.data)

        c = KeyCache('kfoo', 'bar')
        self.assertTrue(c.has())
        self.assertEqual("foo", c.data)

        c = KeyCache('kfoo')
        c.ttl = 1
        c.data = "boom"
        self.assertTrue(c.has())
        time.sleep(1)
        self.assertFalse(c.has())

        c = KeyCache('kfoo2')
        c.data = "boom2"
        self.assertTrue(c.has())
        self.assertEqual("boom2", c.data)

        delattr(c, 'data')
        self.assertFalse(c.has())

        #self.assertEqual('booyah', getattr(c, 'data', 'booyah'))
        self.assertEqual(None, c.data)
예제 #12
0
 def test___del__(self):
     c = KeyCache('KeyCache.__del__')
     del (c.data)
예제 #13
0
    def test_key(self):
        c = KeyCache('kfoo', 'bar')
        self.assertEqual(None, c.data)

        c = KeyCache('kfoo', 'bar')
        self.assertFalse(c.has())
        c.data = "foo"
        self.assertTrue(c.has())

        self.assertEqual("foo", c.data)

        c = KeyCache('kfoo', 'bar')
        self.assertTrue(c.has())
        self.assertEqual("foo", c.data)

        c = KeyCache('kfoo')
        c.ttl = 1
        c.data = "boom"
        self.assertTrue(c.has())
        time.sleep(1)
        self.assertFalse(c.has())

        c = KeyCache('kfoo2')
        c.data = "boom2"
        self.assertTrue(c.has())
        self.assertEqual("boom2", c.data)

        delattr(c, 'data')
        self.assertFalse(c.has())

        #self.assertEqual('booyah', getattr(c, 'data', 'booyah'))
        self.assertEqual(None, c.data)
예제 #14
0
    def test_increment(self):
        c = KeyCache('ktest_increment')
        c.serialize = False
        c += 1

        self.assertEqual(1, c.data)

        c2 = KeyCache('ktest_increment')
        c2.serialize = False
        self.assertEqual(1, int(c2))

        c2.increment(10)
        self.assertEqual(11, int(c2))

        c2.increment(-5)
        self.assertEqual(6, int(c2))

        c3 = KeyCache('ktest_increment')
        c3.serialize = False
        self.assertEqual(6, int(c3))