incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#6667] Fix bug in comment update parsing
Date Wed, 18 Sep 2013 21:45:58 GMT
Updated Branches:
  refs/heads/tv/6667 [created] a71f4554e


[#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/a71f4554
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a71f4554
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a71f4554

Branch: refs/heads/tv/6667
Commit: a71f4554e39572c3fd230977a9d4d99a03105aa4
Parents: a3ba16a
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Wed Sep 18 21:45:16 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Sep 18 21:45:44 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/a71f4554/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/a71f4554/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