Mercurial > public > mercurial-scm > hg-stable
diff tests/test-config-env.py @ 31690: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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-config-env.py Sun Mar 26 21:33:37 2017 -0700 @@ -0,0 +1,48 @@ +# 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, +) + +testtmp = encoding.environ['TESTTMP'] + +# prepare hgrc files +def join(name): + return os.path.join(testtmp, name) + +with open(join('sysrc'), 'w') as f: + f.write('[ui]\neditor=e0\n[pager]\npager=p0\n') + +with open(join('userrc'), 'w') as f: + f.write('[ui]\neditor=e1') + +# replace rcpath functions so they point to the files above +def systemrcpath(): + return [join('sysrc')] + +def userrcpath(): + return [join('userrc')] + +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) + print('%s.%s=%s # %s' % (section, name, value, source)) + print('') + +# environment variable overrides +printconfigs({}) +printconfigs({'EDITOR': 'e2', 'PAGER': 'p2'})