test_core.py
1.1 kB · python · 36 lines
1import hashlib23import numpy as np45from mrlypy.core import Colorizer, codec, colors, ramp, tensor678def test_tensor_rot90(row):9 r = row("core::Tensor::rot90")10 grid = np.array(r["in"]["data"], dtype=np.uint8).reshape(r["in"]["shape"])11 out = tensor.rot90(grid, r["in"]["k"], tuple(r["in"]["axes"]))12 assert list(out.shape) == r["out"]["shape"]13 assert out.flatten().tolist() == r["out"]["data"]141516def test_color_from_hex(row):17 r = row("core::Color::from_hex")18 color = colors.from_hex(r["in"]["hex"])19 assert list(color) == r["out"]["rgba"]20 assert colors.to_hex(color) == r["out"]["hex"]212223def test_png(row):24 r = row("core::png")25 i = r["in"]26 png = codec.png(i["colors"], i["width"], i["height"], i["scale"])27 assert hashlib.sha256(png).hexdigest() == r["out"]282930def test_colorizer_color(row):31 r = row("core::Colorizer::color")32 i = r["in"]33 stops = [colors.from_hex(h) for h in i["ramp"]]34 colorizer = Colorizer.gradient_bins(colors.from_hex(i["background"]), stops, i["shades"])35 swatches = [colors.to_hex(ramp.color(colorizer, v, i["max"])) for v in i["values"]]36 assert swatches == r["out"]