def test_cannot_create_from_non_Workbook_object(self): workbook = object() with self.assertRaises(ValueError): XlSheet(workbook, 'students')
def test_cannot_create_from_non_existing_file(self): filepath = '/tmp/schools.xlsx' with self.assertRaises(OSError): XlSheet(filepath, 'students')
def test_can_be_created_using_workbook_object(self): filepath = os.path.join(self.dir_base, 'fixtures', 'school.xlsx') workbook = openpyxl.load_workbook(filepath) xlsheet = XlSheet(workbook, 'students') self.assertIsNotNone(xlsheet)
def _get_xlsheet(self, sheet_name='students', row_offset=0): filepath = os.path.join(self.dir_base, 'fixtures', 'school.xlsx') xlsheet = XlSheet(filepath, sheet_name, row_offset=row_offset) return xlsheet
def test_can_limit_number_rows_checked_to_find_headers(self): xlsheet = self._get_xlsheet() XlSheet.max_row_check = 4 hdr_idx = XlSheet.find_headers(xlsheet, ['sn', 'name']) self.assertEqual(-1, hdr_idx)
def test_can_apply_offset_and_find_headers_using_valid_samples(self): xlsheet = self._get_xlsheet() hdr_idx = XlSheet.find_headers(xlsheet, ['sn', 'name'], row_offset=4) self.assertEqual(7, hdr_idx)
def test_cant_find_headers_using_invalid_samples(self): xlsheet = self._get_xlsheet() hdr_idx = XlSheet.find_headers(xlsheet, ['sn', 'age']) self.assertEqual(-1, hdr_idx)
def validate_column_headings(self): headers = (self.headers or ('fake-@#$%^',)) xlsheet = XlSheet(self._file_path, 'accounts') if not XlSheet.find_headers(xlsheet, headers): raise ValidationError("Expected columns not found.")