# HG changeset patch # User Steve Losh # Date 1255144844 14400 # Node ID 69bbcf7f0830914077fd811f5db2c395f8aa811b # Parent d32fa8336dc2ff4d42293b3a05e4438975697b51 Add some simple tests for the contextualized diffs. diff -r d32fa8336dc2 -r 69bbcf7f0830 review/extension_ui.py --- a/review/extension_ui.py Fri Oct 09 22:53:11 2009 -0400 +++ b/review/extension_ui.py Fri Oct 09 23:20:44 2009 -0400 @@ -130,10 +130,12 @@ lambda c: filename == c.filename and c.lines, rcset.comments ) prefix = '%%%dd: ' % len(str(content[-1][0])) - previous_n = 0 + previous_n = -1 for n, line in content: if n - 1 > previous_n: skipped = n - previous_n + if previous_n == -1: + skipped -= 1 ui.write(messages.REVIEW_LOG_SKIPPED % skipped) skipped_comments = filter( lambda c: max(c.lines) in range(previous_n + 1, n), diff -r d32fa8336dc2 -r 69bbcf7f0830 review/tests/sample_data.py --- a/review/tests/sample_data.py Fri Oct 09 22:53:11 2009 -0400 +++ b/review/tests/sample_data.py Fri Oct 09 23:20:44 2009 -0400 @@ -1,9 +1,11 @@ log = [ { 'file_one': 'hello\nworld\nfirst\ncommit', 'file_two': 'this is another test file', + 'long_file': 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\no\np\nq\nr\ns\nt', }, { 'file_one': 'hello again\nworld\nfoo\nbar', 'file_three': 'this is a new file\nfor testing\npurposes\nonly', 'test_dir/test_file': 'this file is inside\nof a directory\n\nponies!', + 'long_file': 'a\nb\nc\nd\ne\nf\nX\nh\ni\nj\nk\nl\nY\no\np\nq\nr\ns\nt', }, ] \ No newline at end of file diff -r d32fa8336dc2 -r 69bbcf7f0830 review/tests/test_diffs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/review/tests/test_diffs.py Fri Oct 09 23:20:44 2009 -0400 @@ -0,0 +1,62 @@ +from nose import * +from util import * +from .. import messages + +import os + + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_review_diff_default_context(): + sandbox = get_sandbox_repo() + + output = review(rev='1', files=['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(): + sandbox = get_sandbox_repo() + + output = review(rev='1', files=['long_file'], unified='10000') + + s1, s2 = (messages.REVIEW_LOG_SKIPPED % 1111).split('1111') + 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(): + sandbox = get_sandbox_repo() + + output = review(rev='1', files=['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