fix markdown header writing tests
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 30 Aug 2022 04:13:03 +0000 (21:13 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 30 Aug 2022 04:13:03 +0000 (21:13 -0700)
src/budget_sync/test/test_write_budget_markdown.py
src/budget_sync/write_budget_markdown.py

index e26e92abf10c902e7800b8638aa5c3960cc90640..d832430882cbf53b533b304e9b8c8a3edd3b8040 100644 (file)
@@ -177,7 +177,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     b'    * this task is part of MoU Milestone\n'
                     b'      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n'
                     b'\n'
-                    b'#### MoU Milestone subtotals for not yet submitted payments\n'
+                    b'MoU Milestone subtotals for not yet submitted payments\n'
                     b'\n'
                     b'* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n'
                     b'  summary2\n'
@@ -208,7 +208,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     b'    * this task is part of MoU Milestone\n'
                     b'      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n'
                     b'\n'
-                    b'#### MoU Milestone subtotals for not yet submitted payments\n'
+                    b'MoU Milestone subtotals for not yet submitted payments\n'
                     b'\n'
                     b'* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n'
                     b'  summary2\n'
@@ -300,7 +300,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
             '    * this task is part of MoU Milestone\n',
             '      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n',
             '\n',
-            '#### MoU Milestone subtotals for not yet submitted payments\n',
+            'MoU Milestone subtotals for not yet submitted payments\n',
             '\n',
             '* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n',
             '  summary2\n',
index bc0a95cce7925608594a66fd020b0f32a4862d97..a6b1689ac1a26f9551cf60a902c4e48920ec4fb5 100644 (file)
@@ -57,6 +57,10 @@ class MarkdownWriter:
         if headers == self.last_headers:
             return
         for i in range(len(headers)):
+            if not headers[i].startswith("\n" + "#" * (i + 1) + " "):
+                raise ValueError(
+                    "invalid markdown header. if you're not trying to make a"
+                    " markdown header, don't use write_headers!")
             if i >= len(self.last_headers):
                 print(headers[i], file=self.buffer)
                 self.last_headers.append(headers[i])
@@ -172,17 +176,17 @@ def _markdown_for_person(person: Person,
         # work out headers per status
         if payee_state == PayeeState.NotYetSubmitted:
             display_status_header = "\n## Payment not yet submitted\n"
-            subtotals_header = ("\nMoU Milestone subtotals for not "
+            subtotals_msg = ("\nMoU Milestone subtotals for not "
                                 "yet submitted payments\n")
         elif payee_state == PayeeState.Submitted:
             display_status_header = ("\n## Submitted to NLNet but "
                                      "not yet paid\n")
-            subtotals_header = ("\nMoU Milestone subtotals for "
+            subtotals_msg = ("\nMoU Milestone subtotals for "
                                 "submitted but not yet paid payments\n")
         else:
             assert payee_state == PayeeState.Paid
             display_status_header = "\n## Paid by NLNet\n"
-            subtotals_header = ("\nMoU Milestone subtotals for paid "
+            subtotals_msg = ("\nMoU Milestone subtotals for paid "
                                 "payments\n")
         # list all the payments grouped by Grant
         for milestone, payments_list in payments_dict.items():
@@ -199,9 +203,10 @@ def _markdown_for_person(person: Person,
                     mou_subtotals[node.closest_bug_in_mou] += payment.amount
                     writer.write_node(headers=headers,
                                       node=payment.node, payment=payment)
-            headers.append(subtotals_header)
             # now display the mou subtotals. really, this should be before
             for node, subtotal in mou_subtotals.items():
+                writer.write_headers(headers)
+                print(subtotals_msg, file=writer.buffer)
                 writer.write_node_header(headers, node)
                 if node is None:
                     budget = ""