view tests/test-lrucachedict.py @ 24878:e530cde6d115 stable

bundle2: disable ouput capture unless we use http (issue4613 issue4615) The current bundle2 processing was capturing all output. This is nice as it provide better meta data about what output what, but this was changing two things: 1) adding a prefix "remote: " to "other" output during local push (issue4613) 2) local and ssh push does not provide real time output anymore (issue4615) As we are unsure about what form should be used in (1) and how to solve (2) we disable output capture in this two cases. Output capture can be forced using an experimental option.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 28 Apr 2015 17:38:02 -0700
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()