Frage

Failed example:
    p.parse_name('Adams, Michael') 
    # doctest: +NORMALIZE_WHITESPACE
Expected:
    {'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}
Got:
    {'first_name': 'Michael', 'last_name': 'Adams', 'initials': 'MA'}

The docstring is -

>>> p.parse_name('Adams, Michael') 
... # doctest: +NORMALIZE_WHITESPACE
{'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}
War es hilfreich?

Lösung

From the docs:

When specified, all sequences of whitespace (blanks and newlines) are treated as equal. Any sequence of whitespace within the expected output will match any sequence of whitespace within the actual output

',' contains no sequence of whitespace, so is not treated as equal to ', '.


You might want to read the warnings section of the docs:

Python doesn’t guarantee that the key-value pairs will be printed in any particular order, so a test like

>>> foo()
{"Hermione": "hippogryph", "Harry": "broomstick"}

is vulnerable! One workaround is to do

>>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
True
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top