test-config-env.py
50 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
/ tests / test-config-env.py
|
r31685 | # Test the config layer generated by environment variables | ||
from __future__ import absolute_import, print_function | ||||
import os | ||||
from mercurial import ( | ||||
encoding, | ||||
rcutil, | ||||
ui as uimod, | ||||
|
r31857 | util, | ||
|
r31685 | ) | ||
|
r36748 | testtmp = encoding.environ[b'TESTTMP'] | ||
|
r31685 | |||
# prepare hgrc files | ||||
def join(name): | ||||
return os.path.join(testtmp, name) | ||||
|
r36748 | with open(join(b'sysrc'), 'wb') as f: | ||
f.write(b'[ui]\neditor=e0\n[pager]\npager=p0\n') | ||||
|
r31685 | |||
|
r36748 | with open(join(b'userrc'), 'wb') as f: | ||
f.write(b'[ui]\neditor=e1') | ||||
|
r31685 | |||
# replace rcpath functions so they point to the files above | ||||
def systemrcpath(): | ||||
|
r36748 | return [join(b'sysrc')] | ||
|
r31685 | |||
def userrcpath(): | ||||
|
r36748 | return [join(b'userrc')] | ||
|
r31685 | |||
rcutil.systemrcpath = systemrcpath | ||||
rcutil.userrcpath = userrcpath | ||||
os.path.isdir = lambda x: False # hack: do not load default.d/*.rc | ||||
# utility to print configs | ||||
def printconfigs(env): | ||||
encoding.environ = env | ||||
rcutil._rccomponents = None # reset cache | ||||
ui = uimod.ui.load() | ||||
for section, name, value in ui.walkconfig(): | ||||
source = ui.configsource(section, name) | ||||
|
r36748 | util.stdout.write(b'%s.%s=%s # %s\n' | ||
% (section, name, value, util.pconvert(source))) | ||||
util.stdout.write(b'\n') | ||||
|
r31685 | |||
# environment variable overrides | ||||
printconfigs({}) | ||||
|
r36748 | printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'}) | ||