| 40 | |
| 41 | @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, TEST_CASE_5, TEST_CASE_6]) |
| 42 | def test_shape_value(self, data_shape, filenames, expected_shape, meta_shape, reverse=True): |
| 43 | test_image = np.random.randint(0, 256, size=data_shape) |
| 44 | with tempfile.TemporaryDirectory() as tempdir: |
| 45 | for i, name in enumerate(filenames): |
| 46 | filenames[i] = os.path.join(tempdir, name) |
| 47 | Image.fromarray(test_image.astype("uint8")).save(filenames[i]) |
| 48 | reader = PILReader(mode="r", reverse_indexing=reverse) |
| 49 | result = reader.get_data(reader.read(filenames)) |
| 50 | # load image by PIL and compare the result |
| 51 | test_image = np.asarray(Image.open(filenames[0])) |
| 52 | |
| 53 | self.assertTupleEqual(tuple(result[1]["spatial_shape"]), meta_shape) |
| 54 | self.assertTupleEqual(result[0].shape, expected_shape) |
| 55 | if reverse: |
| 56 | test_image = np.moveaxis(test_image, 0, 1) |
| 57 | if result[0].shape == test_image.shape: |
| 58 | np.testing.assert_allclose(result[0], test_image) |
| 59 | else: |
| 60 | np.testing.assert_allclose(result[0], np.tile(test_image, [result[0].shape[0], 1, 1])) |
| 61 | |
| 62 | @parameterized.expand([TEST_CASE_7]) |
| 63 | def test_converter(self, data_shape, filenames, expected_shape, meta_shape): |