tests/fakepatchtime.py
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 20 Nov 2020 14:43:21 -0800
changeset 45909 9dc1351d0b5f
parent 43076 2372284d9457
child 45957 89a2afe31e82
permissions -rw-r--r--
errors: raise ConfigError on failure to parse config file This replaces two raises of `ParseError` by `ConfigError`, which makes it so we get the desired exit code when `ui.detailed-exit-code` is enabled. Because the exceptions include a location, I had to add that to `ConfigError` as well. I considered making `ConfigError` a subclass of `ParseError`, but it doesn't feel like it quite passes the "is-a" test. I used "config error: " as prefix for these errors instead of the previous "hg: parse error: ", which seems a little less accurate now (and, as I've said before, I don't know what the "hg: " part is supposed to signify anyway). I can easily be convinced to change the prefix to something else (including "abort: "). Some of the exceptions raised here mean that we fail to even load the `ui` object in the `dispatch` module. When that happens, we don't know to use detailed exit codes, so some tests (e.g. `test-hgrc.t`) still see exit code 255. I'll try to get back to that later. It should be possible to give detailed exit codes if at least part of the config can be read (e.g. when the system-wide one enables detailed exit codes and the user's config fails to parse). Differential Revision: https://phab.mercurial-scm.org/D9355
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
# extension to emulate invoking 'patch.internalpatch()' at the time
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
# specified by '[fakepatchtime] fakenow'
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     4
from __future__ import absolute_import
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     5
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     6
from mercurial import (
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     7
    extensions,
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     8
    patch as patchmod,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
     9
    registrar,
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
    10
)
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36358
diff changeset
    11
from mercurial.utils import dateutil
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    12
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    13
configtable = {}
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    14
configitem = registrar.configitem(configtable)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    15
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    16
configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    17
    b'fakepatchtime', b'fakenow', default=None,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    18
)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    19
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    20
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    21
def internalpatch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    22
    orig,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    23
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    24
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    25
    patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    26
    strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    27
    prefix=b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    28
    files=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    29
    eolmode=b'strict',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    30
    similarity=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    31
):
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    32
    if files is None:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    33
        files = set()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    34
    r = orig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    35
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    36
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    37
        patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    38
        strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    39
        prefix=prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    40
        files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    41
        eolmode=eolmode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    42
        similarity=similarity,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    43
    )
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    44
36358
9a75619776ca py3: add b'' prefixes in fakepatchtime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34772
diff changeset
    45
    fakenow = ui.config(b'fakepatchtime', b'fakenow')
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    46
    if fakenow:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    47
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    48
        # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36358
diff changeset
    49
        fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    50
        for f in files:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    51
            repo.wvfs.utime(f, (fakenow, fakenow))
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    52
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    53
    return r
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36636
diff changeset
    55
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    56
def extsetup(ui):
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    57
    extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)