--- a/tests/test_branch.py Fri Nov 27 14:19:35 2009 -0500
+++ b/tests/test_branch.py Fri Nov 27 14:54:19 2009 -0500
@@ -2,7 +2,6 @@
from nose import *
from util import *
-from mercurial import commands
@with_setup(setup_sandbox, teardown_sandbox)
@@ -16,7 +15,7 @@
@with_setup(setup_sandbox, teardown_sandbox)
def test_non_default_branch():
- commands.branch(get_sandbox_ui(), get_sandbox_repo(), 'test')
+ hg_branch('test')
output = prompt(fs='{branch}')
assert output == 'test'
@@ -33,7 +32,7 @@
output = prompt(fs='{on {branch|quiet}}')
assert output == ''
- commands.branch(get_sandbox_ui(), get_sandbox_repo(), 'test')
+ hg_branch('test')
output = prompt(fs='{branch|quiet}')
assert output == 'test'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_node.py Fri Nov 27 14:54:19 2009 -0500
@@ -0,0 +1,74 @@
+'''Test output of {node}.'''
+
+import os
+from nose import *
+from util import *
+
+
+def _parent_node():
+ opts = { 'template': '{node}', 'rev': '.', 'date': None, 'user': None }
+
+ _ui = get_sandbox_ui()
+ _ui.pushbuffer()
+ commands.log(_ui, get_sandbox_repo(), **opts)
+
+ return _ui.popbuffer()
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_node():
+ output = prompt(fs='{node}')
+ assert output == '0000000000000000000000000000000000000000'
+
+ output = prompt(fs='{ at node {node}}')
+ assert output == ' at node 0000000000000000000000000000000000000000'
+
+ hg_commit()
+ output = prompt(fs='{node}')
+ assert output == _parent_node()
+
+ hg_commit()
+ output = prompt(fs='{node}')
+ assert output == _parent_node()
+
+ hg_update(0)
+ output = prompt(fs='{node}')
+ assert output == _parent_node()
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_short_filter():
+ output = prompt(fs='{node|short}')
+ assert output == '0000000000000000000000000000000000000000'[:12]
+
+ output = prompt(fs='{ at node {node|short}}')
+ assert output == ' at node ' + '0000000000000000000000000000000000000000'[:12]
+
+ hg_commit()
+ output = prompt(fs='{node|short}')
+ assert output == _parent_node()[:12]
+
+ hg_commit()
+ output = prompt(fs='{node|short}')
+ assert output == _parent_node()[:12]
+
+ hg_update(0)
+ output = prompt(fs='{node|short}')
+ assert output == _parent_node()[:12]
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_merge_filter():
+ hg_commit('one.txt')
+ hg_commit('one.txt')
+ node_to_merge = _parent_node()
+
+ hg_update(0)
+ hg_commit('two.txt')
+ hg_merge(1)
+
+ output = prompt(fs='{node|merge}')
+ assert output == node_to_merge
+
+ output = prompt(fs='{node|merge|short}')
+ assert output == node_to_merge[:12]
--- a/tests/util.py Fri Nov 27 14:19:35 2009 -0500
+++ b/tests/util.py Fri Nov 27 14:54:19 2009 -0500
@@ -16,6 +16,7 @@
print output
return output
+
sandbox_path = os.path.join(os.path.realpath('.'), 'sandbox')
def setup_sandbox():
@@ -32,4 +33,26 @@
return hg.repository(_ui, sandbox_path)
def get_sandbox_ui():
- return _ui
\ No newline at end of file
+ return _ui
+
+
+# Mercurial command wrappers
+
+def hg_branch(branch='test'):
+ commands.branch(_ui, get_sandbox_repo(), branch)
+
+def hg_update(rev):
+ opts = { 'rev': str(rev) }
+ commands.update(_ui, get_sandbox_repo(), **opts)
+
+def hg_merge(rev):
+ opts = { 'rev': str(rev) }
+ commands.merge(_ui, get_sandbox_repo(), **opts)
+
+def hg_commit(filename='text.txt'):
+ with open(os.path.join(sandbox_path, filename), 'a') as test_file:
+ test_file.writelines(['test', '.'])
+
+ opts = { 'addremove': True, 'date': None, 'user': 'Prompt Tester',
+ 'logfile': None, 'message': "Sandbox commit." }
+ commands.commit(get_sandbox_ui(), get_sandbox_repo(), **opts)