def test_set_header_with_same_header_does_not_change_anything(header_name): fitting_data = FittingData(COLUMNS) fitting_data.set_header(header_name, header_name) for header in COLUMNS_NAMES: assert fitting_data.data[header] == pytest.approx( COLUMNS[header] ), f'Header "{header}" has changed unexpectedly'
def test_header_cannot_already_exist(header_name): fitting_data = FittingData(COLUMNS) new_header = np.random.choice( [header for header in COLUMNS_NAMES if header != header_name] ) with pytest.raises( FittingDataSetError, match=f'^The column name:"{new_header}" is already used.$' ): fitting_data.set_header(header_name, new_header)
def test_set_header_allowed(i): old_header = COLUMNS_NAMES[i] new_header = "new_header" fitting_data = FittingData(deepcopy(COLUMNS)) fitting_data.set_header(old_header, new_header) constant_headers = [header for header in COLUMNS_NAMES if header != old_header] for header in constant_headers: assert fitting_data.data[header] == pytest.approx( COLUMNS[header] ), f'Header "{header}" has changed unexpectedly' assert fitting_data.data[new_header] == pytest.approx( COLUMNS[old_header] ), f'Header "{new_header}" has changed unexpectedly' assert set(fitting_data.all_columns) == set( constant_headers + [new_header] ), "Did not update all columns"
def test_header_cannot_be_set_to_be_empty(header_name): fitting_data = FittingData(COLUMNS) with pytest.raises( FittingDataSetError, match="^Cannot set new header to be empty$" ): fitting_data.set_header(header_name, "")