From: Jacob Lifshay Date: Tue, 30 Aug 2022 04:13:03 +0000 (-0700) Subject: fix markdown header writing tests X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48199615c6d86995692bff7be8dc5eab7e93853d;p=utils.git fix markdown header writing tests --- diff --git a/src/budget_sync/test/test_write_budget_markdown.py b/src/budget_sync/test/test_write_budget_markdown.py index e26e92a..d832430 100644 --- a/src/budget_sync/test/test_write_budget_markdown.py +++ b/src/budget_sync/test/test_write_budget_markdown.py @@ -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', diff --git a/src/budget_sync/write_budget_markdown.py b/src/budget_sync/write_budget_markdown.py index bc0a95c..a6b1689 100644 --- a/src/budget_sync/write_budget_markdown.py +++ b/src/budget_sync/write_budget_markdown.py @@ -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 = ""