def test_sort_option_int(self): "Sorting the table by an int field, Number of Pages" t = TableFu(self.csv_file) pages = t.values('Number of Pages') pages = sorted(pages, reverse=True) t.sort('Number of Pages', reverse=True) self.assertEqual(t.values('Number of Pages'), pages)
def test_transform_to_int(self): """ Convert the Number of Pages field to integers """ t = TableFu(self.csv_file) pages = t.values('Number of Pages') t.transform('Number of Pages', int) for s, i in zip(pages, t.values('Number of Pages')): self.assertEqual(int(s), i)
def test_map_values(self): """ Test mapping a function to specific column values """ t = TableFu(self.table) result = [s.lower() for s in t.values('Style')] self.assertEqual(result, t.map(str.lower, 'Style'))
def test_row_map(self): """ Test map a function to rows, or a subset of fields """ t = TableFu(self.table) result = [s.lower() for s in t.values('Style')] self.assertEqual(result, t.map(lambda row: row['Style'].value.lower()))
def test_map_many_values(self): """ Test mapping a function to multiple columns """ t = TableFu(self.table) result = [[s.lower() for s in t.values(value)] for value in ['Best Book', 'Style']] self.assertEqual(result, t.map(str.lower, 'Best Book', 'Style'))
def test_map_many_values(self): """ Test mapping a function to multiple columns """ t = TableFu(self.table) result = [ [s.lower() for s in t.values(value)] for value in ['Best Book', 'Style'] ] self.assertEqual(result, t.map(str.lower, 'Best Book', 'Style'))
def test_values(self): "Return one column's values for all rows" t = TableFu(self.csv_file) self.table.pop(0) authors = [row[0] for row in self.table] self.assertEqual(authors, t.values('Author'))
def test_unique_values(self): "Adding unique=True returns a set" t = TableFu(self.table) self.table.pop(0) styles = set([row[-1] for row in self.table]) self.assertEqual(t.values('Style', unique=True), styles)