author |
Steve Losh <steve@stevelosh.com> |
date |
Sat, 19 Jun 2010 02:03:37 -0400 |
parents |
(none) |
children |
40e13965af72 |
from nose import *
from util import *
from .. import api, messages
from mercurial import util as hgutil
a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
s1, s2 = (messages.REVIEW_LOG_SIGNOFF_AUTHOR % ('|', 'neutral')).split('|')
def _get_identifiers(rev='.'):
return [l.split(' ')[-1].strip('()\n')
for l in review(rev=rev, verbose=True).splitlines()
if (a1 in l and a2 in l) or (s1 in l and s2 in l)]
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_delete_invalid():
# TODO: rename files.
try:
review(delete=True)
except hgutil.Abort, e:
error = str(e)
assert messages.DELETE_REQUIRES_IDS in error
else:
assert False, 'The correct error message was not printed.'
try:
review(delete=True, files=['a'])
except hgutil.Abort, e:
error = str(e)
assert messages.DELETE_UNKNOWN_ID % 'a' in error
else:
assert False, 'The correct error message was not printed.'
review(comment=True, message='test')
try:
review(delete=True, files=['z'])
except hgutil.Abort, e:
error = str(e)
assert messages.DELETE_UNKNOWN_ID % 'z' in error
else:
assert False, 'The correct error message was not printed.'
# Use the pidgeonhole princicple to create ambiguous identifiers.
for i in range(17):
review(comment=True, message='test%d' % i)
ids = _get_identifiers()
id_map = {}
for i in ids:
id_map[i[0]] = id_map.get(i[0], 0) + 1
i = str(filter(lambda k: id_map[k] > 1, id_map.keys())[0])
try:
review(delete=True, files=[i])
except hgutil.Abort, e:
error = str(e)
print error
assert messages.DELETE_AMBIGUOUS_ID % i in error
else:
assert False, 'The correct error message was not printed.'
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_delete_comment():
def t(rev):
review(rev=rev, comment=True, message='test')
i = _get_identifiers(rev)[0]
output = review(rev=rev, delete=True, files=[i])
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)\n' % i not in output
review(rev=rev, comment=True, message='test2')
review(rev=rev, comment=True, message='test3')
i1, i2 = _get_identifiers(rev)
output = review(rev=rev, delete=True, files=[i1])
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)\n' % i1 not in output
assert '(%s)\n' % i2 in output
review(rev=rev, comment=True, message='test4')
i1, i2 = _get_identifiers(rev)
output = review(rev=rev, delete=True, files=[i1, i2])
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)\n' % i1 not in output
assert '(%s)\n' % i2 not in output
t('.')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_delete_signoff():
# TODO: test multiple signoff deletions
review(signoff=True, message='test')
i = _get_identifiers()[0]
output = review(delete=True, files=[i])
assert not output
output = review(verbose=True)
assert '(%s)\n' % i not in output
review(comment=True, message='test2')
review(signoff=True, message='test3')
i1, i2 = _get_identifiers()
output = review(delete=True, files=[i2])
assert not output
output = review(verbose=True)
assert '(%s)\n' % i1 in output
assert '(%s)\n' % i2 not in output
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_delete_both():
def t(rev):
review(rev=rev, signoff=True, message='test')
review(rev=rev, comment=True, message='test')
ids = _get_identifiers(rev)
output = review(rev=rev, delete=True, files=ids)
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)\n' % ids[0] not in output
assert '(%s)\n' % ids[1] not in output
review(rev=rev, signoff=True, message='test2')
review(rev=rev, comment=True, message='test3')
review(rev=rev, comment=True, message='test4')
ids = _get_identifiers(rev)
output = review(rev=rev, delete=True, files=ids[:2])
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)\n' % ids[0] not in output
assert '(%s)\n' % ids[1] not in output
assert '(%s)\n' % ids[2] in output
t('.')
t('0')