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

testhelpers: implemented random content

That should help users focus a bit more on topology, at
a negligible price in speed.

The content really has to be random, to make sure
there is something to commit.
parent 6449813d3f9d
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
phases,
ui as uimod,
)
import random
# re-exports for stability
NULL_REVISION = node.nullrev
......@@ -84,4 +85,6 @@
rpath = str(rpath)
repo = self.repo
path = os.path.join(repo.root, rpath)
if parent is not None:
self.update_bin(parent)
if content is None:
......@@ -87,4 +90,6 @@
if content is None:
content = "some content that should be random"
content = "random: {}\n\nparent: {}\n".format(
random.random(),
node.hex(repo.dirstate.p1()))
if message is None:
message = content
......@@ -89,7 +94,5 @@
if message is None:
message = content
if parent is not None:
self.update_bin(parent)
if branch is not None:
self.repo.dirstate.setbranch(branch)
......
......@@ -5,6 +5,7 @@
from __future__ import absolute_import
from mercurial import (
extensions,
phases,
ui as uimod,
)
from ..testhelpers import (
......@@ -122,3 +123,30 @@
ctxbr = wrapper.repo[nodebr]
assert ctxbr.branch() == 'default'
assert [c.node() for c in ctxbr.parents()] == [node0]
def test_write_commit_random(tmpdir):
"""Demonstrate how random content is generated."""
wrapper = LocalRepoWrapper.init(tmpdir)
node0 = wrapper.write_commit('foo')
node1 = wrapper.write_commit('foo', parent=node0)
node2 = wrapper.write_commit('foo', parent=node0)
ctx1 = wrapper.repo[node1]
ctx2 = wrapper.repo[node2]
assert ctx1.p1() == ctx2.p1()
assert ctx1 != ctx2
def test_phase(tmpdir):
wrapper = LocalRepoWrapper.init(tmpdir)
node = wrapper.write_commit('foo', content='Foo 0')
ctx = wrapper.repo[node]
assert ctx.phase() == phases.draft
wrapper.set_phase('public', ['.'], force=False)
assert ctx.phase() == phases.public
wrapper.set_phase('draft', ['.'], force=True)
assert ctx.phase() == phases.draft
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