def test_dataframe_nans(self, example_dataframe_loaded): df = example_dataframe_loaded df.Run[0] = np.nan with pytest.raises(ValueError): load_data_for_simulation(df)
def test_dataframe_has_outcome_column(self, example_dataframe_loaded): df = example_dataframe_loaded df.columns = [i.replace('Outcome', 'abc') for i in df.columns] with pytest.raises(AttributeError): load_data_for_simulation(df)
def test_incorrect_input_names(self, example_dataframe_loaded): with pytest.raises(AttributeError): load_data_for_simulation(example_dataframe_loaded, ['Input2'])
def test_dataframe_n_subjects(self, example_dataframe_loaded): assert load_data_for_simulation(example_dataframe_loaded)[3] == 2
def test_dataframe_n_runs(self, example_dataframe_loaded): assert load_data_for_simulation(example_dataframe_loaded)[2] == 2
def test_dataframe_has_rows(self, example_dataframe_loaded): with pytest.raises(AttributeError): load_data_for_simulation(example_dataframe_loaded.iloc[:1, :])
def test_numpy_array_n_runs(self): assert load_data_for_simulation(np.ones((3, 4)))[2] == 4
def test_convert_to_numpy_array(self): """ Try providing a list of pandas dataframes, this should fail as it can't be converted to an array""" with pytest.raises(TypeError): load_data_for_simulation([pd.DataFrame({'a': [1, 2]})])
def test_infs_in_outcomes(self): with pytest.raises(ValueError): load_data_for_simulation(np.array([0, 1, np.inf]))
def test_numpy_array_outcome_shape_1D(self): """Tests whether a 1D array has been successfully converted to shape (n_trials, 1)""" assert load_data_for_simulation(np.ones(3))[0].shape == (3, 1)
def test_more_than_2d_array(self): with pytest.raises(AttributeError): load_data_for_simulation(np.ones((2, 3, 4)))
def test_one_length_array(self): with pytest.raises(AttributeError): load_data_for_simulation(np.array([1]))
def test_array_with_model_inputs(self): with pytest.raises(ValueError): load_data_for_simulation(np.array([1, 2, 3]), ['a'])
def test_inputs_not_strings(self, example_dataframe_loaded): with pytest.raises(TypeError): load_data_for_simulation(example_dataframe_loaded, [1])
def test_dataframe_load_from_string(self): """ Check that loading from path produces a numpy array""" assert isinstance( load_data_for_simulation('example_outcome_df.csv')[0], np.ndarray)
def test_model_input_returns_list_of_arrays(self, example_dataframe_loaded): assert isinstance( load_data_for_simulation(example_dataframe_loaded, ['Input1'])[1][0], np.ndarray)
def test_correct_number_of_outputs(self): assert len(load_data_for_simulation(np.ones(3))) == 5