Skip to content

Commit f343789

Browse files
authored
Update test_util.py to enhance code coverage (nv-legate#1230)
* Update test_util.py
1 parent 062f139 commit f343789

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/unit/cupynumeric/_array/test_util.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from mock import MagicMock
1818
from pytest_mock import MockerFixture
1919
from unit.util import powerset
20+
from cupynumeric._array.util import tuple_pop
2021

2122
import cupynumeric._array.util as m # module under test
2223

@@ -227,6 +228,45 @@ def func(a, b=2, c=None, d=None, e=5, out=None, where=None):
227228
mock_convert.assert_any_call(4, share=True)
228229

229230

231+
def test_add_boilerplate_out_not_writeable_positional(
232+
mock_convert: MagicMock,
233+
) -> None:
234+
@m.add_boilerplate()
235+
def func(a, out=None):
236+
pass
237+
238+
mock_array = MagicMock()
239+
mock_array.flags.writeable = False
240+
mock_convert.return_value = mock_array
241+
242+
with pytest.raises(ValueError, match="out is not writeable"):
243+
func(None, 42)
244+
mock_convert.assert_called_once_with(42, share=True)
245+
246+
247+
def test_add_boilerplate_out_not_writeable_keyword(
248+
mock_convert: MagicMock,
249+
) -> None:
250+
@m.add_boilerplate()
251+
def func(a, out=None):
252+
pass
253+
254+
mock_array = MagicMock()
255+
mock_array.flags.writeable = False
256+
mock_convert.return_value = mock_array
257+
258+
with pytest.raises(ValueError, match="out is not writeable"):
259+
func(None, out=42)
260+
mock_convert.assert_called_once_with(42, share=True)
261+
262+
263+
def test_tuple_pop() -> None:
264+
tup = (1, 2, 3, 4)
265+
assert tuple_pop(tup, 1) == (1, 3, 4)
266+
assert tuple_pop(tup, 0) == (2, 3, 4)
267+
assert tuple_pop(tup, 3) == (1, 2, 3)
268+
269+
230270
if __name__ == "__main__":
231271
import sys
232272

0 commit comments

Comments
 (0)