Exemple #1
0
def test_invalid_transformation_fn():
    with pytest.raises(ValueError):
        array_to_xpath([{
            '@never_defined_transform_fn': [
                'abc',
                'def',
            ]
        }])
Exemple #2
0
def test_if_expr():
    assert array_to_xpath([{
        '@if': [
            'condition',
            "'val1'",
            "'val2'",
        ]
    }]) == "if(condition, 'val1', 'val2')"
Exemple #3
0
def test_equiv_4():
    inp = [
        'a', {
            'something_b': 'b',
            'something_c': 'c'
        }, 'd', [['e', 'f', {
            'x': 'g'
        }]]
    ]
    expected = "abcdefg"
    assert expected == array_to_xpath(inp, _fns)
Exemple #4
0
def test_case_expression():
    inp = [{
        "@case": [
            ['s1', "'red'"],
            ['s2', "'yellow'"],
            ['s3', "'green'"],
            "'blinkred'",
        ]
    }]
    assert array_to_xpath(inp) == '''
        if(s1, 'red', if(s2, 'yellow', if(s3, 'green', 'blinkred')))
    '''.strip()
Exemple #5
0
def test_equiv_14():
    inp = [{
        'aa__q1': [{
            '@lookup': 'question_a'
        }, '!=', "'a'"]
    }, 'and', ['${question_b}', '<=', 123], 'and',
           [{
               '@not_multiselected': ['question_c', "'option_2'"]
           }], 'and', [{
               '@lookup': 'question_d'
           }, '=', "'option_2'"]]
    expected = "${question_a} != 'a' and ${question_b} <= 123 and not(selected(${question_c}, 'option_2')) and ${question_d} = 'option_2'"
    assert expected == array_to_xpath(inp, _fns)
Exemple #6
0
def test_equiv_13():
    inp = [{
        '@and': [[{
            '@lookup': 'a'
        }, '=', "'a'"], [{
            '@lookup': 'b'
        }, '=', "'b'"], [{
            '@lookup': 'c'
        }, '=', "'c'"]]
    }, 'and', {
        '@or': [[{
            '@lookup': 'x'
        }, '=', "'x'"], [{
            '@lookup': 'y'
        }, '=', "'y'"]]
    }]
    expected = "${a} = 'a' and ${b} = 'b' and ${c} = 'c' and ${x} = 'x' or ${y} = 'y'"
    assert expected == array_to_xpath(inp, _fns)
Exemple #7
0
def test_predicate():
    assert array_to_xpath([{'@predicate': ['abc']}]) == '[abc]'
def test_parens():
    assert array_to_xpath([{'@parens': ['123', '+', '456']}]) == '(123 + 456)'
Exemple #9
0
def test_or():
    assert array_to_xpath([{'@or': ['a', 'b']}]) == 'a or b'
Exemple #10
0
def test_equiv_7():
    inp = ['a', ['(', ['1', '2', '3'], ')']]
    expected = "a(123)"
    assert expected == array_to_xpath(inp, _fns)
def test_join():
    assert array_to_xpath([{'@join': ['and', ['a', 'b']]}]) == 'a and b'
Exemple #12
0
def test_not_multiselected():
    assert array_to_xpath([{'@not_multiselected': ['abc', 'xyz']}]) == 'not(selected(${abc}, xyz))'
Exemple #13
0
def test_equiv_3():
    inp = ['a', {'something': 'b'}, 'c']
    expected = "abc"
    assert expected == array_to_xpath(inp, _fns)
def test_equiv_1():
    inp = []
    expected = ""
    assert expected == array_to_xpath(inp, _fns)
def test_equiv_2():
    inp = [u'a', u'b']
    expected = "ab"
    assert expected == array_to_xpath(inp, _fns)
def test_count_selected():
    assert array_to_xpath([{'@count_selected': ['.']}]) == 'count-selected(.)'
def test_not_multiselected():
    assert array_to_xpath([{'@not_multiselected': ['abc', 'xyz']}]) == 'not(selected(${abc}, xyz))'
def test_selected_at():
    assert array_to_xpath([{'@selected_at': ['x', 'y']}]) == 'selected-at(x, y)'
def test_position():
    assert array_to_xpath([{'@position': ['abc']}]) == 'position(abc)'
def test_axis():
    assert array_to_xpath([{'@axis': ['aa', 'bb']}]) == 'aa::bb'
Exemple #21
0
def test_axis():
    assert array_to_xpath([{'@axis': ['aa', 'bb']}]) == 'aa::bb'
def test_equiv_3():
    inp = [u'a', {u'something': u'b'}, u'c']
    expected = "abc"
    assert expected == array_to_xpath(inp, _fns)
Exemple #23
0
def test_selected_at():
    assert array_to_xpath([{'@selected_at': ['x', 'y']}]) == 'selected-at(x, y)'
def test_equiv_4():
    inp = [u'a', {u'something_b': u'b', u'something_c': u'c'}, u'd', [[u'e', u'f', {u'x': u'g'}]]]
    expected = "abcdefg"
    assert expected == array_to_xpath(inp, _fns)
Exemple #25
0
def test_equiv_2():
    inp = ['a', 'b']
    expected = "ab"
    assert expected == array_to_xpath(inp, _fns)
def test_equiv_5():
    inp = [u'a', {u'# pound sign starts a comment': u'never added'}, u'b']
    expected = "ab"
    assert expected == array_to_xpath(inp, _fns)
