def test_diff(self, diff_fixture): with open(os.path.join(FIXTURES, diff_fixture)) as f: diff = f.read() diff_proc = DiffProcessor(diff) diff_proc_d = diff_proc.prepare() data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d] expected_data = DIFF_FIXTURES[diff_fixture] self.assertListEqual(expected_data, data)
def _diff_checker(fixture): with open(os.path.join(FIXTURES, fixture)) as f: diff = f.read() diff_proc = DiffProcessor(diff) diff_proc_d = diff_proc.prepare() data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d] expected_data = DIFF_FIXTURES[fixture] assert expected_data == data
def __changes(self, cs): changes = [] _diff = cs.diff() # we need to protect from parsing huge diffs here other way # we can kill the server, 32*1024 chars is a reasonable limit HUGE_DIFF = 32 * 1024 if len(_diff) > HUGE_DIFF: changes = ['\n ' + _('Changeset was too big and was cut off...')] return changes diffprocessor = DiffProcessor(_diff) stats = diffprocessor.prepare(inline_diff=False) for st in stats: st.update({'added': st['stats'][0], 'removed': st['stats'][1]}) changes.append('\n %(operation)s %(filename)s ' '(%(added)s lines added, %(removed)s lines removed)' % st) return changes
def __changes(self, cs): changes = [] diff_processor = DiffProcessor(cs.diff(), diff_limit=self.feed_diff_limit) _parsed = diff_processor.prepare(inline_diff=False) limited_diff = False if isinstance(_parsed, LimitedDiffContainer): limited_diff = True for st in _parsed: st.update({'added': st['stats']['added'], 'removed': st['stats']['deleted']}) changes.append('\n %(operation)s %(filename)s ' '(%(added)s lines added, %(removed)s lines removed)' % st) if limited_diff: changes = changes + ['\n ' + _('Changeset was too big and was cut off...')] return diff_processor, changes
def test_diff_lib(diff_fixture): diff, expected_data = diff_fixture diff_proc = DiffProcessor(diff) diff_proc_d = diff_proc.prepare() data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d] assert expected_data == data
def test_diffprocessor_as_html_with_comments(): raw_diff = textwrap.dedent(''' diff --git a/setup.py b/setup.py index 5b36422..cfd698e 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ #!/usr/bin/python # Setup file for X # Copyright (C) No one - +x try: from setuptools import setup, Extension except ImportError: ''') diff = GitDiff(raw_diff) processor = DiffProcessor(diff) processor.prepare() # Note that the cell with the context in line 5 (in the html) has the # no-comment class, which will prevent the add comment icon to be displayed. expected_html = textwrap.dedent(''' <table class="code-difftable"> <tr class="line context"> <td class="add-comment-line"><span class="add-comment-content"></span></td> <td class="lineno old">...</td> <td class="lineno new">...</td> <td class="code no-comment"> <pre>@@ -2,7 +2,7 @@ </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o2" class="lineno old"><a href="#setuppy_o2">2</a></td> <td id="setuppy_n2" class="lineno new"><a href="#setuppy_n2">2</a></td> <td class="code"> <pre>#!/usr/bin/python </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o3" class="lineno old"><a href="#setuppy_o3">3</a></td> <td id="setuppy_n3" class="lineno new"><a href="#setuppy_n3">3</a></td> <td class="code"> <pre># Setup file for X </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o4" class="lineno old"><a href="#setuppy_o4">4</a></td> <td id="setuppy_n4" class="lineno new"><a href="#setuppy_n4">4</a></td> <td class="code"> <pre># Copyright (C) No one </pre> </td> </tr> <tr class="line del"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o5" class="lineno old"><a href="#setuppy_o5">5</a></td> <td class="lineno new"><a href="#setuppy_n"></a></td> <td class="code"> <pre> </pre> </td> </tr> <tr class="line add"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td class="lineno old"><a href="#setuppy_o"></a></td> <td id="setuppy_n5" class="lineno new"><a href="#setuppy_n5">5</a></td> <td class="code"> <pre><ins>x</ins> </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o6" class="lineno old"><a href="#setuppy_o6">6</a></td> <td id="setuppy_n6" class="lineno new"><a href="#setuppy_n6">6</a></td> <td class="code"> <pre>try: </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o7" class="lineno old"><a href="#setuppy_o7">7</a></td> <td id="setuppy_n7" class="lineno new"><a href="#setuppy_n7">7</a></td> <td class="code"> <pre> from setuptools import setup, Extension </pre> </td> </tr> <tr class="line unmod"> <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td> <td id="setuppy_o8" class="lineno old"><a href="#setuppy_o8">8</a></td> <td id="setuppy_n8" class="lineno new"><a href="#setuppy_n8">8</a></td> <td class="code"> <pre>except ImportError: </pre> </td> </tr> </table> ''').strip() html = processor.as_html(enable_comments=True).replace('\t', ' ') assert html == expected_html
def processor(self, raw_diff): diff = MercurialDiff(raw_diff) processor = DiffProcessor(diff) return processor