Skip to content

Commit

Permalink
test intervals colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Nov 16, 2021
1 parent 2bba8cc commit ac184ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/titiler/core/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def main(cm=Depends(dependencies.ColorMapParams)):
response = client.get(f"/?colormap={cmap}")
assert response.json()["1"] == [68, 1, 84, 255]

intervals = [
# ([min, max], [r, g, b, a])
([1, 2], [0, 0, 0, 255]),
([2, 3], [255, 255, 255, 255]),
([3, 1000], [255, 0, 0, 255]),
]
cmap = json.dumps(intervals)
response = client.get(f"/?colormap={cmap}")
assert response.json()[0] == [[1, 2], [0, 0, 0, 255]]
assert response.json()[1] == [[2, 3], [255, 255, 255, 255]]
assert response.json()[2] == [[3, 1000], [255, 0, 0, 255]]


def test_default():
"""test default dep behavior."""
Expand Down
18 changes: 18 additions & 0 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_TilerFactory():
assert response.status_code == 200
assert response.headers["content-type"] == "image/png"

# Dict
cmap = urlencode(
{
"colormap": json.dumps(
Expand All @@ -122,6 +123,23 @@ def test_TilerFactory():
assert response.status_code == 200
assert response.headers["content-type"] == "image/png"

# Intervals
cmap = urlencode(
{
"colormap": json.dumps(
[
# ([min, max], [r, g, b, a])
([1, 2], [0, 0, 0, 255]),
([2, 3], [255, 255, 255, 255]),
([3, 1000], [255, 0, 0, 255]),
]
)
}
)
response = client.get(f"/tiles/8/84/47.png?url={DATA_DIR}/cog.tif&bidx=1&{cmap}")
assert response.status_code == 200
assert response.headers["content-type"] == "image/png"

# Bad colormap format
cmap = urlencode({"colormap": json.dumps({"1": [58, 102]})})
response = client.get(f"/tiles/8/84/47.png?url={DATA_DIR}/cog.tif&bidx=1&{cmap}")
Expand Down

0 comments on commit ac184ae

Please sign in to comment.