1 from __future__ import absolute_import |
1 from __future__ import absolute_import, print_function |
2 |
2 |
3 from mercurial import ( |
3 from mercurial import ( |
4 util, |
4 util, |
5 ) |
5 ) |
6 |
6 |
7 def printifpresent(d, xs, name='d'): |
7 def printifpresent(d, xs, name='d'): |
8 for x in xs: |
8 for x in xs: |
9 present = x in d |
9 present = x in d |
10 print "'%s' in %s: %s" % (x, name, present) |
10 print("'%s' in %s: %s" % (x, name, present)) |
11 if present: |
11 if present: |
12 print "%s['%s']: %s" % (name, x, d[x]) |
12 print("%s['%s']: %s" % (name, x, d[x])) |
13 |
13 |
14 def test_lrucachedict(): |
14 def test_lrucachedict(): |
15 d = util.lrucachedict(4) |
15 d = util.lrucachedict(4) |
16 d['a'] = 'va' |
16 d['a'] = 'va' |
17 d['b'] = 'vb' |
17 d['b'] = 'vb' |
54 d['d'] = 'vd3' |
54 d['d'] = 'vd3' |
55 |
55 |
56 dc = d.copy() |
56 dc = d.copy() |
57 |
57 |
58 # all of these should be present |
58 # all of these should be present |
59 print "\nAll of these should be present:" |
59 print("\nAll of these should be present:") |
60 printifpresent(dc, ['a', 'b', 'c', 'd'], 'dc') |
60 printifpresent(dc, ['a', 'b', 'c', 'd'], 'dc') |
61 |
61 |
62 # 'a' should be dropped because it was least recently used |
62 # 'a' should be dropped because it was least recently used |
63 print "\nAll of these except 'a' should be present:" |
63 print("\nAll of these except 'a' should be present:") |
64 dc['e'] = 've3' |
64 dc['e'] = 've3' |
65 printifpresent(dc, ['a', 'b', 'c', 'd', 'e'], 'dc') |
65 printifpresent(dc, ['a', 'b', 'c', 'd', 'e'], 'dc') |
66 |
66 |
67 # contents and order of original dict should remain unchanged |
67 # contents and order of original dict should remain unchanged |
68 print "\nThese should be in reverse alphabetical order and read 'v?3':" |
68 print("\nThese should be in reverse alphabetical order and read 'v?3':") |
69 dc['b'] = 'vb3_new' |
69 dc['b'] = 'vb3_new' |
70 for k in list(iter(d)): |
70 for k in list(iter(d)): |
71 print "d['%s']: %s" % (k, d[k]) |
71 print("d['%s']: %s" % (k, d[k])) |
72 |
72 |
73 if __name__ == '__main__': |
73 if __name__ == '__main__': |
74 test_lrucachedict() |
74 test_lrucachedict() |