Lambda functions allow assertRaises without errors.

Implemented display_single_image function. 

Searching for a way to run all tests at the same time.
This commit is contained in:
Julien Lengrand-Lambert
2011-11-24 17:19:22 +01:00
parent 04262918cb
commit 03cc6b0e20
3 changed files with 24 additions and 12 deletions

View File

@@ -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
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)

View File

@@ -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()
#if __name__ == "__main__":
#unittest.main()

View File

@@ -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()
#if __name__ == "__main__":
#unittest.main()