def testColumnNames(self): table = Table('census', self.schema).data(self.df) self.assertEqual(len(table.column_names()), 22) view = table.find({}, {'Information':True, 'State':True}) self.assertEqual(view.column_names(), ['Information', 'State']) view2 = view.find({}, {'State':True}) self.assertEqual(view2.column_names(), ['State'])
def testColumnCount(self): table = Table('census', self.schema).data(self.df) self.assertEqual(table.column_count(), 22) view = table.find({}, {'Information':True, 'State':True}) self.assertEqual(view.column_count(), 2) view2 = view.find({}, {'State':True}) self.assertEqual(view2.column_count(), 1)
def testRowCount(self): table = Table('census', self.schema).data(self.df) self.assertEqual(table.row_count(), 51) view = table.find({'$or':[{'State': 'NY'},{'State': 'DC'}]}) self.assertEqual(view.row_count(), 2) view2 = view.find({'State': 'NY'}) self.assertEqual(view2.row_count(), 1)
def testIndexItems(self): table = Table('census', self.schema).data(self.df) table.insert({'State': 'DC', 'life_meaning':42}) view = table.find({'$or':[{'State': 'NY'},{'State': 'DC'}]}) self.assertIsInstance(view, TableView) distincts = view.index_items() self.assertEqual(len(distincts), 2) for result in distincts: self.assertIn(result, ['DC','NY'])
def testMultiFind(self): table = Table('census', self.schema).data(self.df) view = table.find({'$or':[{'State': 'NY'},{'State': 'DC'}]}) view2 = view.find({'Information':{'$gt': 200000}}) self.assertIsInstance(view, TableView) for result in view.get_data(): self.assertIn(result['State'], ['DC','NY']) for result in view2.get_data(): self.assertNotIn(result['State'], ['DC'])
def testInsert(self): table = Table('census', self.schema).data(self.df) c1 = table.row_count() table.insert({'State': 'ES', 'life_meaning':42}) self.assertEqual(table.row_count() - c1, 1) c2 = table.row_count() table.insert([{'State': 'ES', 'life_meaning':42}, {'State': 'ES2', 'life_meaning':42},]) self.assertEqual(table.row_count() - c2, 2) view = table.find({'life_meaning': {'$exists':True}}) self.assertEqual(view.row_count(), 3) self.assertEqual(table.find_one({'life_meaning': {'$exists':True}})['life_meaning'], 42)
def testDistinct(self): table = Table('census', self.schema).data(self.df) table.insert({'State': 'DC', 'life_meaning':42}) view = table.find({'$or':[{'State': 'NY'},{'State': 'DC'},{'State': 'CA'}]}) distincts = view.distinct('State') self.assertEqual(len(distincts), 3) for result in distincts: self.assertIn(result, ['DC','NY','CA']) distinct_view = view.distinct('State', as_view=True) self.assertIsInstance(distinct_view, TableView) result = distinct_view.get_data(outtype='c_list') self.assertEqual(result, {'State': ['NY', 'DC', 'CA']}) view2 = view.find({'Information':{'$gt': 200000}}) result = view2.distinct('State') self.assertEqual(result, ['NY', 'CA'])
def testFind(self): table = Table('census', self.schema).data(self.df) view = table.find({'$or':[{'State': 'NY'},{'State': 'DC'}]}) self.assertIsInstance(view, TableView) for result in view.get_data(): self.assertIn(result['State'], ['DC','NY'])
def testRemove(self): table = Table('census', self.schema).data(self.df) query = {'State': 'DC'} c1 = table.find(query).row_count() table.remove(query) self.assertGreater(c1, table.find(query).row_count())