示例#1
0
def test_attribute_is_null():
    result = parse({
        "isNull": {"property": "attr"}
    })
    assert result == ast.IsNull(
        ast.Attribute('attr'), False
    )
示例#2
0
def test_attribute_aoverlaps():
    result = parse({
        "aoverlaps": [
            {"property": "arrayattr"},
            [1, 2, 3]
        ]
    })
    assert result == ast.ArrayOverlaps(
        ast.Attribute('arrayattr'),
        [1, 2, 3],
    )
示例#3
0
def test_attribute_acontainedby():
    result = parse({
        "acontainedBy": [
            {"property": "arrayattr"},
            [1, 2, 3]
        ]
    })
    assert result == ast.ArrayContainedBy(
        ast.Attribute('arrayattr'),
        [1, 2, 3],
    )
示例#4
0
def test_attribute_aequals():
    result = parse({
        "aequals": [
            {"property": "arrayattr"},
            [1, 2, 3]
        ]
    })
    assert result == ast.ArrayEquals(
        ast.Attribute('arrayattr'),
        [1, 2, 3],
    )
示例#5
0
def test_attribute_arithmetic_div():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"/": [5, 2]}
        ]
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            5,
            2,
        ),
    )
示例#6
0
def test_attribute_before():
    result = parse({
        "before": [
            {"property": "attr"},
            "2000-01-01T00:00:01Z",
        ]
    })
    assert result == ast.TimeBefore(
        ast.Attribute('attr'),
        datetime(
            2000, 1, 1, 0, 0, 1,
            tzinfo=StaticTzInfo('Z', timedelta(0))
        ),
    )
示例#7
0
def test_attribute_in_list():
    result = parse({
        "in": {
            "value": {"property": "attr"},
            "list": [1, 2, 3, 4],
        }
    })
    assert result == ast.In(
        ast.Attribute('attr'), [
            1,
            2,
            3,
            4,
        ],
        False
    )
示例#8
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,
    )
示例#9
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,
    )
示例#10
0
def test_meets_dt_dr():
    result = parse({
        "meets": [
            {"property": "attr"},
            ["2000-01-01T00:00:00Z", "PT4S"]
        ]
    })
    assert result == ast.TimeMeets(
        ast.Attribute('attr'),
        values.Interval(
            datetime(
                2000, 1, 1, 0, 0, 0,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
            timedelta(seconds=4),
        ),
    )
示例#11
0
def test_attribute_toverlaps_open_dt():
    result = parse({
        "toverlaps": [
            {"property": "attr"},
            ["..", "2000-01-01T00:00:03Z"]
        ]
    })
    assert result == ast.TimeOverlaps(
        ast.Attribute('attr'),
        values.Interval(
            None,
            datetime(
                2000, 1, 1, 0, 0, 3,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
        ),
    )
示例#12
0
def test_attribute_metby_dr_dt():
    result = parse({
        "metby": [
            {"property": "attr"},
            ["PT4S", "2000-01-01T00:00:03Z"]
        ]
    })
    assert result == ast.TimeMetBy(
        ast.Attribute('attr'),
        values.Interval(
            timedelta(seconds=4),
            datetime(
                2000, 1, 1, 0, 0, 3,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
        ),
    )
示例#13
0
def test_attribute_overlappedby_dt_open():
    result = parse({
        "overlappedby": [
            {"property": "attr"},
            ["2000-01-01T00:00:03Z", ".."]
        ]
    })
    assert result == ast.TimeOverlappedBy(
        ast.Attribute('attr'),
        values.Interval(
            datetime(
                2000, 1, 1, 0, 0, 3,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
            None,
        ),
    )
示例#14
0
def test_intersects_attr_point():
    result = parse({
        "intersects": [
            {"property": "geometry"},
            {
                "type": "Point",
                "coordinates": [1, 1],
            }
        ]
    })
    assert result == ast.GeometryIntersects(
        ast.Attribute('geometry'),
        values.Geometry(
            normalize_geom(
                geometry.Point(1, 1).__geo_interface__
            )
        ),
    )
示例#15
0
def test_string_ilike():
    result = parse({
        "like": {
            "like": [
                {"property": "attr"},
                "some%",
            ],
            "nocase": True,
        }
    })
    assert result == ast.Like(
        ast.Attribute('attr'),
        'some%',
        nocase=True,
        not_=False,
        wildcard='%',
        singlechar='.',
        escapechar='\\',
    )
示例#16
0
def test_function_single_arg():
    result = parse({
        "eq": [
            {"property": "attr"},
            {
                "function": {
                    "name": "myfunc",
                    "arguments": [1]
                }
            }
        ]
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Function(
            'myfunc',
            [1],
        ),
    )
示例#17
0
def test_disjoint_linestring_attr():
    result = parse({
        "disjoint": [
            {
                "type": "LineString",
                "coordinates": [[1, 1], [2, 2]],
                "bbox": [1.0, 1.0, 2.0, 2.0]
            },
            {"property": "geometry"},
        ]
    })
    assert result == ast.GeometryDisjoint(
        values.Geometry(
            normalize_geom(
                geometry.LineString([(1, 1), (2, 2)]).__geo_interface__
            ),
        ),
        ast.Attribute('geometry'),
    )
示例#18
0
def test_attribute_arithmetic_div_sub_bracketted():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"/": [
                3,
                {"-": [5, 2]},
            ]},
        ],
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            3,
            ast.Sub(
                5,
                2,
            ),
        ),
    )
示例#19
0
def test_attribute_arithmetic_add_mul():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"+": [
                3,
                {"*": [5, 2]},
            ]},
        ],
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Add(
            3,
            ast.Mul(
                5,
                2,
            ),
        ),
    )
