Skip to content

Commit

Permalink
Allow to use different function or precision for 'approx equals'. (#2179
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ceball authored and jlstevens committed Dec 13, 2017
1 parent 94abb1b commit 73bd2fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion holoviews/element/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
thus would not supply any information regarding *why* two elements are
considered different.
"""
from functools import partial
import numpy as np
from unittest.util import safe_repr
from unittest import TestCase
Expand Down Expand Up @@ -92,6 +93,9 @@ class Comparison(ComparisonInterface):
Comparison.assertEqual(matrix1, matrix2)
"""

# someone might prefer to use a different function, e.g. assert_all_close
assert_array_almost_equal_fn = partial(assert_array_almost_equal, decimal=6)

@classmethod
def register(cls):

Expand Down Expand Up @@ -246,7 +250,7 @@ def compare_arrays(cls, arr1, arr2, msg='Arrays'):
assert_array_equal(arr1, arr2)
except:
try:
assert_array_almost_equal(arr1, arr2)
cls.assert_array_almost_equal_fn(arr1, arr2)
except AssertionError as e:
raise cls.failureException(msg + str(e)[11:])

Expand Down

0 comments on commit 73bd2fd

Please sign in to comment.