コード例 #1
0
 def test_save_file_content(self):
     excel_file = ExcelFile(self.test_file)
     excel_file.worksheet[self.test_cell] = self.test_value
     # Save file content
     with open(self.file_copy, 'wb') as f:
         f.write(excel_file.content())
     self.assert_cell_value(self.file_copy, self.test_cell, self.test_value)
コード例 #2
0
 def test_modify_file(self):
     copyfile(self.test_file, self.file_copy)
     excel_file = ExcelFile(self.file_copy)
     # Modify the file with a random value
     excel_file.worksheet[self.test_cell] = self.test_value
     excel_file.save()
     self.assert_cell_value(self.file_copy, self.test_cell, self.test_value)
コード例 #3
0
 def test_get_data_table(self):
     excel_file = ExcelFile(self.test_file)
     # Get data table with first row
     table = excel_file.get_data_table(skip_first_row=False)
     self.assertEqual(len(table), 3)
     self.assertEqual(len(table[0]), 3)
     # Get data table without first row
     table = excel_file.get_data_table()
     self.assertEqual(len(table), 2)
コード例 #4
0
 def test_create_file(self):
     excel_file = ExcelFile()
     excel_file.worksheet[self.test_cell] = self.test_value
     # Save without a file path should raise an exception
     with self.assertRaises(Exception):
         excel_file.save()
     # Save with a file path
     excel_file.save(self.file_copy)
     self.assert_cell_value(self.file_copy, self.test_cell, self.test_value)
コード例 #5
0
 def test_read_file_header(self):
     excel_file = ExcelFile(self.test_file)
     # Case sensitive
     self.assertTrue(
         excel_file.has_headers(["Header A", "Header AB", "header c"]))
     self.assertFalse(
         excel_file.has_headers(["header a", "header ab", "header c"]))
     # Case insensitive
     self.assertTrue(
         excel_file.has_headers(["header a", "header ab", "header c"],
                                re.IGNORECASE))
     # Column index
     self.assertEqual(excel_file.column_index("header A"), 1)
     self.assertEqual(excel_file.column_index("Header AB"), 2)
     self.assertEqual(
         excel_file.column_index("Header A", case_sensitive=True), 1)
     self.assertEqual(
         excel_file.column_index("header A", case_sensitive=True), -1)
     # Use another row as index
     excel_file.set_headers(2)
     self.assertTrue(
         excel_file.has_headers(["row 1", "col 2"], re.IGNORECASE))
コード例 #6
0
 def assert_cell_value(self, file_path, cell, value):
     excel_file = ExcelFile(file_path)
     self.assertEqual(excel_file.worksheet[cell].value, value)
コード例 #7
0
 def test_save_as_another_file(self):
     excel_file = ExcelFile(self.test_file)
     excel_file.worksheet[self.test_cell] = self.test_value
     # Save a copy of the file
     excel_file.save(self.file_copy)
     self.assert_cell_value(self.file_copy, self.test_cell, self.test_value)