Let approx() work on more generic sequences
approx() was updated in 9f3122fe to work better with numpy arrays,
however at the same time the requirements were tightened from
requiring an Iterable to requiring a Sequence - the former being
tested only on interface, while the latter requires subclassing or
registration with the abc.
Since the ApproxSequence only used __iter__ and __len__ this commit
reduces the requirement to only what's used, and allows unregistered
Sequence-like containers to be used.
Since numpy arrays qualify for the new criteria, reorder the checks so
that generic sequences are checked for after numpy arrays.
This commit is contained in:
@@ -496,3 +496,13 @@ class TestApprox(object):
|
||||
assert actual != approx(expected, rel=5e-8, abs=0)
|
||||
assert approx(expected, rel=5e-7, abs=0) == actual
|
||||
assert approx(expected, rel=5e-8, abs=0) != actual
|
||||
|
||||
def test_generic_iterable_sized_object(self):
|
||||
class newIterable(object):
|
||||
def __iter__(self):
|
||||
return iter([1, 2, 3, 4])
|
||||
|
||||
def __len__(self):
|
||||
return 4
|
||||
|
||||
assert [1, 2, 3, 4] == approx(newIterable())
|
||||
|
||||
Reference in New Issue
Block a user