Beispiel #1
0
 def test_dicts_to_table_simple_add(self):
     """ A simple test to add a new table based on dicts to a worksheet """
     tests.basicsetup(self)
     ws = self.workbook.create_sheet("testsheet")
     testdata = [dict(a = 1, b = 1, c = 1),
                 dict(a = 2, b = 2, c = 2),
                 dict(a = 3, b = 3, c = 3)]
     table = Tables.dicts_to_table(ws, testdata, start = "$A$1")
     testrange = AL_Excel.Range(ws,Tables.gettablesize(ws,1,1))
     self.assertEqual(testrange.startcoord,AL_Excel.Coordinate("A1"))
     self.assertEqual(testrange.endcoord,AL_Excel.Coordinate("C4"))
     output = table.todicts()[1:]
     self.assertEqual(len(output),len(testdata))
     self.assertEqual(output,testdata)
Beispiel #2
0
 def __init__(self,file):
     self._file=file
     xlsx=self.xlsx=AL_Excel.load_workbook(filename=str(file),data_only=True)
     self._sheets={sheet:xlsx[sheet] for sheet in xlsx.sheetnames}
     self._recordstatssheet = None
     self._recordstats = None
     self._showstatssheet = None
     self._showstats = None
     tables = Tables.get_all_tables(xlsx)
     tables = {table.displayName:table for (ws,table) in tables}
     try:
         table = tables['RecordStats']
     except KeyError:
         table = RecordStats.parsesheet(self._sheets['Record Stats'])
     self._recordstats = RecordStats(table,self)
     try:
         table = tables['Stats']
     except KeyError:
         table = ShowStats.parsesheet(self._sheets['Show Stats'])
     self._showstats = ShowStats(table = table, record = self)
             
     self._weeks={}
     weektables = {int(WEEKRE.search(name).group("number")):table for name,table in tables.items() if WEEKRE.match(name)}
     hypetables = {int(HYPERE.search(name).group("number")):table for name,table in tables.items() if HYPERE.match(name)}
     historytables = {int(HYPEHISTRE.search(name).group("number")):table for name, table in tables.items() if HYPEHISTRE.match(name)}
     for week,table in weektables.items():
         hypetable = hypetables.get(week)
         if self.recordstats.version < 4:
             s=RankingSheetV1(table,hypetable,self)
         else:
             historytable = historytables.get(week)
             s = RankingSheetV4(table, hypetable, self, historytable)
         s.setshowstats(self.showstats.shows)
         self._weeks[week]=s
Beispiel #3
0
 def test_gettablesize_singlecolumn(self):
     """ Tests that single column tables work """
     tests.basicsetup(self)
     ## This uses the first column of the greedycolumn table
     sheet = self.sheet_Tables4
     r1,c1 = 1,1
     self.assertEqual(Tables.gettablesize(sheet, c1, r1), "A1:A3")
Beispiel #4
0
 def test_gettablesize_notable(self):
     """ Tests that gettablesize on a blank row/column results in None"""
     tests.basicsetup(self)
     ## This uses the blank space between the two greedy table tests
     sheet = self.sheet_Tables4
     r1, c1 = 1,10
     self.assertIsNone(Tables.gettablesize(sheet, c1, r1))
Beispiel #5
0
 def test_gettablesize_blank_rows(self):
     """ Tests gettablesize with blank rows """
     tests.basicsetup(self)
     sheet = self.sheet_Tables4
     r1, c1 = 1,11
     for (greedyrows,result) in [(1,"K1:N4"),(2, "K1:N7")]:
         with self.subTest(greedyrows = greedyrows, result = result):
             self.assertEqual(Tables.gettablesize(sheet, c1, r1, greedyrows=greedyrows), result)
Beispiel #6
0
 def test_gettablesize_blank_columns(self):
     """ Tests gettablesize with blank columns """
     tests.basicsetup(self)
     sheet = self.sheet_Tables4
     r1, c1 = 1,1
     for (greedycolumns,result) in [(1,"A1:C3"),(2, "A1:G3")]:
         with self.subTest(greedycolumns = greedycolumns, result = result):
             self.assertEqual(Tables.gettablesize(sheet, c1, r1, greedycolumns=greedycolumns), result)
Beispiel #7
0
 def test_get_table_by_name(self):
     """ Basic Tests for get_table_by_name """
     tests.basicsetup(self)
     sheet = self.sheet_Tables1
     name = 'testtable_1'
     table = Tables.get_table_by_name(sheet,name)
     self.assertIsInstance(table,openpyxl.worksheet.table.Table)
     import collections
     self.assertEqual(dict(a = 1),collections.OrderedDict([("a",1),]))
     dicts = Tables.EnhancedTable.from_table(table,sheet).todicts()
     self.assertEqual(Tables.EnhancedTable.from_table(table,sheet).todicts(),[["Name","Value"],dict(Name="Hello",Value = 1),dict(Name="World",Value=2)])
Beispiel #8
0
 def test_get_all_tables(self):
     ## NOTE: get_all_tables was updated to account for Chartsheets: this test virtually ensures
     ##          that thos changes are effective as it would fail on this first line anyway, therefore
     ##          no additional test has been added to test the change
     tables = Tables.get_all_tables(self.workbook)
     self.assertEqual(len(tables),3)
     tablelookup = {table.name:{"worksheet":worksheet,"table":table} for worksheet,table in tables}
     for tablename,table in tests.DATA['TABLES'].items():
         with self.subTest(tablename=tablename,table = table):
             worksheet = getattr(self,table['worksheet'])
             ## Check correct name
             self.assertIn(table["name"],tablelookup)
             lookup = tablelookup[table["name"]]
             ## Check correct type
             self.assertIsInstance(lookup["table"],Tables.EnhancedTable)
             ## Check correct worksheet
             self.assertEqual(lookup["worksheet"],worksheet)
             ## Check correct range
             self.assertEqual(lookup["table"].ref,table["range"])
Beispiel #9
0
 def parsesheet(sheet):
     column = 1
     row = 1
     tableref = Tables.gettablesize(sheet,startcolumn = column, startrow = row)
     table = AL_Excel.EnhancedTable(worksheet = sheet, displayName = "RecordStats", ref = tableref)
     return table
Beispiel #10
0
 def setUp(self):
     tests.basicsetup(self)
     self.tables = {table.name:table for worksheet,table in Tables.get_all_tables(self.workbook)}
     return super().setUp()
Beispiel #11
0
 def test_gettablesize(self):
     """ Tests gettablesize for a variety of table shapes """
     tests.basicsetup(self)
     sheet = self.sheet_Tables3
     r1,c1 = 2,3
     self.assertEqual(Tables.gettablesize(sheet,c1,r1),"C2:F15")