Пример #1
0
def test_between():
    # allow reduction
    result = optimize(parse("5 BETWEEN 1 AND 6 AND attr = 1"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        1
    )
    result = optimize(parse("10 NOT BETWEEN 1 AND 6 AND attr = 1"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        1
    )

    # don't reduce if either lhs, low or high are uncertain
    result = optimize(parse("attr BETWEEN 1 AND 6"))
    assert result == ast.Between(
        ast.Attribute("attr"), 1, 6, False
    )
    result = optimize(parse("5 BETWEEN attr AND 6"))
    assert result == ast.Between(
        5, ast.Attribute("attr"), 6, False
    )
    result = optimize(parse("5 BETWEEN 1 AND attr"))
    assert result == ast.Between(
        5, 1, ast.Attribute("attr"), False
    )
Пример #2
0
def test_attribute_not_between():
    result = parse('attr NOT BETWEEN 2 AND 5')
    assert result == ast.Between(
        ast.Attribute('attr'),
        2,
        5,
        True,
    )
Пример #3
0
def test_attribute_between():
    result = parse('attr BETWEEN 2 AND 5')
    assert result == ast.Between(
        ast.Attribute('attr'),
        2,
        5,
        False,
    )
Пример #4
0
def test_attribute_between_negative_positive():
    result = parse('attr BETWEEN -1 AND 1')
    assert result == ast.Between(
        ast.Attribute('attr'),
        -1,
        1,
        False,
    )
Пример #5
0
def test_attribute_between_negative_positive():
    result = parse({"op": "between", "args": [{"property": "attr"}, [-1, 1]]})
    assert result == ast.Between(
        ast.Attribute("attr"),
        -1,
        1,
        False,
    )
Пример #6
0
def test_attribute_between():
    result = parse({"op": "between", "args": [{"property": "attr"}, [2, 5]]})
    assert result == ast.Between(
        ast.Attribute("attr"),
        2,
        5,
        False,
    )
Пример #7
0
def test_attribute_between():
    result = parse({
        "between": {
            "value": {
                "property": "attr"
            },
            "lower": 2,
            "upper": 5,
        }
    })
    assert result == ast.Between(
        ast.Attribute('attr'),
        2,
        5,
        False,
    )
Пример #8
0
def test_attribute_between_negative_positive():
    result = parse({
        "between": {
            "value": {
                "property": "attr"
            },
            "lower": -1,
            "upper": 1,
        }
    })
    assert result == ast.Between(
        ast.Attribute('attr'),
        -1,
        1,
        False,
    )
Пример #9
0
def test_is_between():
    result = parse('''
    <fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes">
      <fes:PropertyIsBetween>
        <fes:ValueReference>attr</fes:ValueReference>
        <fes:LowerBoundary>
          <fes:Literal type="xsd:double">10.5</fes:Literal>
        </fes:LowerBoundary>
        <fes:UpperBoundary>
          <fes:Literal type="xsd:double">11.5</fes:Literal>
        </fes:UpperBoundary>
      </fes:PropertyIsBetween>
    </fes:Filter>
    ''')
    assert result == ast.Between(
        ast.Attribute('attr'),
        10.5,
        11.5,
        not_=False,
    )