From 79e0b6c1b6baff609f7edbb415363401fde6a3b1 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 11 Oct 2009 13:57:07 +0200 Subject: [PATCH] Cleaned up ImageCollection and added tests for it. --- scikits/image/io/tests/test_io.py | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scikits/image/io/tests/test_io.py diff --git a/scikits/image/io/tests/test_io.py b/scikits/image/io/tests/test_io.py new file mode 100644 index 00000000..2ebdc71a --- /dev/null +++ b/scikits/image/io/tests/test_io.py @@ -0,0 +1,42 @@ +import os.path + +import numpy as np +from numpy.testing import * + +from scikits.image import data_dir +from scikits.image.io import io + + +class TestImageCollection(): + pattern = [os.path.join(data_dir, pic) for pic in ['camera.png', + 'color.png']] + + def setUp(self): + self.collection = io.ImageCollection(self.pattern) + + def test_len(self): + assert len(self.collection) == 2 + + def test_getitem(self): + num = len(self.collection) + for i in range(-num, num): + assert type(self.collection[i]) is np.ndarray + assert_array_almost_equal(self.collection[0], + self.collection[-num]) + + #assert_raises expects a callable, hence this do-very-little func + def return_img(n): + return self.collection[n] + assert_raises(IndexError, return_img, num) + assert_raises(IndexError, return_img, -num-1) + + def test_files_property(self): + assert isinstance(self.collection.files, list) + + def set_files(f): + self.collection.files = f + assert_raises(AttributeError, set_files, 'newfiles') + +if __name__ == "__main__": + run_module_suite() +