allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/2] git commit: [#5699] move utils tests into same file; diff test in its own file
Date Tue, 29 Jan 2013 03:54:15 GMT
Updated Branches:
  refs/heads/db/5699 [created] 1b8d1d093


[#5699] move utils tests into same file; diff test in its own file


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/1b8d1d09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1b8d1d09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1b8d1d09

Branch: refs/heads/db/5699
Commit: 1b8d1d09300e7aefb8d532091e1b7502cfe2cc72
Parents: 63347da
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Tue Jan 29 03:51:23 2013 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Jan 29 03:51:23 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/test_diff.py       |  122 +++++++++++++++++++++
 Allura/allura/tests/test_utils.py      |   45 +++++++-
 Allura/allura/tests/unit/test_utils.py |  158 ---------------------------
 3 files changed, 163 insertions(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b8d1d09/Allura/allura/tests/test_diff.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_diff.py b/Allura/allura/tests/test_diff.py
new file mode 100644
index 0000000..9dcc0c9
--- /dev/null
+++ b/Allura/allura/tests/test_diff.py
@@ -0,0 +1,122 @@
+import unittest
+
+from allura.lib.diff import HtmlSideBySideDiff
+
+
+class TestHtmlSideBySideDiff(unittest.TestCase):
+
+    def setUp(self):
+        self.diff = HtmlSideBySideDiff()
+
+    def test_render_change(self):
+        html = self.diff._render_change(
+                'aline', 'aline <span class="diff-add">bline</span>',
+                1, 2,'aclass', 'bclass')
+        expected = '''
+<tr>
+  <td class="lineno">1</td>
+  <td class="aclass"><pre>aline</pre></td>
+  <td class="lineno">2</td>
+  <td class="bclass"><pre>aline <span class="diff-add">bline</span></pre></td>
+</tr>'''.strip()
+        self.assertEqual(html, expected)
+
+    def test_render_change_default_args(self):
+        html = self.diff._render_change('aline', 'bline')
+        expected = '''
+<tr>
+  <td class="lineno"></td>
+  <td><pre>aline</pre></td>
+  <td class="lineno"></td>
+  <td><pre>bline</pre></td>
+</tr>'''.strip()
+        self.assertEqual(html, expected)
+
+    def test_preprocess(self):
+        d = self.diff
+        self.assertEquals(d._preprocess(None), None)
+        self.assertEquals(d._preprocess('<br>&nbsp;'), '&lt;br&gt;&amp;nbsp;')
+        self.assertEquals(d._preprocess('\ttabbed'), '    tabbed')
+        # test non default tab size
+        d = HtmlSideBySideDiff(2)
+        self.assertEquals(d._preprocess('\ttabbed'), '  tabbed')
+
+    def test_replace_marks(self):
+        line, flag = self.diff._replace_marks('\0+line added\1')
+        self.assertEquals(line, 'line added')
+        self.assertEquals(flag, 'diff-add')
+        line, flag = self.diff._replace_marks('\0-line removed\1')
+        self.assertEquals(line, 'line removed')
+        self.assertEquals(flag, 'diff-rem')
+        line, flag = self.diff._replace_marks('\0^line changed\1')
+        self.assertEquals(line, '<span class="diff-chg">line changed</span>')
+        self.assertEquals(flag, 'diff-chg')
+        line, flag = self.diff._replace_marks('chunk \0+add\1ed')
+        self.assertEquals(line, 'chunk <span class="diff-add">add</span>ed')
+        self.assertEquals(flag, 'diff-chg')
+        line, flag = self.diff._replace_marks('chunk \0-remov\1ed')
+        self.assertEquals(line, 'chunk <span class="diff-rem">remov</span>ed')
+        self.assertEquals(flag, 'diff-chg')
+        line, flag = self.diff._replace_marks('chunk \0^chang\1ed')
+        self.assertEquals(line, 'chunk <span class="diff-chg">chang</span>ed')
+        self.assertEquals(flag, 'diff-chg')
+
+    def test_make_line(self):
+        # context separation
+        d = (None, None, None)
+        expected = '''
+<tr>
+  <td class="lineno"></td>
+  <td class="diff-gap"><pre>...</pre></td>
+  <td class="lineno"></td>
+  <td class="diff-gap"><pre>...</pre></td>
+</tr>'''.strip()
+        self.assertEquals(self.diff._make_line(d), expected)
+        # no change
+        d = ((1, 'aline'), (1, 'aline'), False)
+        expected = '''
+<tr>
+  <td class="lineno">1</td>
+  <td><pre>aline</pre></td>
+  <td class="lineno">1</td>
+  <td><pre>aline</pre></td>
+</tr>'''.strip()
+        self.assertEquals(self.diff._make_line(d), expected)
+        # has change
+        d = ((1, '\0^a\1line'), (1, '\0^b\1line'), True)
+        expected = '''
+<tr>
+  <td class="lineno">1</td>
+  <td class="diff-chg"><pre><span class="diff-chg">a</span>line</pre></td>
+  <td class="lineno">1</td>
+  <td class="diff-chg"><pre><span class="diff-chg">b</span>line</pre></td>
+</tr>'''.strip()
+        self.assertEquals(self.diff._make_line(d), expected)
+
+    def test_make_table(self):
+        a = 'line 1\nline 2'.split('\n')
+        b = 'changed line 1\nchanged line 2'.split('\n')
+        expected = '''
+<table class="side-by-side-diff">
+  <thead>
+    <th class="lineno"></th>
+    <th>file a</th>
+    <th class="lineno"></th>
+    <th>file b</th>
+  </thead>
+<tr>
+  <td class="lineno">1</td>
+  <td class="diff-rem"><pre>line 1</pre></td>
+  <td class="lineno">1</td>
+  <td class="diff-add"><pre>changed line 1</pre></td>
+</tr>
+<tr>
+  <td class="lineno">2</td>
+  <td class="diff-rem"><pre>line 2</pre></td>
+  <td class="lineno">2</td>
+  <td class="diff-add"><pre>changed line 2</pre></td>
+</tr>
+</table>
+'''.strip()
+        html = self.diff.make_table(a, b, 'file a', 'file b')
+        self.assertEquals(html, expected)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b8d1d09/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 62a01b8..18de6f4 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -5,16 +5,15 @@ from os import path
 
 import pylons
 from webob import Request
-
+from mock import Mock
 from pygments import highlight
-from pygments.lexers import PythonLexer, get_lexer_for_filename
-from pygments.formatters import HtmlFormatter
+from pygments.lexers import get_lexer_for_filename
 
-from ming.orm import state
 from alluratest.controller import setup_unit_test
 
 from allura.lib import utils
 
+
 class TestChunkedIterator(unittest.TestCase):
 
     def setUp(self):
@@ -30,6 +29,16 @@ class TestChunkedIterator(unittest.TestCase):
         assert len(chunks) > 1, chunks
         assert len(chunks[0]) == 2, chunks[0]
 
+
+class TestChunkedList(unittest.TestCase):
+    def test_chunked_list(self):
+        l = range(10)
+        chunks = list(utils.chunked_list(l, 3))
+        self.assertEqual(len(chunks), 4)
+        self.assertEqual(len(chunks[0]), 3)
+        self.assertEqual([el for sublist in chunks for el in sublist], l)
+
+
 class TestAntispam(unittest.TestCase):
 
     def setUp(self):
@@ -102,6 +111,7 @@ class TestTruthyCallable(unittest.TestCase):
         assert bool(true_predicate) == True
         assert bool(false_predicate) == False
 
+
 class TestCaseInsensitiveDict(unittest.TestCase):
 
     def test_everything(self):
@@ -120,6 +130,7 @@ class TestCaseInsensitiveDict(unittest.TestCase):
         assert d != dict(Foo=1, bar=2)
         assert d == utils.CaseInsensitiveDict(Foo=1, bar=2)
 
+
 class TestLineAnchorCodeHtmlFormatter(unittest.TestCase):
     def test_render(self):
         code = '#!/usr/bin/env python\n'\
@@ -143,3 +154,29 @@ class TestIsTextFile(unittest.TestCase):
         assert not utils.is_text_file(open(path.join(
             here_dir,
             'data/test_mime/bin_file')).read())
+
+
+class TestCodeStats(unittest.TestCase):
+
+    def setUp(self):
+        setup_unit_test()
+
+    def test_generate_code_stats(self):
+        blob = Mock()
+        blob.text = \
+"""class Person(object):
+
+    def __init__(self, name='Alice'):
+        self.name = name
+
+    def greetings(self):
+        print "Hello, %s" % self.name
+\t\t"""
+        blob.size = len(blob.text)
+
+        stats = utils.generate_code_stats(blob)
+        assert stats['line_count'] == 8
+        assert stats['data_line_count'] == 5
+        assert stats['code_size'] == len(blob.text)
+
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1b8d1d09/Allura/allura/tests/unit/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_utils.py b/Allura/allura/tests/unit/test_utils.py
deleted file mode 100644
index e7e6338..0000000
--- a/Allura/allura/tests/unit/test_utils.py
+++ /dev/null
@@ -1,158 +0,0 @@
-import unittest
-from mock import Mock
-
-from alluratest.controller import setup_unit_test
-from allura.lib.utils import generate_code_stats, chunked_list
-from allura.lib.diff import HtmlSideBySideDiff
-
-
-class TestCodeStats(unittest.TestCase):
-
-    def setUp(self):
-        setup_unit_test()
-
-    def test_generate_code_stats(self):
-        blob = Mock()
-        blob.text = \
-"""class Person(object):
-
-    def __init__(self, name='Alice'):
-        self.name = name
-
-    def greetings(self):
-        print "Hello, %s" % self.name
-\t\t"""
-        blob.size = len(blob.text)
-
-        stats = generate_code_stats(blob)
-        assert stats['line_count'] == 8
-        assert stats['data_line_count'] == 5
-        assert stats['code_size'] == len(blob.text)
-
-
-class TestUtils(unittest.TestCase):
-    def test_chunked_list(self):
-        l = range(10)
-        chunks = list(chunked_list(l, 3))
-        self.assertEqual(len(chunks), 4)
-        self.assertEqual(len(chunks[0]), 3)
-        self.assertEqual([el for sublist in chunks for el in sublist], l)
-
-
-class TestHtmlSideBySideDiff(unittest.TestCase):
-
-    def setUp(self):
-        self.diff = HtmlSideBySideDiff()
-
-    def test_render_change(self):
-        html = self.diff._render_change(
-                'aline', 'aline <span class="diff-add">bline</span>',
-                1, 2,'aclass', 'bclass')
-        expected = '''
-<tr>
-  <td class="lineno">1</td>
-  <td class="aclass"><pre>aline</pre></td>
-  <td class="lineno">2</td>
-  <td class="bclass"><pre>aline <span class="diff-add">bline</span></pre></td>
-</tr>'''.strip()
-        self.assertEqual(html, expected)
-
-    def test_render_change_default_args(self):
-        html = self.diff._render_change('aline', 'bline')
-        expected = '''
-<tr>
-  <td class="lineno"></td>
-  <td><pre>aline</pre></td>
-  <td class="lineno"></td>
-  <td><pre>bline</pre></td>
-</tr>'''.strip()
-        self.assertEqual(html, expected)
-
-    def test_preprocess(self):
-        d = self.diff
-        self.assertEquals(d._preprocess(None), None)
-        self.assertEquals(d._preprocess('<br>&nbsp;'), '&lt;br&gt;&amp;nbsp;')
-        self.assertEquals(d._preprocess('\ttabbed'), '    tabbed')
-        # test non default tab size
-        d = HtmlSideBySideDiff(2)
-        self.assertEquals(d._preprocess('\ttabbed'), '  tabbed')
-
-    def test_replace_marks(self):
-        line, flag = self.diff._replace_marks('\0+line added\1')
-        self.assertEquals(line, 'line added')
-        self.assertEquals(flag, 'diff-add')
-        line, flag = self.diff._replace_marks('\0-line removed\1')
-        self.assertEquals(line, 'line removed')
-        self.assertEquals(flag, 'diff-rem')
-        line, flag = self.diff._replace_marks('\0^line changed\1')
-        self.assertEquals(line, '<span class="diff-chg">line changed</span>')
-        self.assertEquals(flag, 'diff-chg')
-        line, flag = self.diff._replace_marks('chunk \0+add\1ed')
-        self.assertEquals(line, 'chunk <span class="diff-add">add</span>ed')
-        self.assertEquals(flag, 'diff-chg')
-        line, flag = self.diff._replace_marks('chunk \0-remov\1ed')
-        self.assertEquals(line, 'chunk <span class="diff-rem">remov</span>ed')
-        self.assertEquals(flag, 'diff-chg')
-        line, flag = self.diff._replace_marks('chunk \0^chang\1ed')
-        self.assertEquals(line, 'chunk <span class="diff-chg">chang</span>ed')
-        self.assertEquals(flag, 'diff-chg')
-
-    def test_make_line(self):
-        # context separation
-        d = (None, None, None)
-        expected = '''
-<tr>
-  <td class="lineno"></td>
-  <td class="diff-gap"><pre>...</pre></td>
-  <td class="lineno"></td>
-  <td class="diff-gap"><pre>...</pre></td>
-</tr>'''.strip()
-        self.assertEquals(self.diff._make_line(d), expected)
-        # no change
-        d = ((1, 'aline'), (1, 'aline'), False)
-        expected = '''
-<tr>
-  <td class="lineno">1</td>
-  <td><pre>aline</pre></td>
-  <td class="lineno">1</td>
-  <td><pre>aline</pre></td>
-</tr>'''.strip()
-        self.assertEquals(self.diff._make_line(d), expected)
-        # has change
-        d = ((1, '\0^a\1line'), (1, '\0^b\1line'), True)
-        expected = '''
-<tr>
-  <td class="lineno">1</td>
-  <td class="diff-chg"><pre><span class="diff-chg">a</span>line</pre></td>
-  <td class="lineno">1</td>
-  <td class="diff-chg"><pre><span class="diff-chg">b</span>line</pre></td>
-</tr>'''.strip()
-        self.assertEquals(self.diff._make_line(d), expected)
-
-    def test_make_table(self):
-        a = 'line 1\nline 2'.split('\n')
-        b = 'changed line 1\nchanged line 2'.split('\n')
-        expected = '''
-<table class="side-by-side-diff">
-  <thead>
-    <th class="lineno"></th>
-    <th>file a</th>
-    <th class="lineno"></th>
-    <th>file b</th>
-  </thead>
-<tr>
-  <td class="lineno">1</td>
-  <td class="diff-rem"><pre>line 1</pre></td>
-  <td class="lineno">1</td>
-  <td class="diff-add"><pre>changed line 1</pre></td>
-</tr>
-<tr>
-  <td class="lineno">2</td>
-  <td class="diff-rem"><pre>line 2</pre></td>
-  <td class="lineno">2</td>
-  <td class="diff-add"><pre>changed line 2</pre></td>
-</tr>
-</table>
-'''.strip()
-        html = self.diff.make_table(a, b, 'file a', 'file b')
-        self.assertEquals(html, expected)


Mime
View raw message