annotate genshi/tests/util.py @ 902:09cc3627654c experimental-inline

Sync `experimental/inline` branch with [source:trunk@1126].
author cmlenz
date Fri, 23 Apr 2010 21:08:26 +0000
parents c5ec3146fcb6
children
rev   line source
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
2 #
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
3 # Copyright (C) 2006,2009 Edgewall Software
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
4 # All rights reserved.
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
5 #
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
8 # are also available at http://genshi.edgewall.org/wiki/License.
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
9 #
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
12 # history and logs, available at http://genshi.edgewall.org/log/.
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
13
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
14 import doctest
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
15 import unittest
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
16
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
17 from genshi import util
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
18 from genshi.util import LRUCache
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
19
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
20
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
21 class LRUCacheTestCase(unittest.TestCase):
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
22
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
23 def test_setitem(self):
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
24 cache = LRUCache(2)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
25 cache['A'] = 0
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
26 self.assertEqual(1, len(cache))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
27 self.assertEqual('A', cache.head.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
28 self.assertEqual('A', cache.tail.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
29 item_a = cache._dict['A']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
30 self.assertEqual('A', item_a.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
31 self.assertEqual(0, item_a.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
32 self.assertEqual(None, item_a.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
33 self.assertEqual(None, item_a.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
34
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
35 cache['B'] = 1
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
36 self.assertEqual(2, len(cache))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
37 self.assertEqual('B', cache.head.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
38 self.assertEqual('A', cache.tail.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
39 item_a = cache._dict['A']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
40 item_b = cache._dict['B']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
41 self.assertEqual('A', item_a.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
42 self.assertEqual(0, item_a.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
43 self.assertEqual(item_b, item_a.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
44 self.assertEqual(None, item_a.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
45 self.assertEqual('B', item_b.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
46 self.assertEqual(1, item_b.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
47 self.assertEqual(None, item_b.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
48 self.assertEqual(item_a, item_b.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
49
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
50 cache['C'] = 2
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
51 self.assertEqual(2, len(cache))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
52 self.assertEqual('C', cache.head.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
53 self.assertEqual('B', cache.tail.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
54 item_b = cache._dict['B']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
55 item_c = cache._dict['C']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
56 self.assertEqual('B', item_b.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
57 self.assertEqual(1, item_b.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
58 self.assertEqual(item_c, item_b.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
59 self.assertEqual(None, item_b.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
60 self.assertEqual('C', item_c.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
61 self.assertEqual(2, item_c.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
62 self.assertEqual(None, item_c.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
63 self.assertEqual(item_b, item_c.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
64
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
65 def test_getitem(self):
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
66 cache = LRUCache(2)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
67 cache['A'] = 0
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
68 cache['B'] = 1
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
69
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
70 cache['A']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
71
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
72 self.assertEqual(2, len(cache))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
73 self.assertEqual('A', cache.head.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
74 self.assertEqual('B', cache.tail.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
75 item_a = cache._dict['A']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
76 item_b = cache._dict['B']
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
77 self.assertEqual('A', item_a.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
78 self.assertEqual(0, item_a.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
79 self.assertEqual(None, item_a.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
80 self.assertEqual(item_b, item_a.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
81 self.assertEqual('B', item_b.key)
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
82 self.assertEqual(1, item_b.value)
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
83 self.assertEqual(item_a, item_b.prv)
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 274
diff changeset
84 self.assertEqual(None, item_b.nxt)
274
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
85
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
86
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
87 def suite():
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
88 suite = unittest.TestSuite()
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
89 suite.addTest(doctest.DocTestSuite(util))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
90 suite.addTest(unittest.makeSuite(LRUCacheTestCase, 'test'))
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
91 return suite
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
92
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
93 if __name__ == '__main__':
c5ec3146fcb6 Use an LRU cache for caching parsed templates in the `TemplateLoader`. LRU cache implementation is a simplified version of the `LRUCache` class in [http://www.myghty.org/ Myghty].
cmlenz
parents:
diff changeset
94 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software