
An import report describes validation errors by spreadsheet row. The header occupies the first line, so the first data record must be numbered two in messages to the operator. Starting the counter at two accounts for one header row. The data list itself remains zero-indexed when accessed elsewhere.
Reproduce the input boundary
The script runs enumerate against three independent inputs. Each call starts from the value shown, so changing one example leaves the other expectations available for comparison. The table records real return values from the example. Quotation marks around text in the table make its boundaries visible.
def evaluate(value):
return list(enumerate(value,start=2))
for sample in [['A', 'B'], ['A'], []]:
print(evaluate(sample))What the three inputs produce
| Input to evaluate | Observed result |
|---|---|
| ["A", "B"] | [[2, "A"], [3, "B"]] |
| ["A"] | [[2, "A"]] |
| [] | [] |
For ["A", "B"], the observed output is [[2, "A"], [3, "B"]]. With ["A"], it becomes [[2, "A"]]. Compare the two as a before-and-after record. Keeping the input beside the expectation makes it possible to distinguish an intentional contract change from a change introduced by a different parser or runtime.
The result for [] is an empty collection. A consumer that takes its first element needs a defined fallback at this point. Preserving an empty collection in an export lets another program distinguish zero matches from a missing field.
Choosing the behaviour to ship
Multiline CSV records break the assumption that a logical row number equals a physical line number. Use the parser's line tracking when that distinction matters.
A practical test can begin with assert evaluate(['A', 'B']) == [(2, 'A'), (3, 'B')]. Add the other rows as separate expectations so one failure identifies the input that changed. For a service fed by stored data, repeat the check on one anonymized record from an earlier version of its file or message format.
The boundary case most likely to be missed
Pass the row number explicitly into error messages rather than calculating it later from a filtered list of failures. Filtering changes positions and can cause a user to repair the wrong spreadsheet row.
The same Python function was also run with [] / ["A"] / ["B", "A"]. These additional inputs change the boundary without changing the implementation. An exception name in the table records where the operation rejects an input; a returned empty or zero value records a successful call. Choose deliberately which of those outcomes the surrounding feature should expose.
| Additional fixture | Result or exception |
|---|---|
| [] | [] |
| ["A"] | [[2, "A"]] |
| ["B", "A"] | [[2, "B"], [3, "A"]] |
Python’s functions reference · Python standard library
Sources and further reading
Cover photograph: Computer Desk at Narita Airport 2 (3545071562) by D Coetzee from San Mateo, CA, USA. CC0. Cropped and typeset for this cover. The photograph illustrates the topic.
