def test_table_get_set(self): table = Table(self.window, columns=('A', 'B', 'C')) table.pack() self.window.update() self.assertTrue(table.cget('sortable')) self.assertTrue(table['drag_cols']) self.assertTrue(table['drag_rows']) self.assertEqual(table.cget('columns'), ('A', 'B', 'C')) self.assertTrue(table.heading('A', 'command')) table.configure(sortable=False) self.assertFalse(table._sortable) self.assertFalse(table.heading('A', 'command')) table.configure(drag_cols=False) self.assertFalse(table._drag_cols) table.configure(drag_rows=False) self.assertFalse(table._drag_rows) table.configure(sortable=True) self.assertTrue(table._sortable) table.configure(drag_cols=True) self.assertTrue(table._drag_cols) table.configure(drag_rows=True) self.assertTrue(table._drag_rows) self.assertEqual(table.config('sortable'), ('sortable', table._sortable)) self.assertEqual(table.config('drag_cols'), ('drag_cols', table._drag_cols)) self.assertEqual(table.config('drag_rows'), ('drag_rows', table._drag_rows))
def test_table_methods(self): table = Table(self.window, columns=('A', 'B', 'C')) table.pack() self.window.update() self.assertEqual(table._visual_drag.cget('columns'), ('A', 'B', 'C')) table.configure(columns=('E', 'F', 'G')) self.assertEqual(table.cget('columns'), ('E', 'F', 'G')) self.assertEqual(table._visual_drag.cget('columns'), ('E', 'F', 'G')) for i in range(20): table.insert('', 'end', str(i), values=tuple(str(i) for a in 'EFG')) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) self.assertIs(table.column('E', 'type'), str) table.column('E', type=int) self.assertIs(table.column('E', 'type'), int) table.column('E', width=80) self.assertEqual(table._visual_drag.column('E', 'width'), 80) self.assertIn('type', table.column('G')) table.delete('0', '2') self.assertFalse('2' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.detach('1', '7') self.assertFalse('1' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.reattach('1', '', 0) self.assertTrue('1' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.heading('E', text='col E') self.assertEqual(table._visual_drag.heading('E', 'text'), 'col E') table.item('4', values=('a', 'b', 'c'), text='4') self.assertEqual(table._visual_drag.item('4', 'values'), ('a', 'b', 'c')) self.assertEqual(table._visual_drag.item('4', 'text'), '4') keys = [ 'columns', 'displaycolumns', 'show', 'selectmode', 'height', 'padding', 'xscrollcommand', 'yscrollcommand', 'takefocus', 'cursor', 'style', 'class', 'sortable', 'drag_cols' ] self.assertEqual(sorted(table.keys()), sorted(keys)) table.move('4', '', 0) self.assertEqual(table.get_children('')[0], '4') self.assertEqual(table._visual_drag.get_children('')[0], '4') table.configure(height=10) self.assertEqual(table.bbox('19'), '') self.assertEqual(table._visual_drag.bbox('19'), '') self.assertEqual(table.set('3', 'F'), '3') table.set('3', 'F', 'f') self.assertEqual(table._visual_drag.set('3', 'F'), 'f') table.set_children("", '4', '7') self.assertEqual(table.get_children(""), ('4', '7')) self.assertEqual(table._visual_drag.get_children(""), ('4', '7'))