On Tue, Dec 22, 2020 at 6:57 PM Alan G. Isaac <alan.is...@gmail.com> wrote:

> The following test fails because because `seq1 == seq2` returns a
> (boolean) NumPy array
> whenever either seq is a NumPy array.
>
>      import unittest
>      import numpy as np
>      unittest.TestCase().assertSequenceEqual([1.,2.,3.],
> np.array([1.,2.,3.]))
>
> I expected `unittest` to rely only on features of a
> `collections.abc.Sequence`,
> which based on https://docs.python.org/3/glossary.html#term-sequence,
> I believe are satisfied by a NumPy array.


If you know you might be dealing with NumPy arrays (as the import
suggests), I think it's simply right to spell it as:

unittest.TestCase().assertTrue(np.array_equal([1., 2., 3.], np.array([1.,
2., 3.])))

Or for pytest etc., simply:

assert np.array_equal([1., 2., 3.], np.array([1., 2., 3.]))
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JJHAURGJCFG5PZUQFOUPTJWXGQABOSBT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to