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

testhelpers: facilities for shares

The classmethod works from a path,
wheread the instance method takes an existing
wrapper, a common use-case in such tests.
parent 49f988c0934d
No related branches found
No related tags found
1 merge request!16Support for shared repositories
......@@ -60,6 +60,35 @@
ui = make_ui(base_ui, config=config)
return cls(hg.repository(ui, path))
@classmethod
def share_from_path(cls, src_path, dest_path,
ui=None, base_ui=None, config=None,
**share_opts):
"""Create a new repo as the `share` command would do.
:param ui: if specified, will be copied and used for the new repo
creation through ``share``
:param config: only if ``ui`` is not specified, will be used to
create a new ``ui`` instance
:param base_ui: only if ``ui`` is not specified, will be used to
create a new :class:`ui` instance
:param share_opts: passed directly to :func:`hg.share()`
:return: wrapper for the new repo
"""
if ui is None:
ui = make_ui(base_ui, config=config)
else:
ui = ui.copy()
# the 'share' command defined by the 'share' extension, is just a thin
# wrapper around `hg.share()`, which furthermore returns a repo object.
return cls(hg.share(ui, str(src_path), dest=str(dest_path),
**share_opts))
def share(self, dest_path, **share_opts):
return self.share_from_path(self.repo.root, dest_path,
ui=self.repo.ui, **share_opts)
def command(self, name, *args, **kwargs):
cmd = cmdutil.findcmd(name, commands.table)[1][0]
repo = self.repo
......
......@@ -22,6 +22,9 @@
HGEXT_HEPTA_SOURCE = dirname(hgext3rd.heptapod.__file__)
parametrize = pytest.mark.parametrize
def test_init_write_commit(tmpdir):
wrapper = LocalRepoWrapper.init(tmpdir)
node = wrapper.write_commit('foo', content='Foo', message='Foo committed')
......@@ -103,6 +106,30 @@
assert foo.read() == 'Foo 1'
@parametrize('meth', ['class', 'instance'])
def test_share(tmpdir, meth):
main_path = tmpdir.join('main')
dest_path = tmpdir.join('dest')
main_wrapper = LocalRepoWrapper.init(main_path)
node0 = main_wrapper.write_commit('foo', message='Done in main')
if meth == 'class':
dest_wrapper = LocalRepoWrapper.share_from_path(main_path, dest_path)
else:
dest_wrapper = main_wrapper.share(dest_path)
dest_ctx = dest_wrapper.repo[node0]
assert dest_ctx.description() == 'Done in main'
node1 = dest_wrapper.write_commit(
'foo', message='Done in dest', parent=node0)
# we need to reload the main repo to see the new changeset
reloaded = LocalRepoWrapper.load(main_path)
main_ctx = reloaded.repo[node1]
assert main_ctx.description() == 'Done in dest'
def test_write_commit_named_branch(tmpdir):
"""Demonstrate the use of write_commit with parent."""
wrapper = LocalRepoWrapper.init(tmpdir)
......
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