tests/test-config-env.py
author Yuya Nishihara <yuya@tcha.org>
Mon, 12 Mar 2018 20:45:10 +0900
changeset 37064 434e520adb8c
parent 36730 a22915edc279
child 37119 d4a2e0d5d042
permissions -rw-r--r--
annotate: do not construct attr.s object per line while computing history Unfortunately, good abstraction has a cost. It's way slower to construct an annotateline() object than creating a plain tuple or a list. This patch changes the internal data structure from row-based to columnar, so the decorate() function can be instant (i.e. no Python in hot loop.) For code readability, the outermost tuple is switched to an attr.s object instead. (original, row-based attr.s) $ hg annot mercurial/commands.py --time > /dev/null time: real 11.470 secs (user 11.400+0.000 sys 0.070+0.000) $ hg annot mercurial/commands.py --time --line-number > /dev/null time: real 39.590 secs (user 39.500+0.000 sys 0.080+0.000) (this patch, columnar) $ hg annot mercurial/commands.py --time > /dev/null time: real 11.780 secs (user 11.710+0.000 sys 0.070+0.000) $ hg annot mercurial/commands.py --time --line-number > /dev/null time: real 12.240 secs (user 12.170+0.000 sys 0.090+0.000) (cf. 4.3.3, row-based tuple) $ hg annot mercurial/commands.py --time --line-number > /dev/null time: real 19.540 secs (user 19.460+0.000 sys 0.080+0.000)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     1
# Test the config layer generated by environment variables
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     2
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     3
from __future__ import absolute_import, print_function
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     4
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
import os
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
from mercurial import (
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
    encoding,
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
    rcutil,
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
    ui as uimod,
31857
08fbc97d1364 tests: print Unix style paths in *.py tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 31685
diff changeset
    11
    util,
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
)
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    14
testtmp = encoding.environ[b'TESTTMP']
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    15
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    16
# prepare hgrc files
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    17
def join(name):
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    18
    return os.path.join(testtmp, name)
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    19
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    20
with open(join(b'sysrc'), 'wb') as f:
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    21
    f.write(b'[ui]\neditor=e0\n[pager]\npager=p0\n')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    22
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    23
with open(join(b'userrc'), 'wb') as f:
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    24
    f.write(b'[ui]\neditor=e1')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    25
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    26
# replace rcpath functions so they point to the files above
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    27
def systemrcpath():
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    28
    return [join(b'sysrc')]
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    29
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    30
def userrcpath():
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    31
    return [join(b'userrc')]
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    32
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    33
rcutil.systemrcpath = systemrcpath
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    34
rcutil.userrcpath = userrcpath
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    35
os.path.isdir = lambda x: False # hack: do not load default.d/*.rc
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    36
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    37
# utility to print configs
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    38
def printconfigs(env):
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    39
    encoding.environ = env
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    40
    rcutil._rccomponents = None # reset cache
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    41
    ui = uimod.ui.load()
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    42
    for section, name, value in ui.walkconfig():
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    43
        source = ui.configsource(section, name)
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    44
        util.stdout.write(b'%s.%s=%s # %s\n'
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    45
                          % (section, name, value, util.pconvert(source)))
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    46
    util.stdout.write(b'\n')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    47
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    48
# environment variable overrides
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
    49
printconfigs({})
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
    50
printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'})