Mercurial > hg
annotate tests/test-config-env.py @ 51732:43460c311c0c
typing: add trivial type hints to `mercurial.scmutil`
There's still a lot to go, but there's a lot here already, so I tried to keep it
to obvious/trivial things. I didn't bother with contexts, matchers, and
revisions that can be `bytes | int | None`.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 24 Jul 2024 22:40:22 -0400 |
parents | ca7bde5dbafb |
children |
rev | line source |
---|---|
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 |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
4 import os |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
5 |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
6 from mercurial import ( |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
7 encoding, |
43872
527eba3013ea
tests: make test-config-env.py a little less hacky
Martin von Zweigbergk <martinvonz@google.com>
parents:
43076
diff
changeset
|
8 extensions, |
31685
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 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
14 from mercurial.utils import procutil |
37119
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36730
diff
changeset
|
15 |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
16 testtmp = encoding.environ[b'TESTTMP'] |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
17 |
51703
ca7bde5dbafb
black: format the codebase with 23.3.0
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
18 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
19 # prepare hgrc files |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
20 def join(name): |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
21 return os.path.join(testtmp, name) |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
22 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
23 |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
24 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
|
25 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
|
26 |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
27 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
|
28 f.write(b'[ui]\neditor=e1') |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
29 |
51703
ca7bde5dbafb
black: format the codebase with 23.3.0
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
30 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
31 # 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
|
32 def systemrcpath(): |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
33 return [join(b'sysrc')] |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
34 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
35 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
36 def userrcpath(): |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
37 return [join(b'userrc')] |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
38 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
39 |
44031
1864efbe90d9
ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
43872
diff
changeset
|
40 extensions.wrapfunction(rcutil, 'default_rc_resources', lambda orig: []) |
43872
527eba3013ea
tests: make test-config-env.py a little less hacky
Martin von Zweigbergk <martinvonz@google.com>
parents:
43076
diff
changeset
|
41 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
42 rcutil.systemrcpath = systemrcpath |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
43 rcutil.userrcpath = userrcpath |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
44 |
51703
ca7bde5dbafb
black: format the codebase with 23.3.0
Raphaël Gomès <rgomes@octobus.net>
parents:
51700
diff
changeset
|
45 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
46 # utility to print configs |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
47 def printconfigs(env): |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
48 encoding.environ = env |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
49 rcutil._rccomponents = None # reset cache |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
50 ui = uimod.ui.load() |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
51 for section, name, value in ui.walkconfig(): |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
52 source = ui.configsource(section, name) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
53 procutil.stdout.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
54 b'%s.%s=%s # %s\n' % (section, name, value, util.pconvert(source)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
55 ) |
37119
d4a2e0d5d042
procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36730
diff
changeset
|
56 procutil.stdout.write(b'\n') |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
57 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37119
diff
changeset
|
58 |
31685
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
59 # environment variable overrides |
d83e51654c8a
rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
60 printconfigs({}) |
36730
a22915edc279
py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents:
31857
diff
changeset
|
61 printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'}) |