author |
Steve Losh <steve@stevelosh.com> |
date |
Fri, 18 Jun 2010 21:12:56 -0400 |
parents |
d5280b38dd4c |
children |
bc5a004bfcca |
from nose import *
from util import *
from mercurial import util as hgutil
from mercurial.node import hex
from .. import messages
s1, s2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'neutral')).split('|')
sy1, sy2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'yes')).split('|')
sn1, sn2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'no')).split('|')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_no_signoffs():
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (0, 0, 0, 0) in output
# TODO: Figure out how to handle external editors nicely with nose.
#@with_setup(setup_reviewed_sandbox, teardown_sandbox)
#def test_blank_signoff():
#try:
#review(signoff=True, message=' \t\n')
#except hgutil.Abort, e:
#error = str(e)
#assert messages.SIGNOFF_REQUIRES_MESSAGE in error
#else:
#assert False, 'The correct error message was not printed.'
#try:
#review(signoff=True, message=messages.SIGNOFF_EDITOR_MESSAGE)
#except hgutil.Abort, e:
#error = str(e)
#assert messages.SIGNOFF_REQUIRES_MESSAGE in error
#else:
#assert False, 'The correct error message was not printed.'
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_formatting():
review(signoff=True, message=' \tTest signoff one.\t ')
output = review()
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.' not in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.\t ' not in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.\t ' not in output
review(rev=0, signoff=True,
message=' \tTest\n indented\n\ttabindented\noutdented \ndone\t ')
output = review(rev=0)
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test' in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % ' indented' in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % '\ttabindented' in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'outdented ' in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'done' in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_on_parent_rev():
review(signoff=True, message='Test signoff one.')
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (1, 0, 0, 1) in output
assert s1 in output
assert s1 in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_on_specific_rev():
review(signoff=True, message='Test signoff one.', rev='0')
output = review(rev='0')
assert messages.REVIEW_LOG_SIGNOFFS % (1, 0, 0, 1) in output
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (0, 0, 0, 0) in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_multiple_signoffs():
review(signoff=True, message='Test signoff one.')
try:
review(signoff=True, message='Test signoff two.')
except hgutil.Abort, e:
error = str(e)
assert messages.SIGNOFF_EXISTS in error
else:
assert False, 'The correct error message was not printed.'
review(signoff=True, message='Test signoff two.', force=True)
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (1, 0, 0, 1) in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_yes():
review(signoff=True, yes=True, message='Test signoff one.')
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (1, 1, 0, 0) in output
assert sy1 in output
assert sy1 in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_no():
review(signoff=True, no=True, message='Test signoff one.')
output = review()
assert messages.REVIEW_LOG_SIGNOFFS % (1, 0, 1, 0) in output
assert sn1 in output
assert sn1 in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_signoff_identifiers():
review(signoff=True, message='Test signoff one.', rev='0')
rd = api.ReviewDatastore(get_ui(), get_sandbox_repo())
dsr = get_datastore_repo()
signoff = rd['0'].signoffs[0]
identifier = signoff.identifier
short_identifier = identifier[:12]
signoff_filename = api._split_path_dammit(dsr['tip'].files()[0])[-1]
signoff_cset = hex(dsr['tip'].node())
assert identifier == signoff_filename
assert identifier != signoff_cset
verbose_identifier = messages.REVIEW_LOG_IDENTIFIER % identifier[:12]
debug_identifier = messages.REVIEW_LOG_IDENTIFIER % identifier
normal_output = review(rev='0')
assert verbose_identifier not in normal_output
assert debug_identifier not in normal_output
verbose_output = review(rev='0', verbose=True)
assert verbose_identifier in verbose_output
assert debug_identifier not in verbose_output
debug_output = review(rev='0', debug=True)
assert verbose_identifier not in debug_output
assert debug_identifier in debug_output