Debian Codegraph @

tests/test-config-env.py

raw
1 # Test the config layer generated by environment variables
2
3
4 import os
5
6 from mercurial import (
7 encoding,
8 extensions,
9 ui as uimod,
10 util,
11 )
12
13 from mercurial.configuration import rcutil
14 from mercurial.utils import procutil
15
16 testtmp = encoding.environ[b'TESTTMP']
17
18
19 # prepare hgrc files
20 def join(name):
21 return os.path.join(testtmp, name)
22
23
24 with open(join(b'sysrc'), 'wb') as f:
25 f.write(b'[ui]\neditor=e0\n[pager]\npager=p0\n')
26
27 with open(join(b'userrc'), 'wb') as f:
28 f.write(b'[ui]\neditor=e1')
29
30
31 # replace rcpath functions so they point to the files above
32 def systemrcpath():
33 return [join(b'sysrc')]
34
35
36 def userrcpath():
37 return [join(b'userrc')]
38
39
40 extensions.wrapfunction(rcutil, 'default_rc_resources', lambda orig: [])
41
42 rcutil.systemrcpath = systemrcpath
43 rcutil.userrcpath = userrcpath
44
45
46 # utility to print configs
47 def printconfigs(env):
48 encoding.environ = env
49 rcutil._rccomponents = None # reset cache
50 ui = uimod.ui.load()
51 for section, name, value in ui.walkconfig():
52 source = ui.configsource(section, name)
53 procutil.stdout.write(
54 b'%s.%s=%s # %s\n' % (section, name, value, util.pconvert(source))
55 )
56 procutil.stdout.write(b'\n')
57
58
59 # environment variable overrides
60 printconfigs({})
61 printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'})