def test_fail_to_add_yerr_for_another_yerr(self): mc = MarkedColumns() mc.add_y(0) mc.add_y(1) mc.add_y(2) mc.add_y(3) mc.add_y_err(ErrorColumn(1, 0, 0)) expected = [(0, '[Y0]'), (2, '[Y1]'), (3, '[Y2]'), (1, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels()) self.assertRaises(ValueError, lambda: mc.add_y_err(ErrorColumn(0, 1, 2)))
def test_add_y_err_duplicate_column(self): mc = MarkedColumns() ec = ErrorColumn(2, 4, 0) mc.add_y_err(ec) self.assertEqual(1, len(mc.as_y_err)) mc.add_y_err(ec) self.assertEqual(1, len(mc.as_y_err)) ec2 = ErrorColumn(3, 5, 0) mc.add_y_err(ec2) self.assertEqual(2, len(mc.as_y_err)) mc.add_y_err(ec2) self.assertEqual(2, len(mc.as_y_err))
def test_add_y_err(self): """ Test adding YErr columns that do not overlap in any way """ mc = MarkedColumns() ec = ErrorColumn(2, 4, 0) mc.add_y_err(ec) self.assertEqual(1, len(mc.as_y_err)) ec = ErrorColumn(3, 5, 0) mc.add_y_err(ec) self.assertEqual(2, len(mc.as_y_err)) ec = ErrorColumn(1, 6, 0) mc.add_y_err(ec) self.assertEqual(3, len(mc.as_y_err))
def test_build_labels_y_and_yerr_change_middle(self): mc = MarkedColumns() mc.add_y(0) mc.add_y(1) mc.add_y(2) # change one of the columns to YErr mc.add_y_err(ErrorColumn(1, 0, 0)) expected = [(0, '[Y0]'), (2, '[Y1]'), (1, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels()) # change the last Y column to YErr mc.add_y_err(ErrorColumn(2, 0, 0)) expected = [(0, '[Y0]'), (2, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels())
def test_build_labels_y_and_yerr_change_first(self): mc = MarkedColumns() mc.add_y(0) mc.add_y(1) mc.add_y(2) # change one of the columns to YErr mc.add_y_err(ErrorColumn(0, 1, 1)) # note: the first column is being set -> this decreases the label index of all columns to its right by 1 expected = [(1, '[Y0]'), (2, '[Y1]'), (0, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels()) # change the last Y column to YErr mc.add_y_err(ErrorColumn(2, 1, 0)) expected = [(1, '[Y0]'), (2, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels())
def test_remove_column(self): mc = MarkedColumns() mc.add_y(4) mc.add_x(3) ec = ErrorColumn(column=2, error_for_column=6, label_index=0) mc.add_y_err(ec) self.assertEqual(1, len(mc.as_x)) self.assertEqual(1, len(mc.as_y)) self.assertEqual(1, len(mc.as_y_err)) mc.remove(4) self.assertEqual(0, len(mc.as_y)) self.assertEqual(1, len(mc.as_y_err)) self.assertEqual(1, len(mc.as_x)) mc.remove(3) self.assertEqual(0, len(mc.as_x)) self.assertEqual(0, len(mc.as_y)) self.assertEqual(1, len(mc.as_y_err)) mc.remove(2) self.assertEqual(0, len(mc.as_x)) self.assertEqual(0, len(mc.as_y)) self.assertEqual(0, len(mc.as_y_err))
def test_find_yerr(self): mc = MarkedColumns() mc.add_y(0) mc.add_y(1) mc.add_y(2) mc.add_y(3) mc.add_y_err(ErrorColumn(4, 1, 1)) expected = {1: 4} self.assertEqual(expected, mc.find_yerr([1])) # Replace the Y column, which has an associated YErr. This should remove the YErr as well mc.add_y_err(ErrorColumn(1, 3, 1)) expected = {3: 1} self.assertEqual(expected, mc.find_yerr([0, 1, 2, 3])) mc.add_y_err(ErrorColumn(4, 2, 1)) expected = {2: 4, 3: 1} self.assertEqual(expected, mc.find_yerr([0, 1, 2, 3]))
def test_build_labels_x_y_and_yerr(self): mc = MarkedColumns() mc.add_y(0) mc.add_y(1) mc.add_y(2) mc.add_y(3) mc.add_y_err(ErrorColumn(1, 0, 0)) expected = [(0, '[Y0]'), (2, '[Y1]'), (3, '[Y2]'), (1, '[Y0_YErr]')] self.assertEqual(expected, mc.build_labels()) expected = [(1, '[X0]'), (0, '[Y0]'), (2, '[Y1]'), (3, '[Y2]')] mc.add_x(1) self.assertEqual(expected, mc.build_labels()) expected = [(1, '[X0]'), (2, '[Y0]'), (3, '[Y1]'), (0, '[Y1_YErr]')] mc.add_y_err(ErrorColumn(0, 3, 2)) self.assertEqual(expected, mc.build_labels())
def test_add_y_err_duplicate_column_different_reference_col(self): """ Test for adding a new YErr column with a _different_ source column but same reference column -> The new YErr must replace the old one """ mc = MarkedColumns() ec = ErrorColumn(column=2, error_for_column=4, label_index=0) mc.add_y_err(ec) self.assertEqual(1, len(mc.as_y_err)) self.assertEqual(2, mc.as_y_err[0].column) self.assertEqual(4, mc.as_y_err[0].error_for_column) # different source column but contains error for the same column # adding this one should replace the first one ec2 = ErrorColumn(column=3, error_for_column=4, label_index=0) mc.add_y_err(ec2) self.assertEqual(1, len(mc.as_y_err)) self.assertEqual(3, mc.as_y_err[0].column) self.assertEqual(4, mc.as_y_err[0].error_for_column)
def test_eq_versus_ErrorColumn(self): ec1 = ErrorColumn(0, 1, 0) ec2 = ErrorColumn(0, 1, 0) self.assertEqual(ec1, ec2) ec1 = ErrorColumn(0, 3, 0) ec2 = ErrorColumn(0, 1, 0) self.assertEqual(ec1, ec2) ec1 = ErrorColumn(2, 3, 0) ec2 = ErrorColumn(0, 3, 0) self.assertEqual(ec1, ec2)
def test_changing_y_to_none_removes_associated_yerr_columns(self): """ Test to check if a first column is marked as Y, a second column YErr is associated with it, but then the first one is changed to X - the YErr mark should be removed """ mc = MarkedColumns() mc.add_y(4) ec = ErrorColumn(column=2, error_for_column=4, label_index=0) mc.add_y_err(ec) # check that we have both a Y col and an associated YErr self.assertEqual(1, len(mc.as_y)) self.assertEqual(1, len(mc.as_y_err)) mc.remove(4) # changing the column to NONE should have removed it from X, Y and YErr self.assertEqual(0, len(mc.as_x)) self.assertEqual(0, len(mc.as_y)) self.assertEqual(0, len(mc.as_y_err))
def action_set_as_y_err(self, error_for_column, label_index): """ :param error_for_column: The real index of the column for which the error is being marked :param label_index: The index present in the label of the column for which the error is being marked This will be the number in <ColumnName>[Y10] -> the 10 """ try: selected_columns = self._get_selected_columns(1, "Too many selected to set as Y Error") except ValueError: return selected_column = selected_columns[0] try: err_column = ErrorColumn(selected_column, error_for_column, label_index) except ValueError as e: self.view.show_warning(e.message) return self.model.marked_columns.add_y_err(err_column) self.update_column_headers()
def test_raises_for_same_y_and_yerr(self): self.assertRaises(ValueError, lambda: ErrorColumn(2, 2, 3))
def test_correct_init(self): ErrorColumn(0, 1, 0)
def test_eq_unsupported_type(self): ec = ErrorColumn(150, 1, 0) self.assertRaises(RuntimeError, lambda: ec == "awd")
def test_eq_versus_same_int(self): ec = ErrorColumn(150, 1, 0) self.assertEqual(ec, 150)