def test_parse_table(self):
     table_definition = """
     [
         ['Event', 'Year'],
         ['French Revolution', Numeric(answer=1789)],
         ['Volcano exploded in 1883', Text(answer='Krakatoa')],
         [6.283, 123],
     ]
     """
     thead, tbody = parse_table(table_definition)
     expected = eval(table_definition.strip(), dict(Numeric=NumericCell, Text=TextCell))
     expected_body = []
     for i, row in enumerate(expected[1:], 1):
         cells = []
         for j, cell in enumerate(row):
             if not isinstance(cell, Cell):
                 cell = StaticCell(cell)
             cell.index = j
             cells.append(cell)
         expected_body.append(dict(index=i, cells=cells))
     self.assertEqual(thead, expected[0])
     self.assertEqual(tbody, expected_body)
Exemple #2
0
 def test_parse_table(self):
     table_definition = """
     [
         ['Event', 'Year'],
         ['French Revolution', Numeric(answer=1789)],
         ['Volcano exploded in 1883', Text(answer='Krakatoa')],
         [6.283, 123],
     ]
     """
     thead, tbody = parse_table(table_definition)
     expected = eval(table_definition.strip(),
                     dict(Numeric=NumericCell, Text=TextCell))
     expected_body = []
     for i, row in enumerate(expected[1:], 1):
         cells = []
         for j, cell in enumerate(row):
             if not isinstance(cell, Cell):
                 cell = StaticCell(cell)
             cell.index = j
             cells.append(cell)
         expected_body.append(dict(index=i, cells=cells))
     self.assertEqual(thead, expected[0])
     self.assertEqual(tbody, expected_body)
Exemple #3
0
 def test_parse_table_errors(self, table_definition):
     with self.assertRaises(ParseError):
         parse_table(table_definition)
 def test_parse_table_errors(self, table_definition):
     with self.assertRaises(ParseError):
         parse_table(table_definition)