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)
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)
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)
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)
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)
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)
def test_or_2(self): expected = ['(A == 1 OR B == 2)'] actual = ExOr({'A': 1}, {'B': 2}) self.assertListEqual(expected, actual)
def test_ex_or(self): expected = ['(A == 1 OR B == 2)'] actual = ExOr({'A': 1, 'B': 2}, order=['A', 'B']) self.assertListEqual(expected, actual)