]> git.scottworley.com Git - paperdoorknob/commitdiff
entries() convenience method
authorScott Worley <scottworley@scottworley.com>
Fri, 24 Nov 2023 04:04:59 +0000 (20:04 -0800)
committerScott Worley <scottworley@scottworley.com>
Wed, 20 Dec 2023 01:37:10 +0000 (17:37 -0800)
paperdoorknob.py
paperdoorknob_test.py

index 0c6ec856b50377f1b895a2dfe2d9681badf93dba..6cc76a2f56d465fdf0c897b601dfbaa25dd86d03 100644 (file)
@@ -6,6 +6,7 @@
 
 
 from argparse import ArgumentParser
 
 
 from argparse import ArgumentParser
+import itertools
 import os.path
 
 from typing import Iterable
 import os.path
 
 from typing import Iterable
@@ -33,6 +34,9 @@ class Post:
         assert all(isinstance(r, Tag) for r in replies)
         return replies
 
         assert all(isinstance(r, Tag) for r in replies)
         return replies
 
+    def entries(self) -> Iterable[Tag]:
+        return itertools.chain([self.text()], self.replies())
+
 
 def command_line_parser() -> ArgumentParser:
     parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
 
 def command_line_parser() -> ArgumentParser:
     parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
index 7c486079818f73058a47e181de41eca4ef4e1e08..5fe17797b26336cd3c70b1e60b4889fc29e9ffd5 100644 (file)
@@ -102,6 +102,8 @@ class TestFetch(unittest.TestCase):
             self.assertEqual(post.text().text.strip(), "This is glowfic")
             self.assertEqual([r.text.strip() for r in post.replies()],
                              ["You sure?", "Pretty sure."])
             self.assertEqual(post.text().text.strip(), "This is glowfic")
             self.assertEqual([r.text.strip() for r in post.replies()],
                              ["You sure?", "Pretty sure."])
+            self.assertEqual([r.text.strip() for r in post.entries()],
+                             ["This is glowfic", "You sure?", "Pretty sure."])
 
     def testFetchErrors(self) -> None:
         with requests.session() as s:
 
     def testFetchErrors(self) -> None:
         with requests.session() as s: