예제 #1
0
 def test_multi_dimensional_value(self):
     kwargs = dict(
         value=np.arange(3 * 4, dtype=int).reshape(3, 4), size=3, dtype=float
     )
     expected_exception = ValueError
     match = "value must not have more than 1 dimension."
     with pytest.raises(expected_exception, match=match):
         _validate_scalar_to_multi(**kwargs)
예제 #2
0
 def test_list_value_uncastable_to_dtype(self):
     kwargs = dict(value=[1, 2, "c"], size=3, dtype=int)
     expected_exception = ValueError
     match = "value and dtype are incompatible with one another."
     with pytest.raises(expected_exception, match=match):
         _validate_scalar_to_multi(**kwargs)
예제 #3
0
 def test_value_incompatible_with_size(self):
     kwargs = dict(value=[1, 2, 3, 4], size=3, dtype=int)
     expected_exception = ValueError
     match = "The length of value must either be 1 or it must match size if size is provided."
     with pytest.raises(expected_exception, match=match):
         _validate_scalar_to_multi(**kwargs)
예제 #4
0
 def test_non_int_size(self):
     kwargs = dict(value=[1, 2, 3, 4], size="size: not an int", dtype=float)
     expected_exception = TypeError
     match = "size must be either None or interpretable as an integer."
     with pytest.raises(expected_exception, match=match):
         _validate_scalar_to_multi(**kwargs)
예제 #5
0
 def test_negative_size(self):
     kwargs = dict(value=[], size=-1, dtype=float)
     expected_exception = ValueError
     match = "size must be non-negative."
     with pytest.raises(expected_exception, match=match):
         _validate_scalar_to_multi(**kwargs)
예제 #6
0
 def test_scalar_value_with_size_None(self):
     kwargs = dict(value=1, size=None, dtype=float)
     correct_output = np.array([1], float)
     assert np.array_equal(_validate_scalar_to_multi(**kwargs), correct_output)
예제 #7
0
 def test_array_value(self):
     kwargs = dict(value=np.array([1, 2, 3], float), size=3, dtype=int)
     correct_output = np.array([1, 2, 3], int)
     assert np.array_equal(_validate_scalar_to_multi(**kwargs), correct_output)
예제 #8
0
 def test_list_value_dtype_casting_to_int(self):
     kwargs = dict(value=[1, 2, 3.5], size=3, dtype=int)
     correct_output = np.array([1, 2, 3], int)
     assert np.array_equal(_validate_scalar_to_multi(**kwargs), correct_output)
예제 #9
0
 def test_scalar_dtype_casting(self):
     kwargs = dict(value=9.5, size=4, dtype=int)
     correct_output = np.full(4, 9, int)
     assert np.array_equal(_validate_scalar_to_multi(**kwargs), correct_output)
예제 #10
0
 def test_empty(self):
     kwargs = dict(value=1, size=0, dtype=int)
     correct_output = np.array([], int)
     assert np.array_equal(_validate_scalar_to_multi(**kwargs), correct_output)