[issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9
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 <https://bugs.python.org/issue42586> ___ ___ 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
Change by Valeriu Predoi : -- status: open -> pending ___ Python tracker <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ 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
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 <https://bugs.python.org/issue42586> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com