MCPcopy
hub / github.com/huggingface/datasets / test_encode_np_array

Function test_encode_np_array

tests/features/test_image.py:693–714  ·  view source on GitHub ↗
(array, dtype_cast, expected_image_format)

Source from the content-addressed store, hash-verified

691 ],
692)
693def 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)

Callers

nothing calls this directly

Calls 5

ImageClass · 0.90
splitMethod · 0.80
dtypeMethod · 0.80
encode_exampleMethod · 0.45
decode_exampleMethod · 0.45

Tested by

no test coverage detected