def setUp(self): """Builds a simple table to test the stylesheet """ self.table = Table() self.table.create_row('row1') self.table.create_columns(['a', 'b', 'c']) self.stylesheet = TableStyleSheet() # We don't want anything to be printed self.stdout_backup = sys.stdout sys.stdout = StringIO()
def test_stylesheet_init(self): """tests Stylesheet.__init__""" rule = '0_2 = 1' sheet = TableStyleSheet([rule, 'bad rule']) self.assertEqual(len(sheet.rules), 1, "Ill-formed rule mustn't be added") self.assertEqual(len(sheet.instructions), 1, "Ill-formed rule mustn't be added")
def setUp(self): """Builds a simple table to test the stylesheet """ self.table = Table() self.table.create_row('row1') self.table.create_columns(['a','b','c']) self.stylesheet = TableStyleSheet() # We don't want anything to be printed self.stdout_backup = sys.stdout sys.stdout = StringIO()
class TableStyleSheetTC(TestCase): """The Stylesheet test case """ def setUp(self): """Builds a simple table to test the stylesheet """ self.table = Table() self.table.create_row('row1') self.table.create_columns(['a','b','c']) self.stylesheet = TableStyleSheet() # We don't want anything to be printed self.stdout_backup = sys.stdout sys.stdout = StringIO() def tearDown(self): sys.stdout = self.stdout_backup def test_add_rule(self): """Tests that the regex pattern works as expected. """ rule = '0_2 = sqrt(0_0**2 + 0_1**2)' self.stylesheet.add_rule(rule) self.table.set_row(0, [3,4,0]) self.table.apply_stylesheet(self.stylesheet) self.assertEqual(self.table[0], [3,4,5]) self.assertEqual(len(self.stylesheet.rules), 1) self.stylesheet.add_rule('some bad rule with bad syntax') self.assertEqual(len(self.stylesheet.rules), 1, "Ill-formed rule mustn't be added") self.assertEqual(len(self.stylesheet.instructions), 1, "Ill-formed rule mustn't be added") def test_stylesheet_init(self): """tests Stylesheet.__init__""" rule = '0_2 = 1' sheet = TableStyleSheet([rule, 'bad rule']) self.assertEqual(len(sheet.rules), 1, "Ill-formed rule mustn't be added") self.assertEqual(len(sheet.instructions), 1, "Ill-formed rule mustn't be added") def test_rowavg_rule(self): """Tests that add_rowavg_rule works as expected """ self.table.set_row(0, [10,20,0]) self.stylesheet.add_rowavg_rule((0,2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[0,2] self.assert_(int(val) == 15) def test_rowsum_rule(self): """Tests that add_rowsum_rule works as expected """ self.table.set_row(0, [10,20,0]) self.stylesheet.add_rowsum_rule((0,2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[0,2] self.assert_(val == 30) def test_colavg_rule(self): """Tests that add_colavg_rule works as expected """ self.table.set_row(0, [10,20,0]) self.table.append_row([12,8,3], 'row2') self.table.create_row('row3') self.stylesheet.add_colavg_rule((2,0), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[2,0] self.assert_(int(val) == 11) def test_colsum_rule(self): """Tests that add_colsum_rule works as expected """ self.table.set_row(0, [10,20,0]) self.table.append_row([12,8,3], 'row2') self.table.create_row('row3') self.stylesheet.add_colsum_rule((2,0), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[2,0] self.assert_(val == 22)
class TableStyleSheetTC(TestCase): """The Stylesheet test case """ def setUp(self): """Builds a simple table to test the stylesheet """ self.table = Table() self.table.create_row('row1') self.table.create_columns(['a', 'b', 'c']) self.stylesheet = TableStyleSheet() # We don't want anything to be printed self.stdout_backup = sys.stdout sys.stdout = StringIO() def tearDown(self): sys.stdout = self.stdout_backup def test_add_rule(self): """Tests that the regex pattern works as expected. """ rule = '0_2 = sqrt(0_0**2 + 0_1**2)' self.stylesheet.add_rule(rule) self.table.set_row(0, [3, 4, 0]) self.table.apply_stylesheet(self.stylesheet) self.assertEqual(self.table[0], [3, 4, 5]) self.assertEqual(len(self.stylesheet.rules), 1) self.stylesheet.add_rule('some bad rule with bad syntax') self.assertEqual(len(self.stylesheet.rules), 1, "Ill-formed rule mustn't be added") self.assertEqual(len(self.stylesheet.instructions), 1, "Ill-formed rule mustn't be added") def test_stylesheet_init(self): """tests Stylesheet.__init__""" rule = '0_2 = 1' sheet = TableStyleSheet([rule, 'bad rule']) self.assertEqual(len(sheet.rules), 1, "Ill-formed rule mustn't be added") self.assertEqual(len(sheet.instructions), 1, "Ill-formed rule mustn't be added") def test_rowavg_rule(self): """Tests that add_rowavg_rule works as expected """ self.table.set_row(0, [10, 20, 0]) self.stylesheet.add_rowavg_rule((0, 2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[0, 2] self.assert_(int(val) == 15) def test_rowsum_rule(self): """Tests that add_rowsum_rule works as expected """ self.table.set_row(0, [10, 20, 0]) self.stylesheet.add_rowsum_rule((0, 2), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[0, 2] self.assert_(val == 30) def test_colavg_rule(self): """Tests that add_colavg_rule works as expected """ self.table.set_row(0, [10, 20, 0]) self.table.append_row([12, 8, 3], 'row2') self.table.create_row('row3') self.stylesheet.add_colavg_rule((2, 0), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[2, 0] self.assert_(int(val) == 11) def test_colsum_rule(self): """Tests that add_colsum_rule works as expected """ self.table.set_row(0, [10, 20, 0]) self.table.append_row([12, 8, 3], 'row2') self.table.create_row('row3') self.stylesheet.add_colsum_rule((2, 0), 0, 0, 1) self.table.apply_stylesheet(self.stylesheet) val = self.table[2, 0] self.assert_(val == 22)