Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Last active December 19, 2015 18:29
Show Gist options
  • Save mgedmin/5999095 to your computer and use it in GitHub Desktop.
Save mgedmin/5999095 to your computer and use it in GitHub Desktop.
A solution for dealing with str(some_float_value) differences in doctests, when you want your codebase to support both Python 2.6 and 2.7.
import re
from zope.testing.renormalizing import RENormalizing
FLOAT_CHECKER = RENormalizing([
(re.compile(r'-?\d+[.]\d+'),
lambda m: '%.6g' % float(m.group(0))),
])
... DocTestSuite(..., checker=FLOAT_CHECKER) ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment