From 70467b96611ae069f146c6c50fae9118fee6939e Mon Sep 17 00:00:00 2001 From: Jim Rybarski Date: Sun, 11 Oct 2015 13:59:25 -0500 Subject: [PATCH] Added functional tests --- CHANGELOG.md | 1 + Makefile | 4 +++ ftests.py | 6 ++++ functional_tests/FYLM141111001.py | 56 +++++++++++++++++++++++++++++++ functional_tests/__init__.py | 0 nd2reader/model/image.py | 4 +-- 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 ftests.py create mode 100644 functional_tests/FYLM141111001.py create mode 100644 functional_tests/__init__.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 975412a..090c0dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### ADDED - `Image` objects now have a `frame_number` attribute. - `Nd2` can be used as a context manager. +- More unit tests and functional tests ### CHANGED - `Image` objects now directly subclass Numpy arrays. diff --git a/Makefile b/Makefile index 2a8c0b9..c6af2e3 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,7 @@ test: build docker run --rm -it jimrybarski/nd2reader python3.4 /opt/nd2reader/tests.py docker run --rm -it jimrybarski/nd2reader python2.7 /opt/nd2reader/tests.py +functest: build + docker run --rm -v ~/nd2s:/var/nd2s -it jimrybarski/nd2reader python3.4 /opt/nd2reader/ftests.py + docker run --rm -v ~/nd2s:/var/nd2s -it jimrybarski/nd2reader python2.7 /opt/nd2reader/ftests.py + diff --git a/ftests.py b/ftests.py new file mode 100644 index 0000000..71a362b --- /dev/null +++ b/ftests.py @@ -0,0 +1,6 @@ +import unittest +from functional_tests.FYLM141111001 import FunctionalTests + + +if __name__ == '__main__': + unittest.main() diff --git a/functional_tests/FYLM141111001.py b/functional_tests/FYLM141111001.py new file mode 100644 index 0000000..0b18170 --- /dev/null +++ b/functional_tests/FYLM141111001.py @@ -0,0 +1,56 @@ +""" +These tests require that you have a specific ND2 file created by the developer of nd2reader. You will never need to +run them unless you're Jim Rybarski. + +""" +from nd2reader import Nd2 +from datetime import datetime +import unittest + + +class FunctionalTests(unittest.TestCase): + def setUp(self): + self.nd2 = Nd2("/var/nd2s/FYLM-141111-001.nd2") + + def tearDown(self): + self.nd2.close() + + def test_shape(self): + self.assertEqual(self.nd2.height, 1280) + self.assertEqual(self.nd2.width, 800) + + def test_date(self): + self.assertEqual(self.nd2.date, datetime(2014, 11, 11, 15, 59, 19)) + + def test_length(self): + self.assertEqual(len(self.nd2), 30528) + + def test_frames(self): + self.assertEqual(len(self.nd2.frames), 636) + + def test_fovs(self): + self.assertEqual(len(self.nd2.fields_of_view), 8) + + def test_channels(self): + self.assertTupleEqual(tuple(sorted(self.nd2.channels)), ('', 'GFP')) + + def test_z_levels(self): + self.assertTupleEqual(tuple(self.nd2.z_levels), (0, 1, 2)) + + def test_image(self): + image = self.nd2[14] + self.assertEqual(image.field_of_view, 2) + self.assertEqual(image.frame_number, 0) + self.assertAlmostEqual(image.timestamp, 19.0340758) + self.assertEqual(image.channel, '') + self.assertEqual(image.z_level, 1) + self.assertEqual(image.height, self.nd2.height) + self.assertEqual(image.width, self.nd2.width) + + def test_last_image(self): + image = self.nd2[30526] + self.assertEqual(image.frame_number, 635) + + def test_bad_image(self): + image = self.nd2[13] + self.assertIsNone(image) diff --git a/functional_tests/__init__.py b/functional_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nd2reader/model/image.py b/nd2reader/model/image.py index 39e10a5..af738a4 100644 --- a/nd2reader/model/image.py +++ b/nd2reader/model/image.py @@ -40,11 +40,11 @@ class Image(np.ndarray): @property def height(self): - return self.shape[1] + return self.shape[0] @property def width(self): - return self.shape[0] + return self.shape[1] @property def field_of_view(self):