1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import unittest
from panwid.datatable import *
from orderedattrdict import AttrDict
class TestDataTableWithIndex(unittest.TestCase):
def setUp(self):
self.data = [
dict(a=1, b=2.345, c="foo"),
dict(a=2, b=4.817, c="bar"),
dict(a=3, b=-3.19, c="baz")
]
self.columns = [
DataTableColumn("a"),
DataTableColumn("b"),
DataTableColumn("c")
]
def test_create(self):
dt = DataTable(self.columns, data=self.data, index="a")
dt.refresh()
self.assertEqual(len(dt), 3)
def test_create_without_index(self):
dt = DataTable(self.columns, data=self.data)
dt.refresh()
self.assertEqual(len(dt), 3)
def test_add_row_with_index(self):
dt = DataTable(self.columns, data=self.data, index="a")
dt.refresh()
dt.add_row(dict(a=4, b=7.142, c="qux"))
self.assertEqual(len(dt), 4)
def test_add_row_without_index(self):
dt = DataTable(self.columns, data=self.data)
dt.refresh()
dt.add_row(dict(a=4, b=7.142, c="qux"))
self.assertEqual(len(dt), 4)
|