예제 #1
0
 def test___init__(self):
     dc = DictCache('dfoo__init__', 'bar__init__')
     dc = DictCache('dfoo__init__',
                    'bar__init__',
                    data={
                        'foo': 'foo',
                        'bar': 'bar'
                    })
     self.assertTrue('foo' in dc)
     self.assertTrue('bar' in dc)
예제 #2
0
    def test_dict(self):

        dc = DictCache('dfoo_set', 'bar_set')
        dc.ttl = 1
        self.assertFalse('happy' in dc)
        dc['happy'] = 'sad'
        self.assertTrue('happy' in dc)
        time.sleep(1)
        self.assertFalse('happy' in dc)

        dc = DictCache('dfoo_set',
                       'bar_set',
                       2,
                       data={
                           'foo': 'foo',
                           'bar': 'bar'
                       })
        self.assertTrue('foo' in dc)
        self.assertTrue('bar' in dc)
        self.assertEqual('foo', dc.get('foo'))
        self.assertEqual('bar', dc.get('bar'))
        self.assertEqual('foo', dc['foo'])
        self.assertEqual('bar', dc['bar'])

        d = {'che': 'che'}
        self.assertFalse('che' in dc)
        dc['che'] = d
        self.assertTrue('che' in dc)
        self.assertEqual(d, dc.get('che'))
        self.assertEqual(d, dc['che'])
예제 #3
0
    def test_dict(self):

        dc = DictCache('dfoo_set', 'bar_set')
        dc.ttl = 1
        self.assertFalse('happy' in dc)
        dc['happy'] = 'sad'
        self.assertTrue('happy' in dc)
        time.sleep(1)
        self.assertFalse('happy' in dc)

        dc = DictCache('dfoo_set', 'bar_set', 2, data={'foo': 'foo', 'bar': 'bar'})
        self.assertTrue('foo' in dc)
        self.assertTrue('bar' in dc)
        self.assertEqual('foo', dc.get('foo'))
        self.assertEqual('bar', dc.get('bar'))
        self.assertEqual('foo', dc['foo'])
        self.assertEqual('bar', dc['bar'])

        d = {'che': 'che'}
        self.assertFalse('che' in dc)
        dc['che'] = d
        self.assertTrue('che' in dc)
        self.assertEqual(d, dc.get('che'))
        self.assertEqual(d, dc['che'])
예제 #4
0
 def test_has(self):
     c = DictCache('dhas')
     self.assertFalse(c.has())
     c['foo'] = 'foo'
     self.assertTrue(c.has())
예제 #5
0
 def test_has(self):
     c = DictCache('dhas')
     self.assertFalse(c.has())
     c['foo'] = 'foo'
     self.assertTrue(c.has())