Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_db_init(self):
# locally defined to return an empty ws
db = Database()
self.assertEqual(db._ws, {})
self.assertEqual(DB.ws('merged_cells').index(4, 3), 43)
self.assertEqual(DB.ws('merged_cells').index(5, 2), 52)
self.assertEqual(DB.ws('merged_cells').index(6, 1), 61)
self.assertEqual(DB.ws('merged_cells').index(7, 2), 72)
self.assertEqual(DB.ws('merged_cells').index(7, 3), 73)
self.assertEqual(DB.ws('merged_cells').index(8, 3), 83)
self.assertEqual(DB.ws('merged_cells').index(9, 1), 91)
self.assertEqual(DB.ws('merged_cells').index(9, 3), 93)
self.assertEqual(DB.ws('merged_cells').index(10, 3), 103)
def test_ws_length(self):
self.assertEqual(DB.ws('length').size, [1048576, 16384])
class test_Database(TestCase):
db = Database()
def test_db_badsheet(self):
db = Database()
with self.assertRaises(ValueError) as e:
db.ws('not a sheet')
self.assertEqual(e, 'Error - Sheetname (not a sheet) is not in the database')
def test_db_init(self):
# locally defined to return an empty ws
db = Database()
self.assertEqual(db._ws, {})
def test_db_repr(self):
self.assertEqual(str(self.db), 'pylightxl.Database')
def test_db_ws_names(self):
# test all input types
many_tag_cr_row1 = xml_tag_cr.format(address='A1', str_option='', tag_formula='', val=1) + \
xml_tag_cr.format(address='B1', str_option='t="s"', tag_formula='', val=0) + \
xml_tag_cr.format(address='C1', str_option='t="str"', tag_formula='A1+2', val='"pylightxl - open excel file and save it for formulas to calculate"')
# test scarce, and repeat text value
many_tag_cr_row3 = xml_tag_cr.format(address='A3', str_option='t="s"', tag_formula='', val=0) + \
xml_tag_cr.format(address='C3', str_option='t="s"', tag_formula='', val=1)
many_tag_row = xml_tag_row.format(row_num=1,num_of_cr_tags=3,many_tag_cr=many_tag_cr_row1) + \
xml_tag_row.format(row_num=3,num_of_cr_tags=2,many_tag_cr=many_tag_cr_row3)
uid = '2C7EE24B-C535-494D-AA97-0A61EE84BA40'
sizeAddress = 'A1:C3'
db = Database()
db.add_ws('Sheet1', {'A1':{'v': 1, 'f': '', 's': ''},
'B1':{'v': 'text1', 'f': '', 's': ''},
'C1':{'v': '=A1+2', 'f': '', 's': ''},
'A3':{'v': 'text1', 'f': '', 's': ''},
'C3':{'v': 'text2', 'f': '', 's': ''}})
self.assertEqual(new_worksheet_text(db, 'Sheet1'), xml_base.format(sizeAddress=sizeAddress,
uid=uid,
many_tag_row=many_tag_row))
def test_reading_written_ws(self):
file_path = 'temporary_test_file.xlsx'
db = Database()
db.add_ws('new_ws', {})
writexl(db, file_path)
db = readxl(file_path)
self.assertEqual(db.ws_names, ['new_ws'])
remove(file_path)
xml_tag_sheet = '\r\n'
xml_tag_sharedStrings = '\r\n'
many_tag_sheets = xml_tag_sheet.format(sheet_id=1) + \
xml_tag_sheet.format(sheet_id=2) + \
xml_tag_sheet.format(sheet_id=3) + \
xml_tag_sheet.format(sheet_id=4) + \
xml_tag_sheet.format(sheet_id=5) + \
xml_tag_sheet.format(sheet_id=6) + \
xml_tag_sheet.format(sheet_id=7) + \
xml_tag_sheet.format(sheet_id=8) + \
xml_tag_sheet.format(sheet_id=9) + \
xml_tag_sheet.format(sheet_id=10)
db = Database()
db.add_ws('Sheet1', {})
db.add_ws('Sheet2', {})
db.add_ws('Sheet3', {})
db.add_ws('Sheet4', {})
db.add_ws('Sheet5', {})
db.add_ws('Sheet6', {})
db.add_ws('Sheet7', {})
db.add_ws('Sheet8', {})
db.add_ws('Sheet9', {})
db.add_ws('Sheet10', {})
# test without and sharedStrings in db
self.assertEqual(new_content_types_text(db), xml_base.format(many_tag_sheets=many_tag_sheets, tag_sharedStrings=''))
# test with and sharedStrings in db
db._sharedStrings = ['text']
'16.0300\r\n' \
''
tag_vt = '{sheet_name}\r\n'
many_tag_vt = tag_vt.format(sheet_name='Sheet1') + \
tag_vt.format(sheet_name='Sheet2') + \
tag_vt.format(sheet_name='Sheet3') + \
tag_vt.format(sheet_name='Sheet4') + \
tag_vt.format(sheet_name='Sheet5') + \
tag_vt.format(sheet_name='Sheet6') + \
tag_vt.format(sheet_name='Sheet7') + \
tag_vt.format(sheet_name='Sheet8') + \
tag_vt.format(sheet_name='Sheet9') + \
tag_vt.format(sheet_name='Sheet10')
db = Database()
db.add_ws('Sheet1',{})
db.add_ws('Sheet2',{})
db.add_ws('Sheet3',{})
db.add_ws('Sheet4',{})
db.add_ws('Sheet5',{})
db.add_ws('Sheet6',{})
db.add_ws('Sheet7',{})
db.add_ws('Sheet8',{})
db.add_ws('Sheet9',{})
db.add_ws('Sheet10',{})
self.assertEqual(new_app_text(db), xml_base.format(num_sheets=10, many_tag_vt=many_tag_vt))
def test_db_badsheet(self):
db = Database()
with self.assertRaises(ValueError) as e:
db.ws('not a sheet')
self.assertEqual(e, 'Error - Sheetname (not a sheet) is not in the database')
def test_db_ws_names(self):
# locally defined to return an empty list
db = Database()
self.assertEqual(db.ws_names, [])
''
xml_tag_sheet = '\r\n'
tag_sharedStrings = '\r\n'
many_tag_sheets = xml_tag_sheet.format(sheet_num=1) + \
xml_tag_sheet.format(sheet_num=2) + \
xml_tag_sheet.format(sheet_num=3) + \
xml_tag_sheet.format(sheet_num=4) + \
xml_tag_sheet.format(sheet_num=5) + \
xml_tag_sheet.format(sheet_num=6) + \
xml_tag_sheet.format(sheet_num=7) + \
xml_tag_sheet.format(sheet_num=8) + \
xml_tag_sheet.format(sheet_num=9) + \
xml_tag_sheet.format(sheet_num=10)
db = Database()
db.add_ws('Sheet1',{})
db.add_ws('Sheet2',{})
db.add_ws('Sheet3',{})
db.add_ws('Sheet4',{})
db.add_ws('Sheet5',{})
db.add_ws('Sheet6',{})
db.add_ws('Sheet7',{})
db.add_ws('Sheet8',{})
db.add_ws('Sheet9',{})
db.add_ws('Sheet10',{})
# test without sharedStrings
self.assertEqual(new_workbookrels_text(db), xml_base.format(many_tag_sheets=many_tag_sheets, tag_sharedStrings=''))
# test with sharedStrings in db
db._sharedStrings = ['text']
self.assertEqual(new_workbookrels_text(db), xml_base.format(many_tag_sheets=many_tag_sheets, tag_sharedStrings=tag_sharedStrings))
''
xml_tag_sheet = '\r\n'
many_tag_sheets = xml_tag_sheet.format(sheet_name='Sheet1',order_id=1,ref_id=1) + \
xml_tag_sheet.format(sheet_name='Sheet2',order_id=2,ref_id=2) + \
xml_tag_sheet.format(sheet_name='Sheet3',order_id=3,ref_id=3) + \
xml_tag_sheet.format(sheet_name='Sheet4',order_id=4,ref_id=4) + \
xml_tag_sheet.format(sheet_name='Sheet5',order_id=5,ref_id=5) + \
xml_tag_sheet.format(sheet_name='Sheet6',order_id=6,ref_id=6) + \
xml_tag_sheet.format(sheet_name='Sheet7',order_id=7,ref_id=7) + \
xml_tag_sheet.format(sheet_name='Sheet8',order_id=8,ref_id=8) + \
xml_tag_sheet.format(sheet_name='Sheet9',order_id=9,ref_id=9) + \
xml_tag_sheet.format(sheet_name='Sheet10',order_id=10,ref_id=10)
db = Database()
db.add_ws('Sheet1',{})
db.add_ws('Sheet2',{})
db.add_ws('Sheet3',{})
db.add_ws('Sheet4',{})
db.add_ws('Sheet5',{})
db.add_ws('Sheet6',{})
db.add_ws('Sheet7',{})
db.add_ws('Sheet8',{})
db.add_ws('Sheet9',{})
db.add_ws('Sheet10',{})
self.assertEqual(new_workbook_text(db), xml_base.format(many_tag_sheets=many_tag_sheets))