view tests/test-lrucachedict.py @ 21740:2b3b60031b6f

run-tests: fixes the number of tests ran when '--retest' is enabled This patch fixes a regression recently introduced by a refactoring. (see 92a6b16c9186 and about 200 previous changesets from Gregory Szorc) While retesting, that is when '--retest' is enabled, only failure tests run and others either skipped or ignored. During retesting, "result.testsRun" holds the count of failure test that has run. But as while printing output, we have subtracted the skipped and ignored count from "result.testsRun". Therefore, to make the count remain the same, we need to add skipped and ignored count before printing.
author anuraggoel <anurag.dsps@gmail.com>
date Thu, 12 Jun 2014 03:20:28 +0530
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()