tests/test-config-env.py
author Siddharth Agarwal <sid0@fb.com>
Sat, 10 Jun 2017 14:07:30 -0700
changeset 32769 efd6e941e933
parent 31857 08fbc97d1364
child 36730 a22915edc279
permissions -rw-r--r--
tests: add a wrapper to run fsmonitor tests This script does a bunch of non-trivial configuration work: in particular, it sets up an isolated instance of Watchman which isn't affected by global state and can be torn down on completion. This script also sets the HGFSMONITOR_TESTS environment variable, which hghave will use in the next patch to allow gating on whether fsmonitor is enabled. With fsmonitor enabled, there appear to be a number of failures in the test suite. It's not yet clear to me why they're happening, but if someone would like to jump in and fix some of them I hope this will be helpful for that.

# 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,
    util,
)

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, util.pconvert(source)))
    print('')

# environment variable overrides
printconfigs({})
printconfigs({'EDITOR': 'e2', 'PAGER': 'p2'})