Exemple #27
0
def test_equiv_5():
    inp = ['a', {'# pound sign starts a comment': 'never added'}, 'b']
    expected = "ab"
    assert expected == array_to_xpath(inp, _fns)
Exemple #28
0
def test_response_not_equal():
    assert array_to_xpath([{'@response_not_equal': ['abc', '123']}]
                          ) == '${abc} != 123'
def test_not():
    assert array_to_xpath([{'@not': ['x']}]) == 'not(x)'
Exemple #30
0
def test_join():
    assert array_to_xpath([{'@join': ['and', ['a', 'b']]}]) == 'a and b'
def test_equiv_6():
    inp = [u'a', [u'(', u')']]
    expected = "a()"
    assert expected == array_to_xpath(inp, _fns)
def test_predicate():
    assert array_to_xpath([{'@predicate': ['abc']}]) == '[abc]'
Exemple #33
0
def test_custom_directive():
    assert 'dlrow olleh' == array_to_xpath({
        '@string_reverse': 'hello world'
    }, {
        '@string_reverse': lambda args: [args[::-1]]
    })
def test_equiv_7():
    inp = [u'a', [u'(', [u'1', u'2', u'3'], u')']]
    expected = "a(123)"
    assert expected == array_to_xpath(inp, _fns)
Exemple #35
0
def test_and():
    assert array_to_xpath([{'@and': ['abc', 'def']}]) == 'abc and def'
def test_equiv_9():
    inp = [u'a', [u'(', [u'x', u'+', u'y', u',', u'z'], u')']]
    expected = "a(x + y, z)"
    assert expected == array_to_xpath(inp, _fns)
Exemple #37
0
def test_not():
    assert array_to_xpath([{'@not': ['x']}]) == 'not(x)'
def test_equiv_11():
    inp = [{u'@lookup': u'abc'}]
    expected = "${abc}"
    assert expected == array_to_xpath(inp, _fns)
Exemple #39
0
def test_parens():
    assert array_to_xpath([{'@parens': ['123', '+', '456']}]) == '(123 + 456)'
def test_equiv_12():
    inp = [{u'@response_not_equal': [u'question_a', u"'a'"]}]
    expected = "${question_a} != 'a'"
    assert expected == array_to_xpath(inp, _fns)
Exemple #41
0
def test_position():
    assert array_to_xpath([{'@position': ['abc']}]) == 'position(abc)'
def test_equiv_13():
    inp = [{u'@and': [[{u'@lookup': u'a'}, u'=', u"'a'"], [{u'@lookup': u'b'}, u'=', u"'b'"], [{u'@lookup': u'c'}, u'=', u"'c'"]]}, u'and', {u'@or': [[{u'@lookup': u'x'}, u'=', u"'x'"], [{u'@lookup': u'y'}, u'=', u"'y'"]]}]
    expected = "${a} = 'a' and ${b} = 'b' and ${c} = 'c' and ${x} = 'x' or ${y} = 'y'"
    assert expected == array_to_xpath(inp, _fns)
Exemple #43
0
def test_count_selected():
    assert array_to_xpath([{'@count_selected': ['.']}]) == 'count-selected(.)'
def test_custom_directive():
    assert u'dlrow olleh' == array_to_xpath({
        u'@string_reverse': u'hello world'
    }, {
        u'@string_reverse': lambda args: [args[::-1]]
    })
Exemple #45
0
def test_equiv_1():
    inp = []
    expected = ""
    assert expected == array_to_xpath(inp, _fns)
def test_equiv_14():
    inp = [{u'aa__q1': [{u'@lookup': u'question_a'}, u'!=', u"'a'"]}, u'and', [u'${question_b}', u'<=', 123], u'and', [{u'@not_multiselected': [u'question_c', u"'option_2'"]}], u'and', [{u'@lookup': u'question_d'}, u'=', u"'option_2'"]]
    expected = "${question_a} != 'a' and ${question_b} <= 123 and not(selected(${question_c}, 'option_2')) and ${question_d} = 'option_2'"
    assert expected == array_to_xpath(inp, _fns)
Exemple #47
0
 def _case(*items):
     return array_to_xpath([
         {'@case': list(items)}
     ])
Exemple #48
0
def test_equiv_11():
    inp = [{'@lookup': 'abc'}]
    expected = "${abc}"
    assert expected == array_to_xpath(inp, _fns)
Exemple #49
0
def test_comma_parens():
    assert array_to_xpath([
        {'@comma_parens': [
            ['a', 'b'],
        ]}
    ]) == '(a, b)'
def test_response_not_equal():
    assert array_to_xpath([{'@response_not_equal': ['abc', '123']}]
                          ) == '${abc} != 123'
Exemple #51
0
def test_equiv_6():
    inp = ['a', ['(', ')']]
    expected = "a()"
    assert expected == array_to_xpath(inp, _fns)
def test_and():
    assert array_to_xpath([{'@and': ['abc', 'def']}]) == 'abc and def'
Exemple #53
0
def test_equiv_9():
    inp = ['a', ['(', ['x', '+', 'y', ',', 'z'], ')']]
    expected = "a(x + y, z)"
    assert expected == array_to_xpath(inp, _fns)
def test_or():
    assert array_to_xpath([{'@or': ['a', 'b']}]) == 'a or b'
Exemple #55
0
def test_equiv_12():
    inp = [{'@response_not_equal': ['question_a', "'a'"]}]
    expected = "${question_a} != 'a'"
    assert expected == array_to_xpath(inp, _fns)
def test_lookup():
    assert array_to_xpath([{'@lookup': 'someval'}]) == '${someval}'