def case_unselect_one_record(): fit_data = FitData(COLUMNS) fit_data.unselect_record(2) return ( fit_data, [1] + list(range(3, NUMBER_OF_RECORDS + 1)), )
def test_x_larger_than_size(column): with pytest.raises( FitDataColumnIndexError, match= "^No column number 11 in data. index should be between 1 and 10$", ): FitData(COLUMNS, **{column: 11})
def test_x_zero_index(column): with pytest.raises( FitDataColumnIndexError, match= "^No column number 0 in data. index should be between 1 and 10$", ): FitData(COLUMNS, **{column: 0})
def case_select_all_records(): fit_data = FitData(COLUMNS) fit_data.unselect_all_records() fit_data.select_record(2) fit_data.select_record(5) fit_data.select_all_records() return fit_data, list(range(1, NUMBER_OF_RECORDS + 1))
def case_fitting(case_path): with open(str(case_path), mode="r") as json_file: json_obj = json.load(json_file) func_name = json_obj["fit_function"] func = FitFunctionsRegistry.load(func_name) fix = json_obj.get("fix", None) if fix is not None: for index, value in fix: func.fix(index, value) data_dict = json_obj["data"] data = FitData( OrderedDict( [ ("x", data_dict["x"]), ("xerr", data_dict["xerr"]), ("y", data_dict["y"]), ("yerr", data_dict["yerr"]), ] ) ) a0 = json_obj.get("a0", None) result = fit_to_data(data=data, func=func, a0=a0) decimal = json_obj.get("decimal", 2) inp = dict(actual_result=result, a0=a0, func=func, delta=np.power(10.0, -decimal)) expected_result = json_obj["result"] return inp, expected_result
def test_exception_risen_because_of_columns_length(): data = deepcopy(COLUMNS) data["a"] = data["a"][:-2] with pytest.raises( FitDataColumnsLengthError, match="^All columns in FitData should have the same length$", ): FitData(data=data)
def case_select_multiple_records(): fit_data = FitData(COLUMNS) fit_data.unselect_all_records() fit_data.select_record(2) fit_data.select_record(5) fit_data.select_record(3) fit_data.select_record(10) return fit_data, [2, 3, 5, 10]
def case_jumbled_columns(): fit_data = FitData(COLUMNS, x_column=3, xerr_column=1, y_column="b", yerr_column=9) expected_columns = Columns(x="c", xerr="a", y="b", yerr="i") return fit_data, expected_columns
def case_unselect_multiple(): fit_data = FitData(COLUMNS) fit_data.unselect_record(2) fit_data.unselect_record(5) fit_data.unselect_record(3) fit_data.unselect_record(10) return fit_data, [1, 4, 6, 7, 8, 9] + list(range(11, NUMBER_OF_RECORDS + 1))
def case_string_xerr_column(): fit_data = FitData(COLUMNS, xerr_column="d") expected_columns = Columns( x="a", xerr="d", y="e", yerr="f", ) return fit_data, expected_columns
def case_int_x_column(): fit_data = FitData(COLUMNS, x_column=3) expected_columns = Columns( x="c", xerr="d", y="e", yerr="f", ) return fit_data, expected_columns
def test_set_selection_with_different_size(): fit_data = FitData(COLUMNS) def set_records_indices(): fit_data.records_indices = [False, False, True] with pytest.raises( FitDataColumnsSelectionError, match= f"^Should select {NUMBER_OF_RECORDS} records, only 3 selected.$", ): set_records_indices()
def test_set_selection_with_non_boolean_values(): fit_data = FitData(COLUMNS) def set_records_indices(): fit_data.records_indices = [False, False, "dummy" ] + [True] * (NUMBER_OF_RECORDS - 3) with pytest.raises( FitDataColumnsSelectionError, match= "^When setting record indices, all values should be booleans.$", ): set_records_indices()
def case_select_two_records(): fit_data = FitData(COLUMNS) fit_data.unselect_all_records() fit_data.select_record(2) fit_data.select_record(5) return fit_data, [2, 5]
def case_select_one_records(): fit_data = FitData(COLUMNS) fit_data.unselect_all_records() fit_data.select_record(2) return fit_data, [2]
def case_unselect_all(): fit_data = FitData(COLUMNS) fit_data.unselect_all_records() return fit_data, []
def case_unselect_two_records(): fit_data = FitData(COLUMNS) fit_data.unselect_record(2) fit_data.unselect_record(5) return fit_data, [1, 3, 4] + list(range(6, NUMBER_OF_RECORDS + 1))
def test_x_not_existing(column): with pytest.raises(FitDataColumnExistenceError, match='^Could not find column "r" in data$'): FitData(COLUMNS, **{column: "r"})
def case_int_y_column(): fit_data = FitData(COLUMNS, y_column=5) expected_columns = Columns(x="a", xerr="b", y="e", yerr="f") return fit_data, expected_columns
def case_x_and_y_column(): fit_data = FitData(COLUMNS, x_column=3, y_column="h") expected_columns = Columns(x="c", xerr="d", y="h", yerr="i") return fit_data, expected_columns
def case_string_yerr_column(): fit_data = FitData(COLUMNS, yerr_column="f") expected_columns = Columns(x="a", xerr="b", y="c", yerr="f") return fit_data, expected_columns
def case_set_selected_records(): fit_data = FitData(COLUMNS) fit_data.records_indices = [False, True, False, False, True ] + [False] * (NUMBER_OF_RECORDS - 5) return fit_data, [2, 5]
def case_default(): fit_data = FitData(COLUMNS) expected_columns = Columns(x="a", xerr="b", y="c", yerr="d") return fit_data, expected_columns