Skip to content

Commit ac184ae

Browse files
committed
test intervals colormap
1 parent 2bba8cc commit ac184ae

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/titiler/core/tests/test_dependencies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ def main(cm=Depends(dependencies.ColorMapParams)):
6363
response = client.get(f"/?colormap={cmap}")
6464
assert response.json()["1"] == [68, 1, 84, 255]
6565

66+
intervals = [
67+
# ([min, max], [r, g, b, a])
68+
([1, 2], [0, 0, 0, 255]),
69+
([2, 3], [255, 255, 255, 255]),
70+
([3, 1000], [255, 0, 0, 255]),
71+
]
72+
cmap = json.dumps(intervals)
73+
response = client.get(f"/?colormap={cmap}")
74+
assert response.json()[0] == [[1, 2], [0, 0, 0, 255]]
75+
assert response.json()[1] == [[2, 3], [255, 255, 255, 255]]
76+
assert response.json()[2] == [[3, 1000], [255, 0, 0, 255]]
77+
6678

6779
def test_default():
6880
"""test default dep behavior."""

src/titiler/core/tests/test_factories.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def test_TilerFactory():
106106
assert response.status_code == 200
107107
assert response.headers["content-type"] == "image/png"
108108

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

126+
# Intervals
127+
cmap = urlencode(
128+
{
129+
"colormap": json.dumps(
130+
[
131+
# ([min, max], [r, g, b, a])
132+
([1, 2], [0, 0, 0, 255]),
133+
([2, 3], [255, 255, 255, 255]),
134+
([3, 1000], [255, 0, 0, 255]),
135+
]
136+
)
137+
}
138+
)
139+
response = client.get(f"/tiles/8/84/47.png?url={DATA_DIR}/cog.tif&bidx=1&{cmap}")
140+
assert response.status_code == 200
141+
assert response.headers["content-type"] == "image/png"
142+
125143
# Bad colormap format
126144
cmap = urlencode({"colormap": json.dumps({"1": [58, 102]})})
127145
response = client.get(f"/tiles/8/84/47.png?url={DATA_DIR}/cog.tif&bidx=1&{cmap}")

0 commit comments

Comments
 (0)