]> git.scottworley.com Git - paperdoorknob/blobdiff - glowfic_test.py
More structure and tests around splitting the page into chunks' DOMs.
[paperdoorknob] / glowfic_test.py
diff --git a/glowfic_test.py b/glowfic_test.py
new file mode 100644 (file)
index 0000000..d847333
--- /dev/null
@@ -0,0 +1,50 @@
+# paperdoorknob: Print glowfic
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3.
+
+
+import unittest
+
+from bs4 import BeautifulSoup
+
+from glowfic import chunkDOMs
+
+
+class TestSplit(unittest.TestCase):
+
+    def testSplit1(self) -> None:
+        soup = BeautifulSoup(b'''
+            <html><body><div class="post-container post-post">
+              The "post"
+            </div></body></html>''', 'html.parser')
+        self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
+                         [['The "post"']])
+
+    def testSplit2(self) -> None:
+        soup = BeautifulSoup(b'''
+            <html><body>
+              <div class="post-container post-post">The "post"</div>
+              <div class="flat-post-replies">
+                <div class="post-container post-reply">The "reply"</div>
+              </div>
+            </body></html>''', 'html.parser')
+        self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
+                         [['The "post"'], ['The "reply"']])
+
+    def testSplit3(self) -> None:
+        soup = BeautifulSoup(b'''
+            <html><body>
+              <div class="post-container post-post">The "post"</div>
+              <div class="flat-post-replies">
+                <div class="post-container post-reply">1st reply</div>
+                <div class="post-container post-reply">2nd reply</div>
+              </div>
+            </body></html>''', 'html.parser')
+        self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
+                         [['The "post"'], ['1st reply'], ['2nd reply']])
+
+
+if __name__ == '__main__':
+    unittest.main()