home · contact · privacy
Improve template testing.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 11 Jan 2026 20:45:47 +0000 (21:45 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 11 Jan 2026 20:45:47 +0000 (21:45 +0100)
src/ledgplom/testing.py
src/templates/_base.tmpl
src/templates/_macros.tmpl
src/tests/full.ledger_raw
src/tests/full.ledger_structured

index cf91c0817cb57d986ff16b6929e0ea13aeb659e6..844128d0f0c8dc9311165366e4bcf20e8371b198 100644 (file)
@@ -38,8 +38,11 @@ def run_tests() -> None:
             with test_path.open('r', encoding='utf8') as f:
                 lines_expected = [line.rstrip('\n')
                                   for line in f.readlines()]
-            lines_rendered = template.render(blocks=Ledger(path).blocks
-                                             ).split('\n')
+            ledger = Ledger(path)
+            ctx = {
+                'blocks': ledger.blocks,
+                'has_redundant_empty_lines': ledger.has_redundant_empty_lines}
+            lines_rendered = template.render(**ctx).split('\n')
             msg_prefix = f'test for {test_path}:'
             for idx0, line in enumerate(lines_rendered):
                 idx1 = idx0 + 1
index afecacc77c8003d72cea365078acec5efb096920..0d7534f941c696cca22d2fc7fbd7c0e528548fe0 100644 (file)
@@ -12,14 +12,14 @@ html {
     scroll-padding-top: 2em;
 }
 body {
-    {{macros.css_bg_white()}}
+    {{ macros.css_bg_white() }}
     font-family: sans-serif;
     text-align: left;
     margin: 0;
     padding: 0;
 }
 #header {
-    {{macros.css_bg_white()}}
+    {{ macros.css_bg_white() }}
     position: sticky;
     top: 0;
     padding-left: 0.5em;
@@ -30,13 +30,13 @@ table.alternating > tbody > tr:nth-child(odd) {
     background-color: #dcdcdc;
 }
 table.alternating > tbody > tr:nth-child(even) {
-    {{macros.css_bg_white()}}
+    {{ macros.css_bg_white() }}
 }
 td {
     vertical-align: top;
 }
 .critical {
-    background: {{macros.css_red()}} !important;
+    background: {{ macros.css_red() }} !important;
 }
 {% block css %}
 {% endblock %}
@@ -44,7 +44,7 @@ td {
 </head>
 <body>
 <div id="header">
-    <form action="{{path}}" method="POST">
+    <form action="{{ path }}" method="POST">
         <span class="disable_on_change">
             ledger <a href="/ledger_structured">structured</a>
             / <a href="/ledger_raw">raw</a>
index e6b9268dd53b755991ee6d5d89388d605d30d3c0..a98aa1b4ef64958289f40475e34fd84a957f2162 100644 (file)
@@ -54,9 +54,9 @@ td.balance.currency {
 
 {% macro conditional_block_nav(path, direction, block) %}
 {% if block[direction] %}
-<a href="{{path}}{{block[direction].id_}}">{{direction}}</a>
+<a href="{{ path }}{{ block[direction].id_ }}">{{ direction }}</a>
 {% else %}
-<del>{{direction}}</del>
+<del>{{ direction }}</del>
 {% endif %}
 {% endmacro %}
 
@@ -66,7 +66,7 @@ td.balance.currency {
 
 {% macro css_ledger() %}
 td.block_column {
-    {{css_bg_white()}}
+    {{ css_bg_white() }}
 }
 {%- endmacro %}
 
@@ -74,8 +74,8 @@ td.block_column {
 
 {% macro ledger_empty_lines_fix(has_redundant_empty_lines) %}
 {% if has_redundant_empty_lines %}
-    Detected redundant empty lines in gaps, <input type="submit" name="remove_redundant_empty_lines" value="fix?" />
-    <hr />
+Detected redundant empty lines in gaps, <input type="submit" name="remove_redundant_empty_lines" value="fix?" />
+<hr />
 {% endif %}
 {% endmacro %}
 
@@ -83,7 +83,7 @@ td.block_column {
 
 {% macro ledger_block_columns(mode, block) %}
     <tr></tr><!-- keep the background-color alternation in proper order -->
-    <tr id="block_{{ block.id_ }}">
+    <tr id="block_{{  block.id_ }}">
         <td rowspan={{ block.lines | length + 1 }} {# -#}
             class="block_column{{ ' critical' if block.date_error }}">
             <input type="submit"
@@ -107,10 +107,10 @@ td.block_column {
         </td>
         <td rowspan={{ block.lines | length + 1 }} {# -#}
             class="block_column{{ 'critical' if block.booking
-                                             and block.booking.sink_error}}">
-            [<a href="#block_{{block.id_}}">#</a>]<br />
-            [<a href="/balance?up_incl={{block.id_}}">b</a>]<br />
-            [<a href="/edit_{{mode}}/{{block.id_}}">e</a>]
+                                             and block.booking.sink_error }}">
+            [<a href="#block_{{ block.id_ }}">#</a>]<br />
+            [<a href="/balance?up_incl={{ block.id_ }}">b</a>]<br />
+            [<a href="/edit_{{ mode }}/{{ block.id_ }}">e</a>]
         </td>
     </tr>
 {% endmacro %}
index 09d2075da8aebcfffcaaf8f5a397646854a80d4d..50bf269a7465de3510a8678a6a90aee16dc2e0c8 100644 (file)
@@ -55,6 +55,8 @@ table {
     </form>
 </div>
 <form action="/ledger_raw" method="POST">
+Detected redundant empty lines in gaps, <input type="submit" name="remove_redundant_empty_lines" value="fix?" />
+<hr />
 <table class="alternating">
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_0">
index ee98fa9bcc37a3a34a018aa9293a9f4e061bfe58..d572547e6a722c3e24c3ca198587b69b81475d38 100644 (file)
@@ -60,6 +60,8 @@ td.currency {
     </form>
 </div>
 <form action="/ledger_structured" method="POST">
+Detected redundant empty lines in gaps, <input type="submit" name="remove_redundant_empty_lines" value="fix?" />
+<hr />
 <table class="alternating">
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_0">