from nose import *
from util import *
from mercurial import util as hgutil
from .. import messages
BAD_ERROR = 'The correct error message was not printed.'
def _check_e(e, m):
error = str(e)
assert m in e
def _should_fail_with(m, **kwargs):
try:
output = review(**kwargs)
except hgutil.Abort, e:
_check_e(e, m)
else:
assert False, BAD_ERROR
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_empty():
review(check=True)
output = review(check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(signoff=True, no=True, message='.')
output = review(check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(signoff=True, yes=False, message='.', force=True)
output = review(check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(comment=True, message='.')
output = review(check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_empty_non_tip():
review(rev='0', check=True)
output = review(rev='0', check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(signoff=False, message='.')
output = review(rev='0', check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(signoff=True, message='.')
output = review(rev='0', check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
review(comment=True, message='.')
output = review(rev='0', check=True, verbose=True)
assert messages.CHECK_SUCCESS in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_no_nos():
output = review(check=True, verbose=True, no_nos=True)
assert messages.CHECK_SUCCESS in output
review(signoff=True, no=True, message='.')
_should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True)
review(signoff=True, yes=True, message='.', force=True)
output = review(check=True, verbose=True, no_nos=True)
assert messages.CHECK_SUCCESS in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_yeses():
_should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1')
output = review(check=True, verbose=True, yeses='0')
assert messages.CHECK_SUCCESS in output
review(signoff=True, yes=True, message='.')
output = review(check=True, verbose=True, yeses='1')
assert messages.CHECK_SUCCESS in output
_should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='2')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_seen():
_should_fail_with(messages.CHECK_UNSEEN, check=True, verbose=True, seen=True)
review(signoff=True, yes=True, message='.')
output = review(check=True, verbose=True, seen=True)
assert messages.CHECK_SUCCESS in output
review(signoff=True, no=True, message='.', force=True)
output = review(check=True, verbose=True, seen=True)
assert messages.CHECK_SUCCESS in output
_should_fail_with(messages.CHECK_UNSEEN, rev='0', check=True, verbose=True, seen=True)
review(rev='0', comment=True, message='.')
output = review(check=True, verbose=True, seen=True)
assert messages.CHECK_SUCCESS in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_priority_no_nos():
review(signoff=True, no=True, message='.')
_should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, yeses='0')
_should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True)
_should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True, yeses='0')
review(signoff=True, yes=True, message='.', force=True)
output = review(check=True, verbose=True, no_nos=True, seen=True, yeses='0')
assert messages.CHECK_SUCCESS in output
review(rev='0', signoff=True, no=True, message='.')
review(rev='0', comment=True, message='.')
_should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True)
_should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True)
_should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True, yeses='0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_priority_yeses():
review(comment=True, message='.')
_should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1', seen=True)
review(signoff=True, yes=True, message='.')
output = review(check=True, verbose=True, yeses='1', seen=True)
assert messages.CHECK_SUCCESS in output
# TODO: For multiple signoffs, no_nos should take priority over "yes" signoffs.