From 08eca8966ca5ec91e7677d4c61e22a51c35b92c0 Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Mon, 31 Aug 2020 10:40:47 +0200 Subject: [PATCH] Implemented test. --- tests/test_reader.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_reader.py b/tests/test_reader.py index cf0f22c..c28399d 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -16,18 +16,27 @@ class TestReader(unittest.TestCase): def test_extension(self): self.assertTrue('nd2' in ND2Reader.class_exts()) + def cmp_two_readers(self, r1, r2): + attributes = r1.data['image_attributes']['SLxImageAttributes'] + self.assertEqual(r2.metadata['width'], attributes['uiWidth']) + self.assertEqual(r2.metadata['height'], attributes['uiHeight']) + + self.assertEqual(r2.metadata['width'], r2.sizes['x']) + self.assertEqual(r2.metadata['height'], r2.sizes['y']) + + self.assertEqual(r2.pixel_type, np.float64) + self.assertEqual(r2.iter_axes, ['t']) + def test_init_and_init_axes(self): with ArtificialND2('test_data/test_nd2_reader.nd2') as artificial: with ND2Reader('test_data/test_nd2_reader.nd2') as reader: - attributes = artificial.data['image_attributes']['SLxImageAttributes'] - self.assertEqual(reader.metadata['width'], attributes['uiWidth']) - self.assertEqual(reader.metadata['height'], attributes['uiHeight']) + self.cmp_two_readers(artificial, reader) - self.assertEqual(reader.metadata['width'], reader.sizes['x']) - self.assertEqual(reader.metadata['height'], reader.sizes['y']) - - self.assertEqual(reader.pixel_type, np.float64) - self.assertEqual(reader.iter_axes, ['t']) + def test_init_from_handler(self): + with ArtificialND2('test_data/test_nd2_reader.nd2') as artificial: + with open('test_data/test_nd2_reader.nd2', "rb") as FH: + with ND2Reader(FH) as reader: + self.cmp_two_readers(artificial, reader) def test_init_empty_file(self): with ArtificialND2('test_data/empty.nd2', skip_blocks=['label_map_marker']):