You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can register a custom formatter via the (undocumented) snapshottest.formatter.Formatter.register_formatter() static method, overriding the default float formatter. I believe you'd want to format floats into a new custom type (FloatCloseTo(3.14159)) that implements the desired __eq__ along with a __repr__ that can construct itself.
The built-in file snapshot formatter shows all the moving parts (plus a bunch more complexity you wouldn't need, around writing additional files).
Also (although I'm not proud of this suggestion), if all your floats are of similar precision, it might be sufficient to just serialize them as Decimals?
Self-explanatory.
Some potential ideas / handlers:
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertAlmostEqual
https://docs.scipy.org/doc/numpy/reference/generated/numpy.testing.assert_almost_equal.html
https://docs.python.org/3/whatsnew/3.5.html#pep-485-a-function-for-testing-approximate-equality
The text was updated successfully, but these errors were encountered: