def test_from_float_unknown_dtype(): img = np.ones((100, 100, 3), dtype=np.float32) with pytest.raises(RuntimeError) as exc_info: F.from_float(img, np.dtype(np.int16)) assert str(exc_info.value) == ( "Can't infer the maximum value for dtype int16. You need to specify the maximum value manually by passing " "the max_value argument")
def test_from_float_with_max_value_specified(max_value): img = np.ones((100, 100, 3), dtype=np.float32) expected = (img * max_value).astype(np.uint32) assert_array_almost_equal_nulp( F.from_float(img, dtype=np.uint32, max_value=max_value), expected)
def test_from_float_without_max_value_specified(dtype, multiplier): img = np.ones((100, 100, 3), dtype=np.float32) expected = (img * multiplier).astype(dtype) assert_array_almost_equal_nulp(F.from_float(img, np.dtype(dtype)), expected)