Mercurial > hg
comparison tests/test-config-env.py @ 31685:d83e51654c8a
rcutil: let environ override system configs (BC)
This is BC because system configs won't be able to override $EDITOR, $PAGER.
The new behavior is arguably more rational.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 26 Mar 2017 21:33:37 -0700 |
parents | |
children | 08fbc97d1364 |
comparison
equal
deleted
inserted
replaced
31684:0be96ac9199a | 31685:d83e51654c8a |
---|---|
1 # Test the config layer generated by environment variables | |
2 | |
3 from __future__ import absolute_import, print_function | |
4 | |
5 import os | |
6 | |
7 from mercurial import ( | |
8 encoding, | |
9 rcutil, | |
10 ui as uimod, | |
11 ) | |
12 | |
13 testtmp = encoding.environ['TESTTMP'] | |
14 | |
15 # prepare hgrc files | |
16 def join(name): | |
17 return os.path.join(testtmp, name) | |
18 | |
19 with open(join('sysrc'), 'w') as f: | |
20 f.write('[ui]\neditor=e0\n[pager]\npager=p0\n') | |
21 | |
22 with open(join('userrc'), 'w') as f: | |
23 f.write('[ui]\neditor=e1') | |
24 | |
25 # replace rcpath functions so they point to the files above | |
26 def systemrcpath(): | |
27 return [join('sysrc')] | |
28 | |
29 def userrcpath(): | |
30 return [join('userrc')] | |
31 | |
32 rcutil.systemrcpath = systemrcpath | |
33 rcutil.userrcpath = userrcpath | |
34 os.path.isdir = lambda x: False # hack: do not load default.d/*.rc | |
35 | |
36 # utility to print configs | |
37 def printconfigs(env): | |
38 encoding.environ = env | |
39 rcutil._rccomponents = None # reset cache | |
40 ui = uimod.ui.load() | |
41 for section, name, value in ui.walkconfig(): | |
42 source = ui.configsource(section, name) | |
43 print('%s.%s=%s # %s' % (section, name, value, source)) | |
44 print('') | |
45 | |
46 # environment variable overrides | |
47 printconfigs({}) | |
48 printconfigs({'EDITOR': 'e2', 'PAGER': 'p2'}) |