tests/test-lrucachedict.py
author Simon Heimberg <simohe@besonet.ch>
Wed, 12 Feb 2014 16:09:18 +0100
changeset 20496 acbd19b9fbe1
parent 19710 887ffa22fd0d
child 27371 45d996a566d7
permissions -rw-r--r--
tests: killdaemons.py for windows distinguishes access violation and terminated To distinguish between access violaition (process belonging to another user) and a terminated process, PROCESS_QUERY_INFORMATION must be enabled. But TerminateProcess still raises error 5 in both cases. Therefore check before if the process has already terminated.

from mercurial import util

def printifpresent(d, xs):
    for x in xs:
        present = x in d
        print "'%s' in d: %s" % (x, present)
        if present:
            print "d['%s']: %s" % (x, d[x])

def test_lrucachedict():
    d = util.lrucachedict(4)
    d['a'] = 'va'
    d['b'] = 'vb'
    d['c'] = 'vc'
    d['d'] = 'vd'

    # all of these should be present
    printifpresent(d, ['a', 'b', 'c', 'd'])

    # 'a' should be dropped because it was least recently used
    d['e'] = 've'
    printifpresent(d, ['a', 'b', 'c', 'd', 'e'])

    # touch entries in some order (get or set).
    d['e']
    d['c'] = 'vc2'
    d['d']
    d['b'] = 'vb2'

    # 'e' should be dropped now
    d['f'] = 'vf'
    printifpresent(d, ['b', 'c', 'd', 'e', 'f'])

    d.clear()
    printifpresent(d, ['b', 'c', 'd', 'e', 'f'])

if __name__ == '__main__':
    test_lrucachedict()