incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [14/50] git commit: [#6667] Fix bug in comment update parsing
Date Thu, 26 Sep 2013 18:29:32 GMT
[#6667] Fix bug in comment update parsing

- Instead of iterating through all text nodes, which can break if
  there are an odd number, find the labels (<b> tags) and their
  sibling nodes (descriptions) explicitly

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/tv/6612
Commit: d83c5c29fcd80878f05b0eabe45f7daadbc4d2df
Parents: 1f712d5
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Wed Sep 18 21:45:16 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Sep 19 18:49:28 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/google/__init__.py           |  9 ++--
 .../tests/google/test_extractor.py              | 46 ++++++++++++++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d83c5c29/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index d4eb83d..1a2c5c1 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -234,12 +234,9 @@ class Comment(object):
 
     def _get_updates(self, tag):
         _updates = tag.find('div', 'updates')
-        if _updates:
-            _strings = _updates.findAll(text=True)
-            updates = (s.strip() for s in _strings if s.strip())
-            self.updates = {field: updates.next() for field in updates}
-        else:
-            self.updates = {}
+        self.updates = {
+                b.text: b.nextSibling.strip()
+                for b in _updates.findAll('b')} if _updates else {}
 
     @property
     def annotated_text(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d83c5c29/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 32b3049..4eff44f 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -284,3 +284,49 @@ class TestUserLink(TestCase):
         tag.get.return_value = '/p/project'
         link = google.UserLink(tag)
         self.assertEqual(str(link), '[name](http://code.google.com/p/project)')
+
+
+class TestComment(TestCase):
+    html = """
+    <div class="cursor_off vt issuecomment" id="hc2">
+     <div style="float:right; margin-right:.3em; text-align:right">
+     <span class="date" title="Tue Jun 25 03:20:09 2013">
+     Jun 25, 2013
+     </span>
+     </div>
+     <span class="author">
+     <span class="role_label">Project Member</span>
+     <a name="c2" href="/p/pychess/issues/detail?id=267#c2">#2</a>
+     <a class="userlink" href="/u/gbtami/">gbtami</a></span>
+    <pre><i>(No comment was entered for this change.)</i>
+    </pre>
+     <div class="updates">
+     <div class="round4"></div>
+     <div class="round2"></div>
+     <div class="round1"></div>
+     <div class="box-inner">
+     <b>Summary:</b>
+     Make PyChess keyboard accessible
+     <span class="oldvalue">
+     (was: Make PyChess keyboard accecible)
+     </span>
+     <br>
+     <b>Status:</b>
+     Accepted
+     <br>
+     </div>
+     <div class="round1"></div>
+     <div class="round2"></div>
+     <div class="round4"></div>
+     </div>
+    </div>
+    """
+
+    def test_init(self):
+        from BeautifulSoup import BeautifulSoup
+        html = BeautifulSoup(self.html)
+        comment = google.Comment(html.find('div', 'issuecomment'))
+        self.assertEqual(comment.updates, {
+            u'Summary:': u'Make PyChess keyboard accessible',
+            u'Status:': u'Accepted',
+            })


Mime
View raw message