Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/gumbo-parser/python/gumbo/soup_adapter_test.py @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 # Copyright 2012 Google Inc. All Rights Reserved. | |
| 2 # | |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 # you may not use this file except in compliance with the License. | |
| 5 # You may obtain a copy of the License at | |
| 6 # | |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 # | |
| 9 # Unless required by applicable law or agreed to in writing, software | |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 # See the License for the specific language governing permissions and | |
| 13 # limitations under the License. | |
| 14 # | |
| 15 """Tests for the Gumbo's BeautifulSoup Python adapter.""" | |
| 16 | |
| 17 __author__ = 'jdtang@google.com (Jonathan Tang)' | |
| 18 | |
| 19 import unittest | |
| 20 | |
| 21 import soup_adapter | |
| 22 | |
| 23 | |
| 24 class SoupAdapterTest(unittest.TestCase): | |
| 25 | |
| 26 def testSimpleParse(self): | |
| 27 soup = soup_adapter.parse( | |
| 28 """ | |
| 29 <ul> | |
| 30 <li class=odd><a href="one.html">One</a> | |
| 31 <li class="even"><a href="two.html">Two</a> | |
| 32 <li class='odd'><a href="three.html">Three</a> | |
| 33 <li class="even"><a href="four.html">Four</a> | |
| 34 </ul> | |
| 35 """) | |
| 36 | |
| 37 head = soup.head | |
| 38 self.assertEquals(soup, head.parent.parent) | |
| 39 self.assertEquals(u'head', head.name) | |
| 40 self.assertEquals(0, len(head)) | |
| 41 | |
| 42 body = soup.body | |
| 43 self.assertEquals(head, body.previousSibling) | |
| 44 self.assertEquals(2, len(body)) # <ul> + trailing whitespace | |
| 45 self.assertEquals(u'ul', body.contents[0].name) | |
| 46 self.assertEquals(body, head.next) | |
| 47 self.assertEquals(head, body.previous) | |
| 48 | |
| 49 list_items = body.findAll('li') | |
| 50 self.assertEquals(4, len(list_items)) | |
| 51 | |
| 52 evens = body('li', 'even') | |
| 53 self.assertEquals(2, len(evens)) | |
| 54 | |
| 55 a2 = body.find('a', href='two.html') | |
| 56 self.assertEquals(u'a', a2.name) | |
| 57 self.assertEquals(u'Two', a2.contents[0]) | |
| 58 self.assertEquals(a2, evens[0].next) | |
| 59 self.assertEquals(evens[0], a2.previous) | |
| 60 | |
| 61 li2 = a2.parent | |
| 62 self.assertEquals(u'li', li2.name) | |
| 63 self.assertEquals(u'even', li2['class']) | |
| 64 self.assertEquals(list_items[1], li2) | |
| 65 self.assertEquals(evens[0], li2) | |
| 66 | |
| 67 if __name__ == '__main__': | |
| 68 unittest.main() |
