[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Changed status to pending, will close once we've had 3.9.1 in our env and 
tested proper, but should be OK, cheers!

--
status: pending -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Change by Valeriu Predoi :


--
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Excellent, just gonna let my team know about this and we'll hold off on 3.9.0 
then - good stuff, mate!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

3.9.1 is in RC1 as per https://www.python.org/dev/peps/pep-0596/#lifespan . It 
will be available as part of 3.9.1 or 3.9.2 . I am not sure about anaconda 
packaging schedule though.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Great, cheers mate, I read through the PR's (and sorry to have pestered you 
over at the mock backport GitHub too haha) - this looks it will fix the issue 
nicely. Do you know when will the release be available for us using Python from 
Anaconda etc.? Feel free to close this, and thanks for the assistance! Cheers, V

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

It's a problem with 3.9 only as far as I know. The fix has been merged to 
master (3.10) and 3.9 . I will check with 3.8 but I don't think it will be a 
problem since 3.8 has a different code path. You can check the PR merged for 
more discussion.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Note however, that the need I have for my type of functionality is fulfilled 
and all works fine for Python 3.7 and 3.8, I noticed the problem only for 3.9 - 
the OP in that issue says their versions affected include 3.8 (maybe it creeps 
up for 3.8.6 or larger, I tested with 3.8.5). Cheers!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Indeed so! Sorry, I only glossed over that one before posting mine, now that I 
looked at it more carefully you are right, it does need a check on None and not 
calling the __bool__ member, which is affecting functionally passing an ndarray 
as spec - what should I do with my issue, close it? Cheers muchly!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks, this looks like a duplicate of https://bugs.python.org/issue42532

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


Valeriu Predoi  added the comment:

Hello mate, yes it used to work fine with Python 3.8, no issue with Python 3.9 
and numpy if you call mock as 

ob = mg.Mock(spec=np.array([4, 4]))

this results in a nice exception being raised:

Traceback (most recent call last):
  File "/home/valeriu/ESMValCore/tmock.py", line 20, in 
ob = mg.Mock(spec=np.array([4, 4]))
  File 
"/home/valeriu/miniconda3/envs/esmvalcore39/lib/python3.9/unittest/mock.py", 
line 409, in __new__
if spec_arg and _is_async_obj(spec_arg):
ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

which is pretty normal since that func performs an existence check on an array 
- hope this helps! Cheers

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I don't have Python 3.9 with numpy to test this. Does this used to work with 
python 3.8? Does using numpy produce any error or traceback in 3.9?

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

2020-12-07 Thread Valeriu Predoi


New submission from Valeriu Predoi :

Hey guys, the new unittest.mock.Mock for Python 3.9 can not accept a spec arg 
if it is a numpy array, it'll accept all other types but not ndarray, have a 
look at this quick minimal code:

import numpy as np

from unittest import mock as mg

ob = mg.Mock(spec=[4, 4])
print("spec is list, mock is", ob)

ob = mg.Mock(spec=["4", "4"])
print("spec is list of str, mock is", ob)

ob = mg.Mock(spec=(4, 4))
print("spec is tuple, mock is", ob)

ob = mg.Mock(spec="cow")
print("spec is string, mock is", ob)

ob = mg.Mock(spec=22)
print("spec is int, mock is", ob)

ob = mg.Mock(spec=np.array([4, 4]))
print("spec is ndarray, mock is", ob)

versions:
python  3.9.0 h2a148a8_4_cpythonconda-forge
pytest-mock 3.3.1  pypi_0pypi

Is this intended or it's a buggy-bug?

Cheers muchly! V

--
components: Tests
messages: 382634
nosy: valeriupredoi
priority: normal
severity: normal
status: open
title: unittest.mock.Mock spec can't be array/ndarray in Python 3.9
type: behavior
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com