Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make colormap an independent dependency #252

Merged
merged 5 commits into from
Mar 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add customCmap tests
  • Loading branch information
vincentsarago committed Mar 5, 2021
commit fcd2ddfef0543d5eb4f83565317f932fff8b5261
56 changes: 56 additions & 0 deletions tests/test_CustomCmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# """Test TiTiler Custom Colormap Params."""

from enum import Enum
from io import BytesIO
from typing import Dict, Optional

import numpy
from rio_tiler.colormap import ColorMaps

from titiler.endpoints import factory

from .conftest import DATA_DIR

from fastapi import FastAPI, Query

from starlette.testclient import TestClient

cmap_values = {
"cmap1": {6: (4, 5, 6, 255)},
}
cmap = ColorMaps(data=cmap_values)
ColorMapNames = Enum( # type: ignore
"ColorMapNames", [(a, a) for a in sorted(cmap.list())]
)


def ColorMapParams(
color_map: ColorMapNames = Query(None, description="Colormap name",)
) -> Optional[Dict]:
"""Colormap Dependency."""
if color_map:
return cmap.get(color_map.value)
return None


def test_CustomCmap():
"""Test Custom Render Params dependency."""
app = FastAPI()
cog = factory.TilerFactory(colormap_dependency=ColorMapParams)
app.include_router(cog.router)
client = TestClient(app)

response = client.get(
f"/preview.npy?url={DATA_DIR}/above_cog.tif&bidx=1&color_map=cmap1"
)
assert response.status_code == 200
assert response.headers["content-type"] == "application/x-binary"
data = numpy.load(BytesIO(response.content))
assert 4 in data[0]
assert 5 in data[1]
assert 6 in data[2]

response = client.get(
f"/preview.npy?url={DATA_DIR}/above_cog.tif&bidx=1&color_map=another_cmap"
)
assert response.status_code == 422