[PATCH] test-lrucachedict: move to inline doctest
Augie Fackler
raf at durin42.com
Mon Nov 23 08:51:30 CST 2015
On Sun, Nov 22, 2015 at 10:28:25PM -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1448253387 28800
> # Sun Nov 22 20:36:27 2015 -0800
> # Node ID 160d7e207cc161543c0486c4de223b30621cd6d9
> # Parent 6489d176db3170c5d9cba81e666a6802fbe834d0
> test-lrucachedict: move to inline doctest
queued this, many thanks
>
> This makes the test slightly easier to read and comprehend. This
> makes it easier for me to debug issues as I rewrite the cache
> implementation.
>
> The test output did change slightly: doctest will present a statement's
> return value if nothing is done with it. In 2 cases, we performed a d[]
> lookup, which introduced new output. The output has been adjusted so
> test continued to pass.
>
> diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py
> --- a/tests/test-lrucachedict.py
> +++ b/tests/test-lrucachedict.py
> @@ -1,38 +1,70 @@
> +import doctest
> +
> 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'
> + """
> + >>> 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' in d: True
> + d['a']: va
> + 'b' in d: True
> + d['b']: vb
> + 'c' in d: True
> + d['c']: vc
> + 'd' in d: True
> + d['d']: vd
> + >>> # 'a' should be dropped because it was least recently used
> + >>> d['e'] = 've'
> + >>> printifpresent(d, ['a', 'b', 'c', 'd', 'e'])
> + 'a' in d: False
> + 'b' in d: True
> + d['b']: vb
> + 'c' in d: True
> + d['c']: vc
> + 'd' in d: True
> + d['d']: vd
> + 'e' in d: True
> + d['e']: ve
> + >>> # touch entries in some order (get or set).
> + >>> d['e']
> + 've'
> + >>> d['c'] = 'vc2'
> + >>> d['d']
> + 'vd'
> + >>> d['b'] = 'vb2'
> + >>> # 'e' should be dropped now
> + >>> d['f'] = 'vf'
> + >>> printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
> + 'b' in d: True
> + d['b']: vb2
> + 'c' in d: True
> + d['c']: vc2
> + 'd' in d: True
> + d['d']: vd
> + 'e' in d: False
> + 'f' in d: True
> + d['f']: vf
> + >>>
> + >>> d.clear()
> + >>> printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
> + 'b' in d: False
> + 'c' in d: False
> + 'd' in d: False
> + 'e' in d: False
> + 'f' in d: False
> + """
>
> - # 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()
> +doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
> \ No newline at end of file
> diff --git a/tests/test-lrucachedict.py.out b/tests/test-lrucachedict.py.out
> deleted file mode 100644
> --- a/tests/test-lrucachedict.py.out
> +++ /dev/null
> @@ -1,31 +0,0 @@
> -'a' in d: True
> -d['a']: va
> -'b' in d: True
> -d['b']: vb
> -'c' in d: True
> -d['c']: vc
> -'d' in d: True
> -d['d']: vd
> -'a' in d: False
> -'b' in d: True
> -d['b']: vb
> -'c' in d: True
> -d['c']: vc
> -'d' in d: True
> -d['d']: vd
> -'e' in d: True
> -d['e']: ve
> -'b' in d: True
> -d['b']: vb2
> -'c' in d: True
> -d['c']: vc2
> -'d' in d: True
> -d['d']: vd
> -'e' in d: False
> -'f' in d: True
> -d['f']: vf
> -'b' in d: False
> -'c' in d: False
> -'d' in d: False
> -'e' in d: False
> -'f' in d: False
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list