author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 06 Jul 2010 22:58:02 -0400 |
parents |
01a47fb22911 |
children |
bef3dce04be6 |
import time
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with
from util import get_identifiers, check_comment_exists_on_line
from .. import messages
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_invalid():
should_fail_with(messages.UNKNOWN_ID % 'z', edit='z')
review(comment=True, message='test')
should_fail_with(messages.UNKNOWN_ID % 'z', edit='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.AMBIGUOUS_ID % i, edit=i)
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_touch_comment():
def t(rev):
review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
i = get_identifiers(rev)[0]
# This sucks, but we need to do it to support testing "touch" edits.
time.sleep(1.1)
output = review(edit=i)
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' in output
check_comment_exists_on_line(1, files=['always_changing'], rev='1')
t('1')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_comment_message():
def t(rev):
review(rev=rev, comment=True, message='test')
i = get_identifiers(rev)[0]
output = review(edit=i, message='edited')
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' not in output
assert messages.REVIEW_LOG_COMMENT_LINE % 'edited' in output
t('.')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_comment_lines():
def t(rev):
review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
i = get_identifiers(rev)[0]
output = review(edit=i, lines='3')
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' in output
check_comment_exists_on_line(3, files=['always_changing'], rev=rev)
i = get_identifiers(rev)[0]
output = review(edit=i, lines='1,2')
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' in output
check_comment_exists_on_line(2, files=['always_changing'], rev=rev)
t('1')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_comment_filename():
def t(rev):
review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
i = get_identifiers(rev)[0]
output = review(edit=i, args=['always_changing2'])
assert not output
output = review(rev=rev, verbose=True, args=['always_changing'])
assert '(%s)' % i not in output
assert len(get_identifiers(rev, files=['always_changing'])) == 0
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' not in output
output = review(rev=rev, verbose=True, args=['always_changing2'])
assert '(%s)' % i not in output
assert len(get_identifiers(rev, files=['always_changing2'])) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' in output
t('1')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_comment_everything():
def t(rev):
review(rev=rev, comment=True, message='test', args=['always_changing'], lines='1')
i = get_identifiers(rev)[0]
output = review(edit=i, args=['always_changing2'], message='edited', lines='2')
assert not output
output = review(rev=rev, verbose=True, args=['always_changing'])
assert '(%s)' % i not in output
assert len(get_identifiers(rev, files=['always_changing'])) == 0
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' not in output
output = review(rev=rev, verbose=True, args=['always_changing2'])
assert '(%s)' % i not in output
assert len(get_identifiers(rev, files=['always_changing2'])) == 1
assert messages.REVIEW_LOG_COMMENT_LINE % 'test' not in output
assert messages.REVIEW_LOG_COMMENT_LINE % 'edited' in output
check_comment_exists_on_line(2, files=['always_changing'], rev=rev)
t('1')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_touch_signoff():
def t(rev):
review(rev=rev, signoff=True, message='test', yes=True)
i = get_identifiers(rev)[0]
# This sucks, but we need to do it to support testing "touch" edits.
time.sleep(1.1)
output = review(edit=i)
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'test' in output
assert 'yes' in output
t('1')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_signoff_message():
def t(rev):
review(rev=rev, signoff=True, message='test')
i = get_identifiers(rev)[0]
output = review(edit=i, message='edited')
assert not output
output = review(rev=rev, verbose=True)
assert '(%s)' % i not in output
assert len(get_identifiers(rev)) == 1
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'test' not in output
assert messages.REVIEW_LOG_SIGNOFF_LINE % 'edited' in output
t('.')
t('0')
@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_edit_signoff_opinion():
def t(rev):
review(rev=rev, signoff=True, message='test')
output = review(rev=rev, verbose=True)
assert 'as yes' not in output
assert 'as neutral' in output
assert 'as no' not in output
i = get_identifiers(rev)[0]
output = review(edit=i, yes=True)
assert not output
output = review(rev=rev, verbose=True)
assert 'as yes' in output
assert 'as neutral' not in output
assert 'as no' not in output
i = get_identifiers(rev)[0]
output = review(edit=i, no=True)
assert not output
output = review(rev=rev, verbose=True)
assert 'as yes' not in output
assert 'as neutral' not in output
assert 'as no' in output
t('.')
t('0')