[Python-Dev] Re: unittest of sequence equality

2020-12-23 Thread Steven D'Aprano
On Tue, Dec 22, 2020 at 06:33:41PM -0500, Alan G. Isaac wrote:
> This comment completely misses the point.
> This "weird type" qualifies as a Sequence.
> (See collections.abc.)

It's not weird because of the sequence abc, it's weird because of its 
treatment of equality, using the `==` operator as an element-wise 
operator instead of an object equality boolean operator.

Numpy is entitled to do this, but we're not obligated to take heroic 
measures to integrate numpy arrays with unittest methods. If we can do 
so easily, sure, let's fix it.

I think Ivan's suggestion that the assertSequenceEqual method fall back 
on element-by-element comparisons has some merit.


-- 
Steve
___
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/36XKAIBLKDXSDOBFEI53OKIPV27WZPZ6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: unittest of sequence equality

2020-12-23 Thread Antoine Pitrou
On Tue, 22 Dec 2020 19:32:15 +
David Mertz  wrote:
> 
> 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.])))

Please don't suggest this, it will produce unhelpful error messages (do
you like "False is not true" errors in CI builds?).

The better solution is to use the dedicated assertions in the
`numpy.testing` package:
https://numpy.org/doc/stable/reference/routines.testing.html

Regards

Antoine.

___
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/JIVB4CCRKPYEISJLHPGHPWY2EAD4PDH5/
Code of Conduct: http://python.org/psf/codeofconduct/