Example #1
0
    def test_write_read_roundtrip(self, num_channels, datatype, pass_channels):
        expected_image, expected_channels = _MakeTestImage(
            num_channels, datatype)
        with tempfile.NamedTemporaryFile() as temp:
            exr.write_exr(temp.name, expected_image, expected_channels)
            image, channels = exr.read_exr(
                temp.name, expected_channels if pass_channels else None)

        self.assertEqual(expected_channels, channels)
        self.assertEqual(image.tolist(), expected_image.tolist())
Example #2
0
 def test_reading_unknown_exr_type_fails(self):
   image, channels = _MakeTestImage(3, np.float16)
   with tempfile.NamedTemporaryFile() as temp:
     exr.write_exr(temp.name, image, channels)
     exr_file = OpenEXR.InputFile(temp.name)
     # Deliberately break the R channel header info. A mock InputFile is
     # required to override the header() method.
     header_dict = exr_file.header()
     header_dict['channels']['R'].type.v = -1  # Any bad value will do.
     make_mock_exr = collections.namedtuple('MockExr', ['header', 'channel'])
     mock_broken_exr = make_mock_exr(lambda: header_dict, exr_file.channel)
     with self.assertRaisesRegexp(RuntimeError, 'Unknown EXR channel type'):
       _ = exr.channels_to_ndarray(mock_broken_exr, ['R', 'G', 'B'])
Example #3
0
 def test_writing_unsupported_numpy_type_fails(self):
     uint8_array = np.zeros([64, 64, 3], dtype=np.uint8)
     names = ['R', 'G', 'B']
     with tempfile.NamedTemporaryFile() as temp:
         with self.assertRaisesRegexp(TypeError, 'Unsupported numpy type'):
             exr.write_exr(temp.name, uint8_array, names)