示例#1
0
 def test_expire_callback(self):
     "dictime can expire and callback"
     s = dictime(fruit="orange")
     s.set_expires(timedelta(milliseconds=100), lambda s: s.set('fruit', 'apple'))
     self.assertEqual(s["fruit"], 'orange')
     time.sleep(.1)
     self.assertEqual(s["fruit"], 'apple')
示例#2
0
 def test_set_key_exire_datetime(self):
     s = dictime()
     s.set("fruit",
           "apple",
           expires=datetime.now() + timedelta(milliseconds=100))
     time.sleep(.2)
     self.assertNotIn("fruit", s)
示例#3
0
 def test_set_key_expandfut(self):
     s = dictime()
     s.set("fruit", "apple", expires=dict(milliseconds=200), future=dict(milliseconds=100))
     time.sleep(.1)
     self.assertIn("fruit", s)
     self.assertEqual(s["fruit"], "apple")
     time.sleep(.1)
     self.assertNotIn("fruit", s)
示例#4
0
 def test_setdefault(self):
     s = dictime()
     self.assertEqual(len(s), 0)
     s.setdefault('key', 'value')
     self.assertEqual(len(s), 1)
     self.assertEqual(s.get('key'), 'value')
     s.setdefault('key', 'different')
     self.assertEqual(s.get('key'), 'value')
示例#5
0
 def test_expire_callback(self):
     "dictime can expire and callback"
     s = dictime(fruit="orange")
     s.set_expires(timedelta(milliseconds=100),
                   lambda s: s.set('fruit', 'apple'))
     self.assertEqual(s["fruit"], 'orange')
     time.sleep(.1)
     self.assertEqual(s["fruit"], 'apple')
示例#6
0
 def test_setdefault(self):
     s = dictime()
     self.assertEqual(len(s), 0)
     s.setdefault('key', 'value')
     self.assertEqual(len(s), 1)
     self.assertEqual(s.get('key'), 'value')
     s.setdefault('key', 'different')
     self.assertEqual(s.get('key'), 'value')
示例#7
0
 def test_expire(self):
     "dictime can expire all its contents"
     s = dictime(one=1, two=2, three=3)
     s.set_expires(timedelta(milliseconds=100))
     time.sleep(.2)
     self.assertFalse(s.has_key('one'), "the dicttime was not emptied")
     s['one'] = "something_else"
     self.assertEqual(s['one'], "something_else")
     time.sleep(.1)
     self.assertFalse(s.has_key('one'), "the dicttime was not emptied")
示例#8
0
 def test_expire(self):
     "dictime can expire all its contents"
     s = dictime(one=1, two=2, three=3)
     s.set_expires(timedelta(milliseconds=100))
     time.sleep(.2)
     self.assertFalse(s.has_key('one'), "the dicttime was not emptied")
     s['one'] = "something_else"
     self.assertEqual(s['one'], "something_else")
     time.sleep(.1)
     self.assertFalse(s.has_key('one'), "the dicttime was not emptied")
示例#9
0
 def test_set_key_expandfut(self):
     s = dictime()
     s.set("fruit",
           "apple",
           expires=dict(milliseconds=200),
           future=dict(milliseconds=100))
     time.sleep(.1)
     self.assertIn("fruit", s)
     self.assertEqual(s["fruit"], "apple")
     time.sleep(.1)
     self.assertNotIn("fruit", s)
示例#10
0
 def test_remove(self):
     s = dictime(one=1, two=2, three=3)
     del s['one']
     self.assertNotIn('one', s)
     s.remove('two')
     self.assertNotIn('two', s)
示例#11
0
 def test_set_key_future(self):
     s = dictime()
     s.set("fruit", "apple", future=dict(milliseconds=100))
     time.sleep(.2)
     self.assertIn("fruit", s)
     self.assertEqual(s["fruit"], "apple")
示例#12
0
 def test_keys(self):
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual(s.keys(), ['one', 'two', 'three'])
示例#13
0
 def test_nonzero(self):
     s = dictime(one=1, two=2, three=3)
     self.assertTrue(s.__nonzero__())
     s = dictime()
     self.assertFalse(s.__nonzero__())
示例#14
0
 def test_clear(self):
     s = dictime(one=1, two=2, three=3)
     self.assertEqual(len(s), 3)
     s.clear()
     self.assertEqual(len(s), 0)
示例#15
0
 def test_values(self):
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual(s.values(), [1, 2, 3])
示例#16
0
 def test_getitem(self):
     s = dictime(one=1, two=2, three=3)
     self.assertEqual(s['one'], 1)
     self.assertRaises(KeyError, s.__getitem__, '__')
示例#17
0
 def test_no_kwargs(self):
     s = dictime()
     self.assertEqual(len(s), 0)
     s['key'] = 'value'
     self.assertEqual(len(s), 1)
示例#18
0
 def test_nonzero(self):
     s = dictime(one=1, two=2, three=3)
     self.assertTrue(s.__nonzero__())
     s = dictime()
     self.assertFalse(s.__nonzero__())
示例#19
0
 def test_keys(self):
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual(s.keys(), ['one', 'two', 'three'])
示例#20
0
 def test_remove(self):
     s = dictime(one=1, two=2, three=3)
     del s['one']
     self.assertNotIn('one', s)
     s.remove('two')
     self.assertNotIn('two', s)
示例#21
0
 def test_iter(self):
     "dictime can iter"
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual([x for x in s], [('one', 1), ('two', 2), ('three', 3)])
示例#22
0
 def test_set_key_exire_datetime(self):
     s = dictime()
     s.set("fruit", "apple", expires=datetime.now() + timedelta(milliseconds=100))
     time.sleep(.2)
     self.assertNotIn("fruit", s)
示例#23
0
 def test_clear(self):
     s = dictime(one=1, two=2, three=3)
     self.assertEqual(len(s), 3)
     s.clear()
     self.assertEqual(len(s), 0)
示例#24
0
 def test_contains(self):
     s = dictime(one=1, two=2, three=3)
     self.assertIn('one', s)
     self.assertNotIn('__', s)
示例#25
0
 def test_contains(self):
     s = dictime(one=1, two=2, three=3)
     self.assertIn('one', s)
     self.assertNotIn('__', s)
示例#26
0
 def test_iter(self):
     "dictime can iter"
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual([x for x in s], [('one', 1), ('two', 2),
                                            ('three', 3)])
示例#27
0
 def test_no_kwargs(self):
     s = dictime()
     self.assertEqual(len(s), 0)
     s['key'] = 'value'
     self.assertEqual(len(s), 1)
示例#28
0
 def test_values(self):
     s = dictime(one=1, two=2, three=3)
     self.assertItemsEqual(s.values(), [1,2,3])
示例#29
0
 def test_set_key_future(self):
     s = dictime()
     s.set("fruit", "apple", future=dict(milliseconds=100))
     time.sleep(.2)
     self.assertIn("fruit", s)
     self.assertEqual(s["fruit"], "apple")
示例#30
0
 def test_getitem(self):
     s = dictime(one=1, two=2, three=3)
     self.assertEqual(s['one'], 1)
     self.assertRaises(KeyError, s.__getitem__, '__')