def test_func_with_incorrect_datatype(self): with self.assertRaises(TypeError) as context: _ = validate_array_input((1, 2, 3), np.float64, 'arr') msg = ["The array {} must be either a list, ".format('arr'), "numpy.ndarray or pandas.Series"] self.assertTrue("".join(msg) in str(context.exception))
def test_func_with_non_numerical_input(self): with self.assertRaises(ValueError) as context: _ = validate_array_input(['a', 'b', 1], np.float64, 'arr') msg = [ "The data in the parameter array '{}'".format('arr'), " must be purely numerical." ] self.assertTrue("".join(msg) in str(context.exception))
def test_func_with_list(self): vals = [1., 2., 3., 4.] arr = validate_array_input(vals, np.float64, 'arr') self.assertSequenceEqual(vals, arr.tolist())
def test_func_with_pandas_series(self): vals = [1, 2, 3, 4] data = pd.Series(data=vals, dtype=np.float64) arr = validate_array_input(data, np.float64, 'arr') self.assertSequenceEqual(arr.tolist(), np.array(vals, np.float64).tolist())