/usr/share/pyshared/genshi/tests/util.py is in python-genshi 0.7-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # -*- coding: utf-8 -*-
#
# Copyright (C) 2006,2009 Edgewall Software
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://genshi.edgewall.org/wiki/License.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://genshi.edgewall.org/log/.
import doctest
import unittest
from genshi import util
from genshi.util import LRUCache
class LRUCacheTestCase(unittest.TestCase):
def test_setitem(self):
cache = LRUCache(2)
cache['A'] = 0
self.assertEqual(1, len(cache))
self.assertEqual('A', cache.head.key)
self.assertEqual('A', cache.tail.key)
item_a = cache._dict['A']
self.assertEqual('A', item_a.key)
self.assertEqual(0, item_a.value)
self.assertEqual(None, item_a.prv)
self.assertEqual(None, item_a.nxt)
cache['B'] = 1
self.assertEqual(2, len(cache))
self.assertEqual('B', cache.head.key)
self.assertEqual('A', cache.tail.key)
item_a = cache._dict['A']
item_b = cache._dict['B']
self.assertEqual('A', item_a.key)
self.assertEqual(0, item_a.value)
self.assertEqual(item_b, item_a.prv)
self.assertEqual(None, item_a.nxt)
self.assertEqual('B', item_b.key)
self.assertEqual(1, item_b.value)
self.assertEqual(None, item_b.prv)
self.assertEqual(item_a, item_b.nxt)
cache['C'] = 2
self.assertEqual(2, len(cache))
self.assertEqual('C', cache.head.key)
self.assertEqual('B', cache.tail.key)
item_b = cache._dict['B']
item_c = cache._dict['C']
self.assertEqual('B', item_b.key)
self.assertEqual(1, item_b.value)
self.assertEqual(item_c, item_b.prv)
self.assertEqual(None, item_b.nxt)
self.assertEqual('C', item_c.key)
self.assertEqual(2, item_c.value)
self.assertEqual(None, item_c.prv)
self.assertEqual(item_b, item_c.nxt)
def test_getitem(self):
cache = LRUCache(2)
cache['A'] = 0
cache['B'] = 1
cache['A']
self.assertEqual(2, len(cache))
self.assertEqual('A', cache.head.key)
self.assertEqual('B', cache.tail.key)
item_a = cache._dict['A']
item_b = cache._dict['B']
self.assertEqual('A', item_a.key)
self.assertEqual(0, item_a.value)
self.assertEqual(None, item_a.prv)
self.assertEqual(item_b, item_a.nxt)
self.assertEqual('B', item_b.key)
self.assertEqual(1, item_b.value)
self.assertEqual(item_a, item_b.prv)
self.assertEqual(None, item_b.nxt)
def suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(util))
suite.addTest(unittest.makeSuite(LRUCacheTestCase, 'test'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|