From 1c87d982f8ca4c35a86cbb385b2764d7e74351df Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 22 Oct 2014 09:44:51 -0400 Subject: [PATCH] add negative test for writing non-uint8-uint16 images, closes #281 Improved the error message. --- glymur/jp2k.py | 3 ++- glymur/test/test_jp2k.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 6817dbc..264bd43 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -545,7 +545,8 @@ class Jp2k(Jp2kBox): raise IOError(msg) if img_array.dtype != np.uint8 and img_array.dtype != np.uint16: - msg = "Only uint8 and uint16 images are currently supported." + msg = "Only uint8 and uint16 datatypes are currently supported " + msg += "when writing." raise RuntimeError(msg) def _determine_colorspace(self, img_array, colorspace=None, **kwargs): diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 61ebdce..9df575f 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -843,6 +843,14 @@ class TestJp2k_write(unittest.TestCase): def tearDown(self): pass + def test_unsupported_datatype(self): + """Should raise a runtime error if trying to write uint32""" + data = np.zeros((128, 128), dtype=np.uint32) + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + with self.assertRaises(RuntimeError): + j = Jp2k(tfile.name, 'wb') + j.write(data) + def test_write_with_version_too_early(self): """Should raise a runtime error if trying to write with version 1.3""" data = np.zeros((128, 128), dtype=np.uint8)