69bbcf7f0830

Add some simple tests for the contextualized diffs.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 09 Oct 2009 23:20:44 -0400
parents d32fa8336dc2
children dd45f9a0b74b
branches/tags (none)
files review/extension_ui.py review/tests/sample_data.py review/tests/test_diffs.py

Changes

--- 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),
--- 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
--- /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