예제 #1
0
 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'])
예제 #2
0
    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)
예제 #3
0
    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'])
예제 #4
0
 def testAddEvent(self):
     table = Table('census', self.schema).data(self.df)
     table.subscribe_once('add', self.callback)
     self.callback_executed = False
     table.insert({'State': 'ES', 'life_meaning':42})
     self.assertTrue(self.callback_executed)