Exemplo n.º 1
0
def test_binary_comparison_operator_invalid(type_, first, second, match_action,
                                            expected):
    with pytest.raises(expected):
        operators.BinaryComparisonOperator(operator_type=type_,
                                           first_expression=first,
                                           second_expression=second,
                                           match_action=match_action)
Exemplo n.º 2
0
def test_binary_comparison_operator_type(operator_type):
    first_expression = expressions.ValueReference("fake")
    second_expression = expressions.ValueReference("phony")
    operator = operators.BinaryComparisonOperator(
        operator_type=operator_type,
        first_expression=first_expression,
        second_expression=second_expression,
    )
    assert operator.operator_type == operators.BinaryComparisonName(
        operator_type)
Exemplo n.º 3
0
def test_fes20_examples_212_filter04():
    filter_ = """
        <?xml version="1.0"?>
        <fes:Filter
             xmlns:fes="http://www.opengis.net/fes/2.0"
             xmlns:gml="http://www.opengis.net/gml"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.opengis.net/fes/2.0 
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd
                 http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/geometry.xsd"
        >
            <fes:And>
                <fes:PropertyIsLessThan>
                    <fes:ValueReference>DEPTH</fes:ValueReference>
                    <fes:Literal>30</fes:Literal>
                </fes:PropertyIsLessThan>
                <fes:Not>
                    <fes:Disjoint>
                        <fes:ValueReference>Geometry</fes:ValueReference>
                        <gml:Box srsName="urn:fes:def:crs:EPSG::4326">
                            <gml:coordinates>
                                13.0983,31.5899 35.5472,42.8143
                            </gml:coordinates>
                        </gml:Box>
                    </fes:Disjoint>
                </fes:Not>
            </fes:And>
        </fes:Filter>
    """.strip(),
    expected = operators.BinaryLogicOperator(
        operator_type=operators.BinaryLogicType.AND,
        first_expression=operators.BinaryComparisonOperator(
            operator_type=operators.BinaryComparisonName.PROPERTY_IS_LESS_THAN,
            first_expression=expressions.ValueReference("DEPTH"),
            second_expression=expressions.Literal("30")),
        second_expression=operators.UnaryLogicOperator(
            operator_type=operators.UnaryLogicType.NOT,
            operand=operators.BinarySpatialOperator(
                operator_type=operators.SpatialOperatorName.DISJOINT,
                first_operand=expressions.ValueReference("Geometry"),
                second_operand=None,
            )))
    result = parsers.parse_filter(filter_)
    assert result == expected
Exemplo n.º 4
0
def test_fes20_examples_212_filter02():
    filter_ = """
        <?xml version="1.0"?>
        <fes:Filter
             xmlns:fes="http://www.opengis.net/fes/2.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.opengis.net/fes/2.0 
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd"
        >
            <fes:PropertyIsLessThan>
                <fes:ValueReference>DEPTH</fes:ValueReference>
                <fes:Literal>30</fes:Literal>
            </fes:PropertyIsLessThan>
        </fes:Filter>
    """.strip()
    expected = operators.BinaryComparisonOperator(
        operators.BinaryComparisonName.PROPERTY_IS_LESS_THAN,
        first_expression=expressions.ValueReference("DEPTH"),
        second_expression=expressions.Literal("30"))
    result = parsers.parse_filter(filter_)
    assert result == expected
Exemplo n.º 5
0
    (expressions.ValueReference("first"),
     (expressions.Literal, expressions.Function)),
    (expressions.Literal("second"),
     (expressions.ValueReference, expressions.Function)),
    (expressions.Function("third"),
     (expressions.ValueReference, expressions.Literal)),
])
def test_validate_operand_invalid(operand, allowed):
    with pytest.raises(errors.InvalidExpressionError):
        operators.validate_operand(operand=operand, allowed_types=allowed)


@pytest.mark.parametrize("first, second", [
    (operators.BinaryComparisonOperator(
        operator_type=operators.BinaryComparisonName.PROPERTY_IS_EQUAL_TO,
        first_expression=expressions.ValueReference("this"),
        second_expression=expressions.Literal("that"),
        match_action=operators.MatchAction.ANY,
        match_case=True),
     operators.BinaryComparisonOperator(
         operator_type=operators.BinaryComparisonName.PROPERTY_IS_EQUAL_TO,
         first_expression=expressions.ValueReference("this"),
         second_expression=expressions.Literal("that"),
         match_action=operators.MatchAction.ANY,
         match_case=True)),
])
def test_operator_equality(first, second):
    assert first == second


@pytest.mark.parametrize("operator_type", [
    "PropertyIsEqualTo",