Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parent():
parent = mercantile.parent(486, 332, 10)
assert parent == (243, 166, 9)
assert parent.z == 9
def test_parent_fractional_tile():
with pytest.raises(mercantile.ParentTileError) as e:
mercantile.parent((243.3, 166.2, 9), zoom=1)
assert "the parent of a non-integer tile is undefined" in str(e.value)
def test_parent_invalid_args(args):
"""tile arg must have length 1 or 3"""
with pytest.raises(mercantile.TileArgParsingError):
mercantile.parent(*args)
def test_parent_fractional_zoom():
with pytest.raises(mercantile.InvalidZoomError) as e:
mercantile.parent((243, 166, 9), zoom=1.2)
assert "zoom must be an integer and less than" in str(e.value)
def test_parent_multi():
parent = mercantile.parent(486, 332, 10, zoom=8)
assert parent == (121, 83, 8)
assert parent.z == 8
def test_parent_bad_tile_zoom():
with pytest.raises(mercantile.InvalidZoomError) as e:
mercantile.parent((243.3, 166.2, 9), zoom=10)
assert "zoom must be an integer and less than" in str(e.value)
https://tools.ietf.org/html/rfc8142 and
https://tools.ietf.org/html/rfc7159).
$ echo "[486, 332, 10]" | mercantile parent
Output:
[243, 166, 9]
"""
src = normalize_input(input)
for line in iter_lines(src):
tile = json.loads(line)[:3]
if tile[2] - depth < 0:
raise click.UsageError("Invalid parent level: {0}".format(tile[2] - depth))
for i in range(depth):
tile = mercantile.parent(tile)
output = json.dumps(tile)
click.echo(output)