(array, dtype_cast, expected_image_format)
| 691 | ], |
| 692 | ) |
| 693 | def test_encode_np_array(array, dtype_cast, expected_image_format): |
| 694 | if dtype_cast.startswith("downcast"): |
| 695 | _, dest_dtype = dtype_cast.split("->") |
| 696 | dest_dtype = np.dtype(dest_dtype) |
| 697 | with pytest.warns(UserWarning, match=f"Downcasting array dtype.+{dest_dtype}.+"): |
| 698 | encoded_image = Image().encode_example(array) |
| 699 | elif dtype_cast == "error": |
| 700 | with pytest.raises(TypeError): |
| 701 | Image().encode_example(array) |
| 702 | return |
| 703 | else: # exact_match (no warnings are raised) |
| 704 | with warnings.catch_warnings(): |
| 705 | warnings.simplefilter("error") |
| 706 | encoded_image = Image().encode_example(array) |
| 707 | |
| 708 | assert isinstance(encoded_image, dict) |
| 709 | assert encoded_image.keys() == {"path", "bytes"} |
| 710 | assert encoded_image["path"] is None |
| 711 | assert encoded_image["bytes"] is not None and isinstance(encoded_image["bytes"], bytes) |
| 712 | decoded_image = Image().decode_example(encoded_image) |
| 713 | assert decoded_image.format == expected_image_format |
| 714 | np.testing.assert_array_equal(np.array(decoded_image), array) |
nothing calls this directly
no test coverage detected