Add the Python variant, agreeing with Go byte for byte

A second, independent implementation of the same contract, in the same repo:

- swehockey/dom.py builds the tree on html.parser, so the variant has no
  runtime dependencies; the only HTML5 behaviour it depends on - stray <tr>
  landing in an implicit <tbody> - is handled explicitly by table_rows().
- parse.py mirrors the Go layout profiles, dual-render checks, carry-forward and
  invariants; a DriftError is raised in the same places with the same advice.
- cli.py offers the same three commands, flags and exit codes as the Go main.
- tests/ assert against the Go golden files, so the suite is also a
  cross-implementation check. 23 offline tests plus an opt-in live test.

Verified against the live site: JSON and CSV are byte-identical to the Go
output (364 games, 102536 bytes / 365 lines), and the full archive crawl gives
the same 27 seasons, 2119 games and 1779 played.

Also split the DriftError hint out in Go, so a golden mismatch no longer tells
the reader to extend layouts[].
This commit is contained in:
Mats Tornberg committed 2026-09-27 08:53:23 +00:00
1 parent 6b701819ca
commit 47e1811d9e
15 files changed
+1821 -3

No files matched your search

+9 -2
View File
@@ -123,8 +123,15 @@ type DriftError struct {
Got string
Want string
Msg string
// Every layout problem ends with the same advice, so an operator reading a
// cron mail knows exactly what to do. Failures that are not about the table
// shape pass an empty Hint and get no advice.
Hint string
}
// layoutHint is the advice attached to every markup problem.
const layoutHint = " - extend layouts[] in parse.go and add a fixture, in one commit"
func (e *DriftError) Error() string {
var b strings.Builder
fmt.Fprintf(&b, "swehockey: markup drift (season %d", e.Season)
@@ -143,12 +150,12 @@ func (e *DriftError) Error() string {
if e.Got != "" {
fmt.Fprintf(&b, ": got %q, want %q", e.Got, e.Want)
}
b.WriteString(" - extend layouts[] in parse.go and add a fixture, in one commit")
b.WriteString(e.Hint)
return b.String()
}
func drift(season int, gameID, column, msg, got, want string) error {
return &DriftError{Season: season, GameID: gameID, Column: column, Msg: msg, Got: got, Want: want}
return &DriftError{Season: season, GameID: gameID, Column: column, Msg: msg, Got: got, Want: want, Hint: layoutHint}
}
// ParseSchedule extracts the schedule table from one saved or fetched page.