author |
Steve Losh <steve@stevelosh.com> |
date |
Sat, 19 Jun 2010 02:25:49 -0400 |
parents |
40e13965af72 |
children |
f8bca5fc564b |
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.
should_fail_with(messages.DELETE_REQUIRES_IDS, delete=True)
should_fail_with(messages.DELETE_UNKNOWN_ID % 'a', delete=True, args=['a'])
review(comment=True, message='test')
should_fail_with(messages.DELETE_UNKNOWN_ID % 'z', delete=True, args=['z'])
# 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])
should_fail_with(messages.DELETE_AMBIGUOUS_ID % i, delete=True, args=[i])
@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, args=[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, args=[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, args=[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, args=[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, args=[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, args=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, args=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')