get write tests passing on travis

This commit is contained in:
John Evans 2014-11-19 14:49:15 -05:00
commit 8f8e9eff85
2 changed files with 7 additions and 12 deletions

View file

@ -59,13 +59,12 @@ class TestDataEntryURL(unittest.TestCase):
def test_wrap_greyscale(self): def test_wrap_greyscale(self):
"""A single component should be wrapped as GREYSCALE.""" """A single component should be wrapped as GREYSCALE."""
j = Jp2k(self.jp2file) j = Jp2k(self.jp2file)
data = j.read() data = j[:]
red = data[:, :, 0] red = data[:, :, 0]
# Write it back out as a raw codestream. # Write it back out as a raw codestream.
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile1: with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile1:
j2k = glymur.Jp2k(tfile1.name, 'wb') j2k = glymur.Jp2k(tfile1.name, data=red)
j2k.write(data[:, :, 0])
# Ok, now rewrap it as JP2. The colorspace should be GREYSCALE. # Ok, now rewrap it as JP2. The colorspace should be GREYSCALE.
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile2: with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile2:
@ -126,24 +125,21 @@ class TestChannelDefinition(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
"""Need a one_plane plane image for greyscale testing.""" """Need a one_plane plane image for greyscale testing."""
j2k = Jp2k(glymur.data.goodstuff()) j2k = Jp2k(glymur.data.goodstuff())
data = j2k.read() data = j2k[:]
# Write the first component back out to file. # Write the first component back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb') grey_j2k = Jp2k(tfile.name, data=data[:, :, 0])
grey_j2k.write(data[:, :, 0])
cls.one_plane = tfile.name cls.one_plane = tfile.name
# Write the first two components back out to file. # Write the first two components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb') grey_j2k = Jp2k(tfile.name, data=data[:, :, 0:1])
grey_j2k.write(data[:, :, 0:1])
cls.two_planes = tfile.name cls.two_planes = tfile.name
# Write four components back out to file. # Write four components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
rgba_jp2 = Jp2k(tfile.name, 'wb')
shape = (data.shape[0], data.shape[1], 1) shape = (data.shape[0], data.shape[1], 1)
alpha = np.zeros((shape), dtype=data.dtype) alpha = np.zeros((shape), dtype=data.dtype)
data4 = np.concatenate((data, alpha), axis=2) data4 = np.concatenate((data, alpha), axis=2)
rgba_jp2.write(data4) rgba_jp2 = Jp2k(tfile.name, data=data4)
cls.four_planes = tfile.name cls.four_planes = tfile.name
@classmethod @classmethod

View file

@ -115,8 +115,7 @@ class TestPrinting(unittest.TestCase):
# OpenJPEG doesn't have such a file. # OpenJPEG doesn't have such a file.
data = glymur.Jp2k(self.jp2file)[::2, ::2] data = glymur.Jp2k(self.jp2file)[::2, ::2]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
j = glymur.Jp2k(tfile.name, 'wb') j = glymur.Jp2k(tfile.name, data=data)
j.write(data)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: