def test_chain_select_where(self): table = Table(self.rows, self.columns) new_table = table.select(('one', 'two')).where(lambda r: r['two'] == 3) self.assertEqual(len(new_table.rows), 1) self.assertSequenceEqual(new_table.rows[0], (2, 3)) self.assertEqual(len(new_table.columns), 2) self.assertSequenceEqual(new_table._column_types, (self.number_type, self.number_type)) self.assertEqual(new_table._column_names, ('one', 'two')) self.assertSequenceEqual(new_table.columns['one'], (2,))
def test_chain_select_where(self): table = Table(self.rows, self.columns) new_table = table.select(('one', 'two')).where(lambda r: r['two'] == 3) self.assertEqual(len(new_table.rows), 1) self.assertSequenceEqual(new_table.rows[0], (2, 3)) self.assertEqual(len(new_table.columns), 2) self.assertSequenceEqual(new_table._column_types, (self.number_type, self.number_type)) self.assertEqual(new_table._column_names, ('one', 'two')) self.assertSequenceEqual(new_table.columns['one'], (2, ))
def test_select(self): table = Table(self.rows, self.columns) new_table = table.select(('three',)) self.assertIsNot(new_table, table) self.assertEqual(len(new_table.rows), 3) self.assertSequenceEqual(new_table.rows[0], ('a',)) self.assertSequenceEqual(new_table.rows[1], ('b',)) self.assertSequenceEqual(new_table.rows[2], (u'👍',)) self.assertEqual(len(new_table.columns), 1) self.assertSequenceEqual(new_table._column_types, (self.text_type,)) self.assertSequenceEqual(new_table._column_names, ('three',)) self.assertSequenceEqual(new_table.columns['three'], ('a', 'b', u'👍'))
def test_select(self): table = Table(self.rows, self.columns) new_table = table.select(('three', )) self.assertIsNot(new_table, table) self.assertEqual(len(new_table.rows), 3) self.assertSequenceEqual(new_table.rows[0], ('a', )) self.assertSequenceEqual(new_table.rows[1], ('b', )) self.assertSequenceEqual(new_table.rows[2], (u'👍', )) self.assertEqual(len(new_table.columns), 1) self.assertSequenceEqual(new_table._column_types, (self.text_type, )) self.assertSequenceEqual(new_table._column_names, ('three', )) self.assertSequenceEqual(new_table.columns['three'], ('a', 'b', u'👍'))
def test_select_does_not_exist(self): table = Table(self.rows, self.columns) with self.assertRaises(KeyError): table.select(('four',))
def test_select_with_row_names(self): table = Table(self.rows, self.columns, row_names='three') new_table = table.select(('three',)) self.assertSequenceEqual(new_table.rows['a'], ('a',)) self.assertSequenceEqual(new_table.row_names, ('a', 'b', u'👍'))
def test_select_does_not_exist(self): table = Table(self.rows, self.columns) with self.assertRaises(KeyError): table.select(('four', ))
def test_select_with_row_names(self): table = Table(self.rows, self.columns, row_names='three') new_table = table.select(('three', )) self.assertSequenceEqual(new_table.rows['a'], ('a', )) self.assertSequenceEqual(new_table.row_names, ('a', 'b', u'👍'))