def test_transform_PIL(self, typ): image = PIL.Image.new("RGBA", size=(50, 50), color=(155, 0, 0)) out = BytesIO() image.save(out, typ) value = PIL.Image.open(out) expected = "data:image/%s;base64," % typ + base64.b64encode(out.getvalue()).decode('ascii') prop = bcpv.Image() assert prop.transform(value) == expected
def test_transform_numpy(self): data = np.zeros((50, 50, 3), dtype=np.uint8) data[:, 30:35] = [255, 0, 0] value = PIL.Image.fromarray(data) out = BytesIO() value.save(out, "png") expected = "data:image/png;base64," + base64.b64encode(out.getvalue()).decode('ascii') prop = bcpv.Image() assert prop.transform(data) == expected
def test_validate_invalid(self): prop = bcpv.Image() assert not prop.is_valid(10) assert not prop.is_valid(True) assert not prop.is_valid(False) assert not prop.is_valid([]) assert not prop.is_valid({}) assert not prop.is_valid(set()) data = np.zeros((50, 50, 2), dtype=np.uint8) assert not prop.is_valid(data) data = np.zeros((50, 50), dtype=np.uint8) assert not prop.is_valid(data)
def test_str(self): prop = bcpv.Image() assert str(prop) == "Image"
def test_has_ref(self): prop = bcpv.Image() assert not prop.has_ref
def test_transform_bad(self): prop = bcpv.Image() with pytest.raises(ValueError): assert prop.transform(10)
def test_transform_None(self): prop = bcpv.Image() assert prop.transform(None) is None
def test_validate_PIL(self, typ): file = BytesIO() image = PIL.Image.new('RGBA', size=(50, 50), color=(155, 0, 0)) image.save(file, typ) prop = bcpv.Image() assert prop.is_valid(image)
def test_validate_numpy_RGBA(self): data = np.zeros((50, 50, 4), dtype=np.uint8) data[:, 30:35] = [255, 0, 0, 255] prop = bcpv.Image() assert prop.is_valid(data)
def test_validate_None(self): prop = bcpv.Image() assert prop.is_valid(None)
def test_validate_string(self): prop = bcpv.Image() assert prop.is_valid("string")
def test_default_creation(self): bcpv.Image()
def test_transform_data_url(self) -> None: prop = bcpv.Image() image = "data:image/png;base64," assert prop.transform(image) == image
def test_validate_raw_path(self) -> None: prop = bcpv.Image() assert prop.is_valid("some/path")
def test_validate_data_url(self) -> None: prop = bcpv.Image() assert prop.is_valid("data:image/png;base64,")
def test_default_creation(self) -> None: bcpv.Image()