示例#20
0
def test_attribute_after_dt_dt():
    result = parse({
        "after": [
            {"property": "attr"},
            ["2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z"]
        ]
    })

    assert result == ast.TimeAfter(
        ast.Attribute('attr'),
        values.Interval(
            datetime(
                2000, 1, 1, 0, 0, 0,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
            datetime(
                2000, 1, 1, 0, 0, 1,
                tzinfo=StaticTzInfo('Z', timedelta(0))
            ),
        ),
    )
示例#21
0
def test_overlaps_attr_multilinestring():
    result = parse({
        "overlaps": [
            {"property": "geometry"},
            {
                "type": "MultiLineString",
                "coordinates": [[[1, 1], [2, 2]], [[0, 3], [1, 1]]],
                "bbox": [0.0, 1.0, 2.0, 3.0]
            },
        ]
    })
    assert result == ast.GeometryOverlaps(
        ast.Attribute('geometry'),
        values.Geometry(
            normalize_geom(
                geometry.MultiLineString([
                    geometry.LineString([(1, 1), (2, 2)]),
                    geometry.LineString([(0, 3), (1, 1)]),
                ]).__geo_interface__
            ),
        ),
    )
示例#22
0
def test_within_multipolygon_attr():
    result = parse({
        "within": [
            {
                "type": "MultiPolygon",
                "coordinates": [
                    [[[1, 1], [2, 2], [0, 3], [1, 1]]]
                ],
                'bbox': [0.0, 1.0, 2.0, 3.0]
            },
            {"property": "geometry"},
        ]
    })
    assert result == ast.GeometryWithin(
        values.Geometry(
            normalize_geom(
                geometry.MultiPolygon([
                    geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
                ]).__geo_interface__
            ),
        ),
        ast.Attribute('geometry'),
    )
示例#23
0
def test_contains_attr_polygon():
    result = parse({
        "contains": [
            {"property": "geometry"},
            {
                "type": "Polygon",
                "coordinates": [
                    [[1, 1], [2, 2], [0, 3], [1, 1]]
                ],
                'bbox': [0.0, 1.0, 2.0, 3.0]
            },
        ]
    })
    assert result == ast.GeometryContains(
        ast.Attribute('geometry'),
        values.Geometry(
            normalize_geom(
                geometry.Polygon(
                    [(1, 1), (2, 2), (0, 3), (1, 1)]
                ).__geo_interface__
            ),
        ),
    )
示例#24
0
def test_function_attr_string_arg():
    result = parse({
        "eq": [
            {"property": "attr"},
            {
                "function": {
                    "name": "myfunc",
                    "arguments": [
                        {"property": "other_attr"},
                        "abc"
                    ]
                }
            }
        ]
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Function(
            'myfunc', [
                ast.Attribute('other_attr'),
                "abc",
            ]
        ),
    )
示例#25
0
def test_attribute_lt_literal():
    result = parse('{ "lt": [{ "property": "attr" }, 5]}')
    assert result == ast.LessThan(
        ast.Attribute('attr'),
        5.0,
    )
示例#26
0
def test_attribute_gte_literal():
    result = parse('{ "gte": [{ "property": "attr" }, 5]}')
    assert result == ast.GreaterEqual(
        ast.Attribute('attr'),
        5.0,
    )
示例#27
0
def test_attribute_eq_literal():
    result = parse('{ "eq": [{ "property": "attr" }, "A"]}')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        'A',
    )