def test_create_api_image_payload_numpy_image(): numpy_image = numpy.random.randint(0, 255, (16, 16)) data = create_api_image_payload(numpy_image) assert data is not None filepath, image_data, content_type = data assert filepath is None assert content_type == "image/png"
def test_create_api_image_payload_string_path_bad_type(): with ObserveWarnings() as w: path = "./test/runs/test_files/test.txt" data = create_api_image_payload(path) assert data is None assert len(w) == 1 assert issubclass(w[-1].category, RuntimeWarning)
def test_create_api_image_payload_string_path(image_path, expected_type): image_path = os.path.join("./test/runs/test_files", image_path) data = create_api_image_payload(image_path) assert data is not None filepath, image_data, content_type = data with image_data: image_data.seek(0) with open(image_path, "rb") as fp: original_contents = fp.read() assert image_data.read() == original_contents assert filepath == image_path assert content_type == expected_type
def test_create_api_image_payload_unsupported_type(): with ObserveWarnings() as w: data = create_api_image_payload({}) assert data is None assert len(w) >= 1 assert issubclass(w[-1].category, RuntimeWarning)
def test_create_api_image_payload_matplotlib_figure(matplotlib_figure): data = create_api_image_payload(matplotlib_figure) assert data is not None filepath, image_data, content_type = data assert filepath is None assert content_type == "image/svg+xml"
def test_create_api_image_payload_pil_image(pil_image): data = create_api_image_payload(pil_image) assert data is not None filepath, image_data, content_type = data assert filepath is None assert content_type == "image/png"