Here are the examples of the python api tests.mock.NumpyArray taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
3
Source : test_invariant.py
with MIT License
from Parquery
with MIT License
from Parquery
def test_no_boolyness(self) -> None:
@icontract.invariant(lambda self: tests.mock.NumpyArray([True, False]))
class A:
def __init__(self) -> None:
pass
value_error = None # type: Optional[ValueError]
try:
_ = A()
except ValueError as err:
value_error = err
self.assertIsNotNone(value_error)
self.assertEqual('Failed to negate the evaluation of the condition.',
tests.error.wo_mandatory_location(str(value_error)))
if __name__ == '__main__':
3
Source : test_precondition.py
with MIT License
from Parquery
with MIT License
from Parquery
def test_no_boolyness(self) -> None:
@icontract.require(lambda: tests.mock.NumpyArray([True, False]))
def some_func() -> None:
pass
value_error = None # type: Optional[ValueError]
try:
some_func()
except ValueError as err:
value_error = err
self.assertIsNotNone(value_error)
self.assertEqual('Failed to negate the evaluation of the condition.',
tests.error.wo_mandatory_location(str(value_error)))
def test_unexpected_positional_argument(self) -> None:
3
Source : test_represent.py
with MIT License
from Parquery
with MIT License
from Parquery
def test_that_mock_works(self) -> None:
arr = tests.mock.NumpyArray(values=[-3, 3])
value_err = None # type: Optional[ValueError]
try:
not (arr > 0) # pylint: disable=superfluous-parens,unneeded-not
except ValueError as err:
value_err = err
self.assertIsNotNone(value_err)
self.assertEqual('The truth value of an array with more than one element is ambiguous.', str(value_err))
def test_that_single_comparator_works(self) -> None:
3
Source : test_represent.py
with MIT License
from Parquery
with MIT License
from Parquery
def test_that_single_comparator_works(self) -> None:
@icontract.require(lambda arr: (arr > 0).all())
def some_func(arr: tests.mock.NumpyArray) -> None:
pass
violation_error = None # type: Optional[icontract.ViolationError]
try:
some_func(arr=tests.mock.NumpyArray(values=[-3, 3]))
except icontract.ViolationError as err:
violation_error = err
self.assertIsNotNone(violation_error)
self.assertEqual(
textwrap.dedent("""\
(arr > 0).all():
(arr > 0).all() was False
arr was NumpyArray([-3, 3])"""), tests.error.wo_mandatory_location(str(violation_error)))
def test_that_multiple_comparators_fail(self) -> None:
3
Source : test_postcondition.py
with MIT License
from Parquery
with MIT License
from Parquery
async def test_no_boolyness(self) -> None:
@icontract.ensure(lambda: tests.mock.NumpyArray([True, False]))
async def some_func() -> None:
pass
value_error = None # type: Optional[ValueError]
try:
await some_func()
except ValueError as err:
value_error = err
self.assertIsNotNone(value_error)
self.assertEqual('Failed to negate the evaluation of the condition.',
tests.error.wo_mandatory_location(str(value_error)))
if __name__ == '__main__':
0
Source : test_represent.py
with MIT License
from Parquery
with MIT License
from Parquery
def test_that_multiple_comparators_fail(self) -> None:
"""
Test that multiple comparators in an expression will fail.
Multiple comparisons are not implemented in numpy as of version < = 1.16.
The following snippet exemplifies the problem:
.. code-block:: python
import numpy as np
x = np.array([-3, 3])
-100 < x < 100
Traceback (most recent call last):
...
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
:return:
"""
@icontract.require(lambda arr: (-3 < arr < 0).all())
def some_func(arr: tests.mock.NumpyArray) -> None:
pass
value_err = None # type: Optional[ValueError]
try:
some_func(arr=tests.mock.NumpyArray(values=[-10, -1]))
except ValueError as err:
value_err = err
self.assertIsNotNone(value_err)
self.assertEqual('The truth value of an array with more than one element is ambiguous.', str(value_err))
class TestNumpyArrays(unittest.TestCase):