Add --raw flag to csv command to skip aggregation

- Add `to_csv_entries()` to output.py: converts raw rows to write_csv
  entries one-for-one, without merging by (project, description)
- Add `--raw` flag to the csv subparser; _cmd_csv branches on it
- Add TestToCsvEntries with 6 tests
- Update README with --raw usage example
- Add .coverage and htmlcov/ to .gitignore
This commit is contained in:
Jef Roosens 2026-05-28 13:07:50 +02:00
parent 91ce81a65f
commit 985ee28113
Signed by: Jef Roosens
GPG key ID: 119385BCAA005C21
6 changed files with 97 additions and 4 deletions

View file

@ -3,7 +3,7 @@ import io
import pytest
from timesheets.output import print_stories, print_summary, write_csv
from timesheets.output import print_stories, print_summary, to_csv_entries, write_csv
# ---------------------------------------------------------------------------
# Shared fixtures
@ -20,6 +20,64 @@ AGGREGATED = [
]
# ---------------------------------------------------------------------------
# to_csv_entries
# ---------------------------------------------------------------------------
def _raw_row(project, story, note, duration_hours):
return {
"project": project,
"story": story,
"story_raw": story,
"note": note,
"start": "09:00",
"end": "10:00" if duration_hours is not None else None,
"duration_hours": duration_hours,
}
class TestToCsvEntries:
def test_basic_conversion(self):
rows = [_raw_row("bugs", "ticket 1", "", 1.0)]
assert to_csv_entries(rows) == [
{"project": "bugs", "description": "ticket 1", "quantity": 1.0}
]
def test_skips_open_entries(self):
rows = [_raw_row("bugs", "ticket 1", "", None)]
assert to_csv_entries(rows) == []
def test_does_not_aggregate(self):
rows = [
_raw_row("bugs", "ticket 1", "", 0.5),
_raw_row("bugs", "ticket 1", "", 0.5),
]
entries = to_csv_entries(rows)
assert len(entries) == 2
assert entries[0]["quantity"] == 0.5
assert entries[1]["quantity"] == 0.5
def test_description_combines_story_and_note(self):
rows = [_raw_row("bugs", "ticket 1", "fix", 1.0)]
assert to_csv_entries(rows)[0]["description"] == "ticket 1 - fix"
def test_project_stripped(self):
rows = [_raw_row(" bugs ", "", "dsu", 0.25)]
assert to_csv_entries(rows)[0]["project"] == "bugs"
def test_mixed_open_and_closed(self):
rows = [
_raw_row("bugs", "ticket 1", "", 1.0),
_raw_row("bugs", "ticket 2", "", None),
_raw_row("scrum", "", "dsu", 0.25),
]
entries = to_csv_entries(rows)
assert len(entries) == 2
assert entries[0]["description"] == "ticket 1"
assert entries[1]["description"] == "dsu"
# ---------------------------------------------------------------------------
# write_csv
# ---------------------------------------------------------------------------