test-config-env.py
54 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
/ tests / test-config-env.py
Jun Wu
|
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, | ||||
Matt Harbison
|
r31857 | util, | ||
Jun Wu
|
r31685 | ) | ||
Yuya Nishihara
|
r37137 | from mercurial.utils import ( | ||
procutil, | ||||
) | ||||
Yuya Nishihara
|
r36748 | testtmp = encoding.environ[b'TESTTMP'] | ||
Jun Wu
|
r31685 | |||
# prepare hgrc files | ||||
def join(name): | ||||
return os.path.join(testtmp, name) | ||||
Yuya Nishihara
|
r36748 | with open(join(b'sysrc'), 'wb') as f: | ||
f.write(b'[ui]\neditor=e0\n[pager]\npager=p0\n') | ||||
Jun Wu
|
r31685 | |||
Yuya Nishihara
|
r36748 | with open(join(b'userrc'), 'wb') as f: | ||
f.write(b'[ui]\neditor=e1') | ||||
Jun Wu
|
r31685 | |||
# replace rcpath functions so they point to the files above | ||||
def systemrcpath(): | ||||
Yuya Nishihara
|
r36748 | return [join(b'sysrc')] | ||
Jun Wu
|
r31685 | |||
def userrcpath(): | ||||
Yuya Nishihara
|
r36748 | return [join(b'userrc')] | ||
Jun Wu
|
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) | ||||
Yuya Nishihara
|
r37137 | procutil.stdout.write(b'%s.%s=%s # %s\n' | ||
% (section, name, value, util.pconvert(source))) | ||||
procutil.stdout.write(b'\n') | ||||
Jun Wu
|
r31685 | |||
# environment variable overrides | ||||
printconfigs({}) | ||||
Yuya Nishihara
|
r36748 | printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'}) | ||