Exemplo n.º 1
0
    def test_execute_datasource(self):
        select = Selector([('A', 'B'), ('1', '2'), ('1', '2')])
        query = Query(select, ['B'])
        query._query_steps = [
            ('map', (int, ), {}),
            ('map', (lambda x: x * 2, ), {}),
            ('sum', (), {}),
        ]
        result = query.execute()
        self.assertEqual(result, 8)

        query = Query(['A'])
        regex = "expected 'Selector', got 'list'"
        with self.assertRaisesRegex(TypeError, regex):
            query.execute(['hello',
                           'world'])  # <- Expects None or Query, not list!
Exemplo n.º 2
0
    def test_filter(self):
        query1 = Query(['col1'])
        query2 = query1.filter(lambda x: x == 'a')
        self.assertIsNot(query1, query2, 'should return new object')

        source = Selector([('col1', 'col2'), ('a', '2'), ('b', '2')])
        result = query2.execute(source)
        self.assertEqual(result.fetch(), ['a'])

        # No filter arg should default to bool()
        source = Selector([('col1', ), (1, ), (2, ), (0, ), (3, )])
        query = Query(set(['col1'])).filter()  # <- No arg!
        result = query.execute(source)
        self.assertEqual(result.fetch(), set([1, 2, 3]))