示例#1
0
 def test_sum_expressions_2(self):
     expected = ['(A == 1 AND (B == 2 OR C == 3))', '(D == 1 OR E == 2)']
     actual = Ex({'A': 1}, ExOr({
         'B': 2,
         'C': 3
     }, order=['B', 'C'])) + ExOr({
         'D': 1,
         'E': 2
     }, order=['D', 'E'])
     self.assertListEqual(expected, actual)
示例#2
0
 def test_deep_nested(self):
     expected = [
         '(A == 1 AND (B == 2 AND (C == 3 OR D == 4 OR (E == 5 OR F == 6))))'
     ]
     actual = Ex({'A': 1},
                 Ex({'B': 2},
                    ExOr({
                        'C': 3,
                        'D': 4
                    },
                         ExOr({
                             'E': 5,
                             'F': 6
                         }, order=['E', 'F']),
                         order=['C', 'D'])))
     self.assertListEqual(expected, actual)
示例#3
0
    def test_select_from_where(self):
        """Asserts Statement object Where"""
        scenarios = [{
            'expected': 'WHERE A == 1',
            'elements': ('A == 1', )
        }, {
            'expected': 'WHERE A == 1',
            'elements': (Ex({'A': 1}), )
        }, {
            'expected': 'WHERE A == 1',
            'elements': (Ex({'A': op.equal(1)}), )
        }, {
            'expected': 'WHERE A > 1',
            'elements': (Ex({'A': op.bigger(1)}), )
        }, {
            'expected': 'WHERE A >= 1',
            'elements': (Ex({'A': op.bigger_or_equal(1)}), )
        }, {
            'expected': 'WHERE A < 1',
            'elements': (Ex({'A': op.smaller(1)}), )
        }, {
            'expected': 'WHERE A <= 1',
            'elements': (Ex({'A': op.smaller_or_equal(1)}), )
        }, {
            'expected': 'WHERE A <> 1',
            'elements': (Ex({'A': op.different(1)}), )
        }, {
            'expected': 'WHERE DAY IN (20, 30, 40)',
            'elements': (Ex({'DAY': [20, 30, 40]}), )
        }, {
            'expected': 'WHERE DAY IN (20, 30, 40)',
            'elements': (Ex({'DAY': op.in_operator([20, 30, 40])}), )
        }, {
            'expected': 'WHERE DAY IN (\'20\', \'30\', \'40\')',
            'elements': (Ex({'DAY': ['20', '30', '40']}), )
        }, {
            'expected':
            'WHERE REFERENCE_DAY BETWEEN \'20170101\' AND \'20170731\'',
            'elements':
            ('REFERENCE_DAY BETWEEN \'20170101\' AND \'20170731\'', )
        }, {
            'expected':
            'WHERE REFERENCE_DAY BETWEEN \'20170701\' AND \'20170731\'',
            'elements':
            (Ex({'REFERENCE_DAY': op.between('20170701', '20170731')}), )
        }, {
            'expected': 'WHERE A == 1 OR B == 1',
            'elements': ('A == 1 OR B == 1', )
        }, {
            'expected': 'WHERE (A == 1 OR B == 1)',
            'elements': (ExOr({
                'A': 1,
                'B': 1
            }, order=['A', 'B']), )
        }, {
            'expected':
            'WHERE (A == 1 AND (B == 2 OR C == 3))',
            'elements': (Ex(Ex({'A': 1}),
                            ExOr({
                                'B': 2,
                                'C': 3
                            }, order=['B', 'C'])), )
        }, {
            'expected': 'WHERE A == 1 AND B == 2',
            'elements': (Ex({
                'A': 1
            }).add(Ex({'B': 2})), )
        }, {
            'expected': 'WHERE A == 1 AND B == 2',
            'elements': (Ex({'A': 1}) + Ex({'B': 2}), )
        }]
        for scenario in scenarios:
            elements = scenario['elements']
            expected = scenario['expected']

            statement = Where().add(*elements)
            actual = statement.parse()
            self.assertEqualQueries(expected, actual)
示例#4
0
 def test_multiple_calls_nested(self):
     expected = ['(A == 1 AND (B == 2 OR C == 3))', '(D == 1 OR E == 2)']
     actual = Ex({'A': 1}, ExOr({'B': 2, 'C': 3}, order=['B', 'C'])) \
         .add(ExOr({'D': 1, 'E': 2}, order=['D', 'E']))
     self.assertListEqual(expected, actual)
示例#5
0
 def test_or_and_combination(self):
     expected = ['(A == 1 OR (B == 2 AND C == 3))']
     actual = ExOr({'A': 1}, Ex({'B': 2, 'C': 3}, order=['B', 'C']))
     self.assertListEqual(expected, actual)
示例#6
0
 def test_and_or_combination_2(self):
     expected = ['(A == 1 AND (B == 2 OR C == 3))']
     actual = Ex(Ex({'A': 1}), ExOr({'B': 2, 'C': 3}, order=['B', 'C']))
     self.assertListEqual(expected, actual)
示例#7
0
 def test_or_2(self):
     expected = ['(A == 1 OR B == 2)']
     actual = ExOr({'A': 1}, {'B': 2})
     self.assertListEqual(expected, actual)
示例#8
0
 def test_ex_or(self):
     expected = ['(A == 1 OR B == 2)']
     actual = ExOr({'A': 1, 'B': 2}, order=['A', 'B'])
     self.assertListEqual(expected, actual)