From 293ea03dccfed383faebe6494b426a04993c5427 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 17 Sep 2015 18:14:49 +0300 Subject: [PATCH 1/3] test2.py: remove unused imports --- modules/python/test/test2.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/python/test/test2.py b/modules/python/test/test2.py index 9126160948..f9b46234b2 100644 --- a/modules/python/test/test2.py +++ b/modules/python/test/test2.py @@ -2,17 +2,8 @@ import unittest import random -import time -import math -import sys -import array import urllib -import tarfile import hashlib -import os -import getopt -import operator -import functools import numpy as np import cv2 import cv2.cv as cv From 56f17e4921a379317a0602d92d7ca3677cabe9d6 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 17 Sep 2015 18:17:06 +0300 Subject: [PATCH 2/3] test2.py: fail if a downloaded image can't be decoded --- modules/python/test/test2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/python/test/test2.py b/modules/python/test/test2.py index f9b46234b2..4cd67e7f12 100644 --- a/modules/python/test/test2.py +++ b/modules/python/test/test2.py @@ -13,7 +13,9 @@ class NewOpenCVTests(unittest.TestCase): def get_sample(self, filename, iscolor = cv.CV_LOAD_IMAGE_COLOR): if not filename in self.image_cache: filedata = urllib.urlopen("https://raw.github.com/Itseez/opencv/2.4/" + filename).read() - self.image_cache[filename] = cv2.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor) + image = cv2.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor) + self.assertFalse(image is None) + self.image_cache[filename] = image return self.image_cache[filename] def setUp(self): From 08ad3b500b8d458a12dbe78909bd9956dfe3e479 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 17 Sep 2015 18:21:04 +0300 Subject: [PATCH 3/3] test2.py: switch from urllib to urllib2 urllib2 raises an exception if an HTTP request produces an error code, making the test fail earlier. --- modules/python/test/test2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/python/test/test2.py b/modules/python/test/test2.py index 4cd67e7f12..815993e8a1 100644 --- a/modules/python/test/test2.py +++ b/modules/python/test/test2.py @@ -2,7 +2,7 @@ import unittest import random -import urllib +import urllib2 import hashlib import numpy as np import cv2 @@ -12,7 +12,7 @@ class NewOpenCVTests(unittest.TestCase): def get_sample(self, filename, iscolor = cv.CV_LOAD_IMAGE_COLOR): if not filename in self.image_cache: - filedata = urllib.urlopen("https://raw.github.com/Itseez/opencv/2.4/" + filename).read() + filedata = urllib2.urlopen("https://raw.github.com/Itseez/opencv/2.4/" + filename).read() image = cv2.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor) self.assertFalse(image is None) self.image_cache[filename] = image