Write a CSV comparison helper that catches more than row-count differences.

Instruction: Implement the comparison in Python, give the exact findings and test a correct reordered export plus malformed inputs. Preserve string IDs.

Context:

Two small UTF-8 CSV texts have exactly the header id,name. Use Python csv.reader with its default comma-separated dialect and strict=True, or equivalent parsing. IDs are nonempty strings; leading zeros and name whitespace are significant. Expected IDs must be unique; duplicates are an invalid oracle. Actual row order is irrelevant. Report sorted missing IDs, unexpected IDs, duplicate actual IDs and changed-name IDs. A shared ID is changed if any actual occurrence has a different name. Reject wrong headers, wrong field counts, empty IDs and CSV parser errors. Header-only files are valid.

Expected:

id,name
001,"North, East"
002,"Quote ""Lab"""
003,東京

Actual:

id,name
002,"Quote ""Lab"""
001,North East
002,"Quote ""Lab"""
004,Extra

This is fixture-scale comparison in memory, not a large-file streaming design.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

I would parse the declared CSV dialect, validate the header and every row, and keep IDs as strings. The expected fixture must be unique before it can serve as an oracle...

Related Questions