My function is
def validate_latitude(lat):
"""Enforce latitude is in range
>>> validate_latitude(65)
65
>>> validate_latitude(91)
90
>>> validate_latitude(-91)
-90
"""
lat = min(lat, 90)
lat = max(lat, -90)
return lat
And the test fails with this output
**********************************************************************
File "packages/utils.py", line 64, in __main__.validate_latitude
Failed example:
validate_latitude(-91)
Expected:
-90
Got:
-90
**********************************************************************
Cant see why it fails in spite of having the deisred output
Whitespace?
If I highlight your output, I can see additional whitespace following the "Expected" value. Not sure whether this is relevant or not.
In these two lines:
You have a Tab character before the
-
in-90
, and four space characters after the0
. When doctests runs this code the extra whitespace is of course not produced, so the equality comparison fails.Good editors, e.g. vim, have ways to highlight trailing spaces, and stray tabs, so that you don't fall afould of such accidents. Not sure what editor you're using or how you have set it up, so it's hard to give more specific advice (besides the obvious one of ensuring you use an editor WITH such capabilities, and enable the capabilities in question;-).