Skip to content
Snippets Groups Projects
Commit 9e636c1c authored by Georges Racinet's avatar Georges Racinet
Browse files

testhelpers: config facilities

and demonstrating them in tests.
Checked also that hgrc is properly read in
LocalRepoWrapper.load()
parent 1be9168c
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
NULL_ID = node.nullid NULL_ID = node.nullid
def make_ui(base_ui): def make_ui(base_ui, config=None):
# let's make sure we aren't polluted by surrounding settings # let's make sure we aren't polluted by surrounding settings
os.environ['HGRCPATH'] = '' os.environ['HGRCPATH'] = ''
if base_ui is None: if base_ui is None:
...@@ -26,8 +26,15 @@ ...@@ -26,8 +26,15 @@
# let's make sure we aren't polluted by surrounding settings # let's make sure we aren't polluted by surrounding settings
os.environ['HGRCPATH'] = '' os.environ['HGRCPATH'] = ''
if base_ui is None: if base_ui is None:
return uimod.ui.load() ui = uimod.ui.load()
return base_ui.copy() else:
ui = base_ui.copy()
if config is not None:
for section_name, section in config.items():
for item_name, item_value in section.items():
ui.setconfig(section_name, item_name, item_value,
source='tests')
return ui
class LocalRepoWrapper(object): class LocalRepoWrapper(object):
...@@ -36,6 +43,6 @@ ...@@ -36,6 +43,6 @@
self.repo = repo self.repo = repo
@classmethod @classmethod
def init(cls, path, base_ui=None): def init(cls, path, base_ui=None, config=None):
path = str(path) path = str(path)
init = cmdutil.findcmd('init', commands.table)[1][0] init = cmdutil.findcmd('init', commands.table)[1][0]
...@@ -40,7 +47,7 @@ ...@@ -40,7 +47,7 @@
path = str(path) path = str(path)
init = cmdutil.findcmd('init', commands.table)[1][0] init = cmdutil.findcmd('init', commands.table)[1][0]
ui = make_ui(base_ui) ui = make_ui(base_ui, config)
init(ui, dest=path) init(ui, dest=path)
return cls(hg.repository(ui, path)) return cls(hg.repository(ui, path))
@classmethod @classmethod
...@@ -43,6 +50,6 @@ ...@@ -43,6 +50,6 @@
init(ui, dest=path) init(ui, dest=path)
return cls(hg.repository(ui, path)) return cls(hg.repository(ui, path))
@classmethod @classmethod
def load(cls, path, base_ui=None): def load(cls, path, base_ui=None, config=None):
path = str(path) path = str(path)
...@@ -48,5 +55,5 @@ ...@@ -48,5 +55,5 @@
path = str(path) path = str(path)
ui = make_ui(base_ui) ui = make_ui(base_ui, config=config)
return cls(hg.repository(ui, path)) return cls(hg.repository(ui, path))
def write_commit(self, rpath, content=None, message=None): def write_commit(self, rpath, content=None, message=None):
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
from __future__ import absolute_import from __future__ import absolute_import
from mercurial import ( from mercurial import (
extensions, extensions,
ui as uimod,
) )
from ..testhelpers import ( from ..testhelpers import (
LocalRepoWrapper, LocalRepoWrapper,
...@@ -47,7 +48,20 @@ ...@@ -47,7 +48,20 @@
"[extensions]", "[extensions]",
"heptapod=" + HGEXT_HEPTA_SOURCE, "heptapod=" + HGEXT_HEPTA_SOURCE,
))) )))
wrapper = LocalRepoWrapper.load(tmpdir) wrapper = LocalRepoWrapper.load(tmpdir, config=dict(foo=dict(bar='17')))
exts = dict(extensions.extensions(wrapper.repo.ui))
assert_is_hepta_ext(exts.get('heptapod'))
assert wrapper.repo.ui.configint('foo', 'bar') == 17
def test_init_baseui_config_extension(tmpdir):
ui = uimod.ui.load()
ui.setconfig('foo', 'bar', 'yes', source='tests')
ui.setconfig('extensions', 'heptapod', HGEXT_HEPTA_SOURCE, source='tests')
wrapper = LocalRepoWrapper.init(tmpdir, base_ui=ui)
assert wrapper.repo.ui.configbool('foo', 'bar')
exts = dict(extensions.extensions(wrapper.repo.ui)) exts = dict(extensions.extensions(wrapper.repo.ui))
assert_is_hepta_ext(exts.get('heptapod')) assert_is_hepta_ext(exts.get('heptapod'))
...@@ -57,7 +71,11 @@ ...@@ -57,7 +71,11 @@
ui = uimod.ui.load() ui = uimod.ui.load()
ui.setconfig('foo', 'bar', 'yes', source='tests') ui.setconfig('foo', 'bar', 'yes', source='tests')
ui.setconfig('extensions', 'heptapod', HGEXT_HEPTA_SOURCE, source='tests') ui.setconfig('extensions', 'heptapod', HGEXT_HEPTA_SOURCE, source='tests')
wrapper = LocalRepoWrapper.init(tmpdir, base_ui=ui) wrapper = LocalRepoWrapper.init(
tmpdir,
config=dict(foo=dict(bar='yes'),
extensions=dict(heptapod=HGEXT_HEPTA_SOURCE),
))
assert wrapper.repo.ui.configbool('foo', 'bar') assert wrapper.repo.ui.configbool('foo', 'bar')
exts = dict(extensions.extensions(wrapper.repo.ui)) exts = dict(extensions.extensions(wrapper.repo.ui))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment