Skip to content

Commit

Permalink
TST:RF: inherit Rois2MaskTifffile class for pillow testing
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lowe <[email protected]>
  • Loading branch information
swkeemink and scottclowe committed Jun 7, 2021
1 parent fbb04ef commit 4e952e0
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions fissa/tests/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,60 +121,11 @@ def teardown_class(self):
os.remove('test.tif')


class TestRois2MasksPillow(BaseTestCase):
'''Tests for rois2masks.'''
class TestRois2MasksPillow(TestRois2MasksTifffile):
'''Tests for rois2masks using DataHandlerPillow.'''
def setup_class(self):
self.polys = [np.array([[39., 62.], [60., 45.], [48., 71.]]),
np.array([[72., 107.], [78., 130.], [100., 110.]])]
self.expected = roitools.getmasks(self.polys, (176, 156))
self.data = Image.fromarray(np.zeros((176, 156), dtype=np.uint8))
self.datahandler = DataHandlerPillow()

def test_imagej_zip(self):
# load zip of rois
ROI_loc = os.path.join(self.test_directory, 'resources', 'RoiSet.zip')
actual = self.datahandler.rois2masks(ROI_loc, self.data)

# assert equality
self.assert_equal(actual, self.expected)

def test_arrays(self):
# load from array
actual = self.datahandler.rois2masks(self.polys, self.data)
# assert equality
self.assert_equal(actual, self.expected)

def test_transposed_polys(self):
# load from array
actual = self.datahandler.rois2masks([x.T for x in self.polys], self.data)
# assert equality
self.assert_equal(actual, self.expected)

def test_masks(self):
# load from masks
actual = self.datahandler.rois2masks(self.expected, self.data)

# assert equality
self.assert_equal(actual, self.expected)

def test_rois_not_list(self):
# check that rois2masks fails when the rois are not a list
with self.assertRaises(TypeError):
self.datahandler.rois2masks({}, self.data)
with self.assertRaises(TypeError):
self.datahandler.rois2masks(self.polys[0], self.data)

def test_polys_not_2d(self):
# check that rois2masks fails when the polys are not 2d
polys1d = [
np.array([[39.,]]),
np.array([[72.,]]),
]
with self.assertRaises(ValueError):
self.datahandler.rois2masks(polys1d, self.data)
polys3d = [
np.array([[39., 62., 0.], [60., 45., 0.], [48., 71., 0.]]),
np.array([[72., 107., 0.], [78., 130., 0.], [100., 110., 0.]]),
]
with self.assertRaises(ValueError):
self.datahandler.rois2masks(polys3d, self.data)

0 comments on commit 4e952e0

Please sign in to comment.