def test_validation():
    h = '8a28308280fffff'  # invalid hex

    with pytest.raises(H3CellError):
        h3.h3_get_base_cell(h)

    with pytest.raises(H3CellError):
        h3.h3_get_resolution(h)

    with pytest.raises(H3CellError):
        h3.h3_to_parent(h, 9)

    with pytest.raises(H3CellError):
        h3.h3_distance(h, h)

    with pytest.raises(H3CellError):
        h3.k_ring(h, 1)

    with pytest.raises(H3CellError):
        h3.hex_ring(h, 1)

    with pytest.raises(H3CellError):
        h3.h3_to_children(h, 11)

    with pytest.raises(H3CellError):
        h3.compact({h})

    with pytest.raises(H3CellError):
        h3.uncompact({h}, 10)
示例#2
0
def test_uncompact_cell_input():
    # `uncompact` takes in a collection of cells, not a single cell.
    # Since a python string is seen as a Iterable collection,
    # inputting a single cell string can raise weird errors.

    # Ensure we get a reasonably helpful answer
    with pytest.raises(H3CellError):
        h3.uncompact('8001fffffffffff', 1)
def test_uncompact():

    h_uncomp, h_comp, res = test_compact()

    out = h3.uncompact(h_comp, res)

    assert out == h_uncomp
示例#4
0
def test_cell_perimiter_calculations():
    resolutions = [0, 1]

    for r in resolutions:
        cells = h3.uncompact(h3.get_res0_indexes(), r)
        for h in cells:
            for unit in ['rads', 'm', 'km']:
                v1 = cell_perimiter1(h, unit)
                v2 = cell_perimiter2(h, unit)

                assert v1 == pytest.approx(v2)
示例#5
0
def test_compact_and_uncompact():
    geo = {
        'type': 'Polygon',
        'coordinates': [
            [
                [37.813318999983238, -122.4089866999972145],
                [37.7866302000007224, -122.3805436999997056],
                [37.7198061999978478, -122.3544736999993603],
                [37.7076131999975672, -122.5123436999983966],
                [37.7835871999971715, -122.5247187000021967],
                [37.8151571999998453, -122.4798767000009008],
            ]
        ]
    }

    hexes = h3.polyfill(geo, 9)

    compact_hexes = h3.compact(hexes)
    assert len(compact_hexes) == 209

    uncompact_hexes = h3.uncompact(compact_hexes, 9)
    assert len(uncompact_hexes) == 1253
示例#6
0
def test_uncompact_error():
    hexagons = [h3.geo_to_h3(37, -122, 10)]

    with pytest.raises(Exception):
        h3.uncompact(hexagons, 5)
示例#7
0
def test_compact_and_uncompact_nothing():
    assert h3.compact([]) == set()
    assert h3.uncompact([], 9) == set()