review/tests/test_diffs.py @ a0929b448985

web: sometimes I hate you, vim
author Steve Losh <steve@stevelosh.com>
date Tue, 20 Jul 2010 19:11:50 -0400
parents fe2edf9c9098
children bef3dce04be6
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review

from .. import messages

a1, a2 = (messages.REVIEW_LOG_COMMENT_AUTHOR % '|').split('|')
s1, s2 = (messages.REVIEW_LOG_SKIPPED % 1111).split('1111')

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_review_diff_default_context():
    output = review(rev='1', args=['long_file'], unified='5')

    assert ' 0:' not in output
    assert messages.REVIEW_LOG_SKIPPED % 1 in output

    for n in range(1, 20):
        assert '%2d:' % n in output

    assert '-g' in output
    assert '+X' in output
    assert '-m' in output
    assert '+Y' in output

    assert '20:' not in output
    assert messages.REVIEW_LOG_SKIPPED % 2 in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_review_diff_full_context():
    output = review(rev='1', args=['long_file'], unified='10000')

    assert s1 not in output
    assert s2 not in output

    for n in range(0, 21):
        assert '%2d:' % n in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_review_diff_small_context():
    output = review(rev='1', args=['long_file'], unified='2')

    assert ' 3:' not in output
    assert messages.REVIEW_LOG_SKIPPED % 4 in output

    assert '-g' in output
    assert '+X' in output

    assert '10:' not in output
    assert messages.REVIEW_LOG_SKIPPED % 2 in output

    assert '-m' in output
    assert '+Y' in output

    assert '17:' not in output
    assert messages.REVIEW_LOG_SKIPPED % 5 in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_review_diff_with_comment():
    review(comment=True, rev='1', message='Test comment one.',
        args=['long_file'], lines='6,7')

    output = review(rev='1', args=['long_file'], unified=0)

    # Make sure the comment is present at all.
    assert a1 in output
    assert a2 in output
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output

    # Make sure it's in the correct place
    output = output.splitlines()
    for n, line in enumerate(output):
        if line.startswith('#'):
            assert output[n-1].strip().startswith('7')
            break

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_review_diff_with_skipped_comment():
    review(comment=True, rev='1', message='Test comment one.',
        args=['long_file'], lines='3')

    output = review(rev='1', args=['long_file'], unified=0)

    # Make sure the comment is present at all.
    assert a1 in output
    assert a2 in output
    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output

    # Make sure it's in the correct place
    output = output.splitlines()
    for n, line in enumerate(output):
        if line.startswith('#'):
            assert output[n-1].startswith(s1)
            assert output[n-1].endswith(s2.strip())
            break