From 03cc6b0e2079531c2a404eb965cbbabf890c7ed6 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Thu, 24 Nov 2011 17:19:22 +0100 Subject: [PATCH] Lambda functions allow assertRaises without errors. Implemented display_single_image function. Searching for a way to run all tests at the same time. --- tippy/display_operations.py | 20 ++++++++++++++++---- tippy/tests/test_basic_operations.py | 6 +++--- tippy/tests/test_display_operations.py | 10 +++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tippy/display_operations.py b/tippy/display_operations.py index 55dc15c..e15c126 100644 --- a/tippy/display_operations.py +++ b/tippy/display_operations.py @@ -10,16 +10,28 @@ Created on Nov 19, 2011 import sys import cv -def display_single_image(img, name="Image", x_pos=0, y_pos=0, wait=0): +def display_single_image(img, name="Image", x_pos=0, y_pos=0, delay=0): """ Displays an image on screen. Position can be chosen, and time on screen too. - Wait is diplay time, in milliseconds. - If wait =0, the Image stays on screen until user interaction. + Delay corresponds to the diplay time, in milliseconds. + If delay =0, the Image stays on screen until user interaction. ---- Ex: img = cv.LoadImage("../data/tippy.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE) display_single_image(img, "My Tippy", 0, 0, 100) """ #TODO: Still not implemented! - pass \ No newline at end of file + + if not isinstance(name, str): + raise TypeError("(%s) Name :String expected!" % (sys._getframe().f_code.co_name)) + if (not isinstance(x_pos, int)) \ + or (not isinstance(x_pos, int)) \ + or (not isinstance(x_pos, int)) : # TODO: find more pythonic way to do that ! + raise TypeError("(%s) Int expected!" % (sys._getframe().f_code.co_name)) + + cv.NamedWindow(name) + cv.MoveWindow(name, x_pos, y_pos) + cv.ShowImage(name, img) + cv.WaitKey(delay) + \ No newline at end of file diff --git a/tippy/tests/test_basic_operations.py b/tippy/tests/test_basic_operations.py index 70d98c2..daf7ffb 100644 --- a/tippy/tests/test_basic_operations.py +++ b/tippy/tests/test_basic_operations.py @@ -37,7 +37,7 @@ class Test(unittest.TestCase): self.assertEqual(img.nChannels, out_img.nChannels) self.assertEqual(img.depth, out_img.depth) self.assertEqual(cv.GetSize(img), cv.GetSize(out_img)) - self.assertRaises(TypeError, bo.create_same_image(self.fake_img)) #TODO: Problem here :s + self.assertRaises(TypeError, lambda: bo.create_same_image(self.fake_img)) -if __name__ == "__main__": - unittest.main() \ No newline at end of file +#if __name__ == "__main__": + #unittest.main() \ No newline at end of file diff --git a/tippy/tests/test_display_operations.py b/tippy/tests/test_display_operations.py index 9c411fa..fb66a9c 100644 --- a/tippy/tests/test_display_operations.py +++ b/tippy/tests/test_display_operations.py @@ -30,9 +30,9 @@ class Test(unittest.TestCase): ## TESTS def test_display_single_image(self): #exception still to be found! - self.assertRaises(TypeError, display_single_image(self.img, x_pos="A")) - self.assertRaises(TypeError, display_single_image(self.img, name=2)) - self.assertRaises(TypeError, display_single_image(self.fake_img )) + self.assertRaises(TypeError, lambda: do.display_single_image(self.img, x_pos="A")) + self.assertRaises(TypeError, lambda: do.display_single_image(self.img, name=2)) + self.assertRaises(TypeError, lambda: do.display_single_image(self.fake_img )) -if __name__ == "__main__": - unittest.main() \ No newline at end of file +#if __name__ == "__main__": + #unittest.main() \ No newline at end of file