view tests/test-lrucachedict.py @ 23623:80a37f706011

test-check-commit-hg: clarify misleading "commit message rules" error The test case doesn't only check the commit message, but also the patch, which can result in confusing output like + Revision df6f06d17100 does not comply to commit message rules + ------------------------------------------------------ + 32: adds double empty line + + even when there are no double blank lines in the commit message. Drop the "commit message" part to make it less confusing.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 18 Dec 2014 10:11:38 -0800
parents 887ffa22fd0d
children 45d996a566d7
line wrap: on
line source

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()