コード例 #1
0
def test_logical_any():
    result = parse(
        ['any', ['<', ['get', 'height'], 50], ['!', ['get', 'occupied']]])
    assert result == ast.Or(ast.LessThan(
        ast.Attribute('height'),
        50,
    ), ast.Not(ast.Attribute('occupied')))
コード例 #2
0
def test_arithmetic_pow():
    result = parse(['>', ['^', ['get', 'size'], 2], 100])
    assert result == ast.GreaterThan(
        ast.Function(
            'pow',
            [ast.Attribute('size'), 2],
        ), 100)
コード例 #3
0
def test_attribute_during_dt_dt():
    result = parse([
        'during', ['get', 'attr'], '2000-01-01T00:00:00Z',
        '2000-01-01T00:00:01Z'
    ])

    assert result == ast.TimeDuring(
        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))),
        ),
    )
コード例 #4
0
def test_attribute_in_list():
    result = parse(['in', ['get', 'attr'], 1, 2, 3, 4])
    assert result == ast.In(ast.Attribute('attr'), [
        1,
        2,
        3,
        4,
    ], False)
コード例 #5
0
def test_arithmetic_ceil():
    result = parse(['==', ['ceil', ['get', 'age']], 42])
    assert result == ast.Equal(
        ast.Function(
            'ceil',
            [
                ast.Attribute('age'),
            ],
        ), 42)
コード例 #6
0
def test_attribute_arithmetic_div():
    result = parse(['==', ['get', 'attr'], ['/', 5, 2]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            5,
            2,
        ),
    )
コード例 #7
0
def test_arithmetic_abs():
    result = parse(['>', ['abs', ['get', 'delta']], 1])
    assert result == ast.GreaterThan(
        ast.Function(
            'abs',
            [
                ast.Attribute('delta'),
            ],
        ), 1)
コード例 #8
0
def test_arithmetic_modulo():
    result = parse(['==', ['get', 'attr'], ['%', 3, 7]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Function(
            'mod',
            [3, 7],
        ),
    )
コード例 #9
0
def test_arithmetic_max():
    result = parse(['>', ['max', ['get', 'wins'], ['get', 'ties']], 10])
    assert result == ast.GreaterThan(
        ast.Function(
            'max',
            [
                ast.Attribute('wins'),
                ast.Attribute('ties'),
            ],
        ), 10)
コード例 #10
0
def test_logical_all():
    result = parse([
        'all', ['>', ['get', 'height'], 50],
        ['==', ['get', 'type'], 'commercial'], ['get', 'occupied']
    ])
    assert result == ast.And(
        ast.And(ast.GreaterThan(
            ast.Attribute('height'),
            50,
        ), ast.Equal(ast.Attribute('type'), 'commercial')),
        ast.Attribute('occupied'))
コード例 #11
0
def test_string_like():
    result = parse(['like', ['get', 'attr'], 'some%'])
    assert result == ast.Like(
        ast.Attribute('attr'),
        'some%',
        nocase=False,
        wildcard='%',
        singlechar='.',
        escapechar='\\',
        not_=False,
    )
コード例 #12
0
def test_attribute_arithmetic_div_sub_bracketted():
    result = parse(['==', ['get', 'attr'], ['/', 3, ['-', 5, 2]]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            3,
            ast.Sub(
                5,
                2,
            ),
        ),
    )
コード例 #13
0
def test_intersects_attr_point():
    result = parse([
        'intersects', ['geometry'], {
            'type': 'Point',
            'coordinates': [1, 1],
        }
    ])
    assert result == ast.GeometryIntersects(
        ast.Attribute('geometry'),
        values.Geometry(normalize_geom(geometry.Point(1,
                                                      1).__geo_interface__)),
    )
コード例 #14
0
def test_attribute_arithmetic_add_mul():
    result = parse(['==', ['get', 'attr'], ['+', 3, ['*', 5, 2]]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Add(
            3,
            ast.Mul(
                5,
                2,
            ),
        ),
    )
コード例 #15
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]
        },
        ['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'),
    )
コード例 #16
0
def test_attribute_ne_literal():
    result = parse('["!=", ["get", "attr"], 5]')
    assert result == ast.NotEqual(
        ast.Attribute('attr'),
        5.0,
    )
コード例 #17
0
def test_attribute_gte_literal():
    result = parse('[">=", ["get", "attr"], 5]')
    assert result == ast.GreaterEqual(
        ast.Attribute('attr'),
        5.0,
    )
コード例 #18
0
def test_attribute_lt_literal():
    result = parse('["<", ["get", "attr"], 5]')
    assert result == ast.LessThan(
        ast.Attribute('attr'),
        5.0,
    )
コード例 #19
0
def test_attribute_eq_literal():
    result = parse('["==", ["get", "attr"], "A"]')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        'A',
    )
コード例 #20
0
def test_attribute_before():
    result = parse(['before', ['get', '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))),
    )
コード例 #21
0
def test_id_in_list():
    result = parse(['in', ['id'], 'someID', 'anotherID'])
    assert result == ast.In(ast.Attribute('id'), ['someID', 'anotherID'],
                            False)