def test_expand_sheet_just_values(self): """Test the expanding of the sheet size if it has only values""" sheet = Sheet.create_new_sheet( self.nr_row, self.nr_col, rows_labels=self.rows_labels, columns_labels=self.columns_labels, rows_help_text=self.rows_help_text, columns_help_text=self.columns_help_text, excel_append_row_labels=True, excel_append_column_labels=True, warning_logger=lambda message: self.warnings.append(message), values_only=True ) self.assertTupleEqual(sheet.shape, (20, 30)) expand_row = 3 expand_col = 5 new_rows_labels = [f'LeR_{r_i}' for r_i in range(expand_row)] new_columns_labels = [f'LeC_{c_i}' for c_i in range(expand_col)] new_rows_help_text = [f'HeR_{r_i}' for r_i in range(expand_row)] new_columns_help_text = [f'HeC_{c_i}' for c_i in range(expand_col)] # Test expansion sheet.expand(3, 5, new_rows_labels=new_rows_labels, new_columns_labels=new_columns_labels, new_rows_help_text=new_rows_help_text, new_columns_help_text=new_columns_help_text ) self.assertTupleEqual(sheet.shape, (23, 35))
def setUp(self) -> None: self.warnings = [] self.nr_row = 20 self.nr_col = 30 self.rows_labels = [f"R_{r_i}" for r_i in range(self.nr_row)] self.columns_labels = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.rows_help_text = [f"HT_R_{r_i}" for r_i in range(self.nr_row)] self.columns_help_text = [f"HT_C_{c_i}" for c_i in range(self.nr_col)] self.native_rows = [f"NL_R_{r_i}" for r_i in range(self.nr_row)] self.native_cols = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.sheet = Sheet.create_new_sheet( self.nr_row, self.nr_col, { 'native': ( self.native_rows, self.native_cols ) }, rows_labels=self.rows_labels, columns_labels=self.columns_labels, rows_help_text=self.rows_help_text, columns_help_text=self.columns_help_text, excel_append_row_labels=True, excel_append_column_labels=True, warning_logger=lambda message: self.warnings.append(message) ) self.sheet_shape = (self.nr_row, self.nr_col)
def setUp(self) -> None: self.warnings = [] self.nr_row = 20 self.nr_col = 30 self.rows_labels = [f"R_{r_i}" for r_i in range(self.nr_row)] self.columns_labels = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.rows_help_text = [f"HT_R_{r_i}" for r_i in range(self.nr_row)] self.columns_help_text = [f"HT_C_{c_i}" for c_i in range(self.nr_col)] self.native_rows = [f"NL_R_{r_i}" for r_i in range(self.nr_row)] self.native_cols = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.sheet = Sheet.create_new_sheet( self.nr_row, self.nr_col, {'native': (self.native_rows, self.native_cols)}, rows_labels=self.rows_labels, columns_labels=self.columns_labels, rows_help_text=self.rows_help_text, columns_help_text=self.columns_help_text, excel_append_row_labels=True, excel_append_column_labels=True, warning_logger=lambda message: self.warnings.append(message)) self.sheet_shape = (self.nr_row, self.nr_col) # Add some random values: self.inserted_rand_values: np.ndarray = \ np.random.random(self.sheet_shape) * 1_000 self.sheet.iloc[:, :] = self.inserted_rand_values
def test_cross_reference(self): """Test the cross-reference (reference to another sheet)""" sheet = Sheet.create_new_sheet(3, 3) with self.assertRaises(ValueError): Cell.cross_reference(self.u_operand, sheet, sheet) u_reference = Cell.cross_reference(self.a_operand, sheet, sheet) u_ref_word = u_reference.parse self.assertEqual(u_ref_word['excel'], "=" + "'Results'!F5") self.assertEqual(u_ref_word['python_numpy'], "Results.values[3,4]")
def setUp(self) -> None: self.n_row = 13 self.n_col = 27 self.row_labels = [f"R_{r_i}" for r_i in range(self.n_row)] self.col_labels = [f"C_{c_i}" for c_i in range(self.n_col)] self.sheet = Sheet.create_new_sheet( self.n_row, self.n_col, rows_labels=self.row_labels, columns_labels=self.col_labels )
def test_to_list_skipped_labels(self): """Test when some labels are passed as SkippedLabel""" sheet = Sheet.create_new_sheet( 2, 3, name="Sheet", rows_labels=[SkippedLabel('A'), 'B'], columns_labels=['C1', SkippedLabel('C2'), 'C3']) sheet.iloc[:, :] = [[2, 1, 3], [7, 3, 9]] # Test the setter val_t = 72.8 sheet.loc['A', 'C2'] = val_t self.assertTrue( np.allclose(sheet.to_numpy(), [[2., val_t, 3.], [7., 3., 9.]])) # Test the getter self.assertAlmostEqual(sheet.loc['A', 'C2'].value, val_t) # Test export (regression test) self.assertListEqual( [['Sheet', 'C1', 'HH', 'C3'], ['HH', 2, 72.8, 3], ['B', 7, 3, 9]], sheet.to_list(skipped_label_replacement="HH"))
def setUp(self) -> None: self.warnings = [] self.nr_row = 5 self.nr_col = 4 self.rows_labels = [f"R_{r_i}" for r_i in range(self.nr_row)] self.columns_labels = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.rows_help_text = [f"HT_R_{r_i}" for r_i in range(self.nr_row)] self.columns_help_text = [f"HT_C_{c_i}" for c_i in range(self.nr_col)] self.native_rows = [f"NL_R_{r_i}" for r_i in range(self.nr_row)] self.native_cols = [f"NL_C_{c_i}" for c_i in range(self.nr_col)] self.sheet = Sheet.create_new_sheet( self.nr_row, self.nr_col, {'native': (self.native_rows, self.native_cols)}, name="Sheet", rows_labels=self.rows_labels, columns_labels=self.columns_labels, rows_help_text=self.rows_help_text, columns_help_text=self.columns_help_text, excel_append_row_labels=True, excel_append_column_labels=True, warning_logger=lambda message: self.warnings.append(message)) self.sheet_shape = (self.nr_row, self.nr_col) # Add some random values: self.inserted_rand_values: np.ndarray = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]]) self.sheet.iloc[:, :] = self.inserted_rand_values # Add some descriptions: for row_idx in range(self.nr_row): for col_idx in range(self.nr_col): self.sheet.iloc[row_idx, col_idx].description = \ f"DescFor{row_idx},{col_idx}" # Temporary directory for file exports self.working_dir = tempfile.mkdtemp()
def setUp(self) -> None: self.names = ['ABC', 'EFG'] self.sheet_a = Sheet.create_new_sheet(5, 5, name=self.names[0]) self.sheet_b = Sheet.create_new_sheet(5, 5, name=self.names[1]) self.workbook = WorkBook(self.sheet_a, self.sheet_b) self.temp_dir = tempfile.mkdtemp()