From ac184aecb14e520afb13dced81bf04762595c143 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 16 Nov 2021 16:57:09 +0100 Subject: [PATCH] test intervals colormap --- src/titiler/core/tests/test_dependencies.py | 12 ++++++++++++ src/titiler/core/tests/test_factories.py | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/titiler/core/tests/test_dependencies.py b/src/titiler/core/tests/test_dependencies.py index e86dcfd3c..71021b9f7 100644 --- a/src/titiler/core/tests/test_dependencies.py +++ b/src/titiler/core/tests/test_dependencies.py @@ -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.""" diff --git a/src/titiler/core/tests/test_factories.py b/src/titiler/core/tests/test_factories.py index 4c292d4f8..d9ee1ce5f 100644 --- a/src/titiler/core/tests/test_factories.py +++ b/src/titiler/core/tests/test_factories.py @@ -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( @@ -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}")