Fix weekly summary crash on open entries

print_summary_weekly, print_summary_weekly_totals and _aggregate summed
raw duration_hours, which is None for open (unfinished) entries, raising
TypeError: float + NoneType. Skip open entries from the weekly totals,
matching to_csv_entries and parser.aggregate. Add regression tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jef Roosens 2026-05-30 19:57:36 +02:00
parent b2b45fd4e1
commit 8f5232d1fe
Signed by: Jef Roosens
GPG key ID: 119385BCAA005C21
2 changed files with 50 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import csv
import datetime
import io
import pytest
@ -6,6 +7,9 @@ import pytest
from timesheets.output import (
print_stories,
print_summary,
print_summary_weekly,
print_summary_weekly_short,
print_summary_weekly_totals,
to_csv_entries,
write_csv,
write_csv_weekly,
@ -330,3 +334,38 @@ class TestPrintStories:
print_stories([])
out = capsys.readouterr().out
assert out == ""
# ---------------------------------------------------------------------------
# Weekly summaries with open (unfinished) entries
# ---------------------------------------------------------------------------
class TestWeeklySummaryOpenEntries:
"""An open entry (start present, end absent) has duration_hours=None and
must be skipped from totals, not crash the weekly summary commands."""
def _sections(self):
rows = [
_raw_row("bugs", "ticket 1", "", 1.0),
_raw_row("bugs", "ticket 2", "", None), # open entry
]
return [(datetime.date(2026, 1, 6), rows)]
def test_weekly_totals_skips_open_entry(self, capsys):
print_summary_weekly_totals(self._sections(), {})
out = capsys.readouterr().out
# only the 1.0h closed entry counts
assert "01:00" in out
assert "WEEK TOTAL" in out
def test_weekly_full_skips_open_entry(self, capsys):
print_summary_weekly(self._sections(), {})
out = capsys.readouterr().out
assert "WEEK TOTAL" in out
assert "01:00" in out
def test_weekly_short_skips_open_entry(self, capsys):
print_summary_weekly_short(self._sections(), {})
out = capsys.readouterr().out
assert "01:00" in out