Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element comparison: allow alternative functions (and arguments) for 'assert approx equal'. #2179

Merged
merged 1 commit into from Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion holoviews/element/comparison.py
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