annotate hgext/children.py @ 39772:ae531f5e583c

testing: add interface unit tests for file storage Our strategy for supporting alternate storage backends is to define interfaces for everything then "code to the interface." We already have interfaces for various primitives, including file and manifest storage. What we don't have is generic unit tests for those interfaces. Up to this point we've been relying on high-level integration tests (mainly in the form of existing .t tests) to test alternate storage backends. And my experience with developing the "simple store" test extension is that such testing is very tedious: it takes several minutes to run all tests and when you find a failure, it is often non-trivial to debug. This commit starts to change that. This commit introduces the mercurial.testing.storage module. It contains testing code for storage. Currently, it defines some unittest.TestCase classes for testing the file storage interfaces. It also defines some factory functions that allow a caller to easily spawn a custom TestCase "bound" to a specific file storage backend implementation. A new .py test has been added. It simply defines a callable to produce filelog and transaction instances on demand and then "registers" the various test classes so the filelog class can be tested with the storage interface unit tests. As part of writing the tests, I identified a couple of apparent bugs in revlog.py and filelog.py! These are tracked with inline TODO comments. Writing the tests makes it more obvious where the storage interface is lacking. For example, we raise either IndexError or error.LookupError for missing revisions depending on whether we use an integer revision or a node. Also, we raise error.RevlogError in various places when we should be raising a storage-agnostic error type. The storage interfaces are currently far from perfect and there is much work to be done to improve them. But at least with this commit we finally have the start of unit tests that can be used to "qualify" the behavior of a storage backend. And when implementing and debugging new storage backends, we now have an obvious place to define new tests and have obvious places to insert breakpoints to facilitate debugging. This should be invaluable when implementing new storage backends. I added the mercurial.testing package because these interface conformance tests are generic and need to be usable by all storage backends. Having the code live in tests/ would make it difficult for storage backends implemented in extensions to test their interface conformance. First, it would require obtaining a copy of Mercurial's storage test code in order to test. Second, it would make testing against multiple Mercurial versions difficult, as you would need to import N copies of the storage testing code in order to achieve test coverage. By making the test code part of the Mercurial distribution itself, extensions can `import mercurial.testing.*` to access and run the test code. The test will run against whatever Mercurial version is active. FWIW I've always wanted to move parts of run-tests.py into the mercurial.* package to make the testing story simpler (e.g. imagine an `hg debugruntests` command that could invoke the test harness). While I have no plans to do that in the near future, establishing the mercurial.testing package does provide a natural home for that code should someone do this in the future. Differential Revision: https://phab.mercurial-scm.org/D4650
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 18 Sep 2018 16:52:11 -0700
parents 7c8524efd847
children c303d65d2e34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
1 # Mercurial extension to provide the 'hg children' command
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
2 #
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
3 # Copyright 2007 by Intevation GmbH <intevation@intevation.de>
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
4 #
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
5 # Author(s):
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
6 # Thomas Arendsen Hein <thomas@intevation.de>
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
7 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8076
diff changeset
8 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9253
diff changeset
9 # GNU General Public License version 2 or any later version.
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
10
16668
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
11 '''command to display child changesets (DEPRECATED)
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
12
16670
052047753f7d children: use hg reST role for example
Martin Geisler <mg@lazybytes.net>
parents: 16668
diff changeset
13 This extension is deprecated. You should use :hg:`log -r
052047753f7d children: use hg reST role for example
Martin Geisler <mg@lazybytes.net>
parents: 16668
diff changeset
14 "children(REV)"` instead.
16668
f393d20fb2ba children: mark extension as deprecated
Augie Fackler <raf@durin42.com>
parents: 11321
diff changeset
15 '''
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8277
diff changeset
16
28093
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
17 from __future__ import absolute_import
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
18
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
19 from mercurial.i18n import _
28093
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
20 from mercurial import (
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
21 cmdutil,
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34973
diff changeset
22 logcmdutil,
34973
11a372d80496 py3: handle keyword arguments in hgext/children.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34945
diff changeset
23 pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
24 registrar,
37357
7c8524efd847 children: support specifying revision by revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 37265
diff changeset
25 scmutil,
28093
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
26 )
7353cacd5d54 children: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27716
diff changeset
27
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
28 templateopts = cmdutil.templateopts
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
29
21248
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
30 cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29841
diff changeset
31 command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 28799
diff changeset
32 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24482
diff changeset
33 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24482
diff changeset
34 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24482
diff changeset
35 # leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 28799
diff changeset
36 testedwith = 'ships-with-hg-core'
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
37
21248
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
38 @command('children',
37265
923362010525 children: use repo['.'] instead of repo['']
Martin von Zweigbergk <martinvonz@google.com>
parents: 35888
diff changeset
39 [('r', 'rev', '.',
21248
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
40 _('show children of the specified revision'), _('REV')),
48e859e30cbf children: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 17773
diff changeset
41 ] + templateopts,
21780
2d3fb8476d7a children: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21248
diff changeset
42 _('hg children [-r REV] [FILE]'),
2d3fb8476d7a children: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21248
diff changeset
43 inferrepo=True)
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
44 def children(ui, repo, file_=None, **opts):
8026
683d8ebcf434 expand "dir" to "directory" in help texts
Martin Geisler <mg@lazybytes.net>
parents: 7986
diff changeset
45 """show the children of the given or working directory revision
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
46
9253
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
47 Print the children of the working directory's revisions. If a
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
48 revision is given via -r/--rev, the children of that revision will
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
49 be printed. If a file argument is given, revision in which the
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
50 file was last changed (after the working directory revision or the
d6d811d90976 children: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9055
diff changeset
51 argument to --rev if given) is printed.
27716
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
52
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
53 Please use :hg:`log` instead::
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
54
34945
d2554ef04d26 children: fix the log expansion of `hg children` in doc
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32375
diff changeset
55 hg children => hg log -r "children(.)"
28799
ccab2923a093 children: use double quotes for arguments
timeless <timeless@mozdev.org>
parents: 28093
diff changeset
56 hg children -r REV => hg log -r "children(REV)"
27716
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
57
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
58 See :hg:`help log` and :hg:`help revsets.children`.
3501bd89dad2 children: update help with replacement
timeless <timeless@mozdev.org>
parents: 25186
diff changeset
59
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
60 """
34973
11a372d80496 py3: handle keyword arguments in hgext/children.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34945
diff changeset
61 opts = pycompat.byteskwargs(opts)
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
62 rev = opts.get('rev')
37357
7c8524efd847 children: support specifying revision by revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 37265
diff changeset
63 ctx = scmutil.revsingle(repo, rev)
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
64 if file_:
37357
7c8524efd847 children: support specifying revision by revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 37265
diff changeset
65 fctx = repo.filectx(file_, changeid=ctx.rev())
24482
3eb9045396b0 children: don't pass filectx to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 21780
diff changeset
66 childctxs = [fcctx.changectx() for fcctx in fctx.children()]
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
67 else:
24482
3eb9045396b0 children: don't pass filectx to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 21780
diff changeset
68 childctxs = ctx.children()
4783
8b90d763ea90 Add extension to provide the 'hg children' command (with tests)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
69
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34973
diff changeset
70 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
24482
3eb9045396b0 children: don't pass filectx to displayer
Yuya Nishihara <yuya@tcha.org>
parents: 21780
diff changeset
71 for cctx in childctxs:
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6747
diff changeset
72 displayer.show(cctx)
10152
56284451a22c Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents: 9253
diff changeset
73 displayer.close()