Add new tests on python
This commit is contained in:
55
modules/python/test/test.py
Normal file → Executable file
55
modules/python/test/test.py
Normal file → Executable file
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import random
|
||||
import time
|
||||
@@ -17,51 +19,24 @@ import numpy as np
|
||||
import cv2
|
||||
import argparse
|
||||
|
||||
# local test modules
|
||||
from test_digits import digits_test
|
||||
from test_calibration import calibration_test
|
||||
from test_squares import squares_test
|
||||
from test_texture_flow import texture_flow_test
|
||||
from test_fitline import fitline_test
|
||||
from test_houghcircles import houghcircles_test
|
||||
from test_houghlines import houghlines_test
|
||||
from test_gaussian_mix import gaussian_mix_test
|
||||
from test_facedetect import facedetect_test
|
||||
|
||||
# Python 3 moved urlopen to urllib.requests
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib import urlopen
|
||||
|
||||
class NewOpenCVTests(unittest.TestCase):
|
||||
|
||||
# path to local repository folder containing 'samples' folder
|
||||
repoPath = None
|
||||
# github repository url
|
||||
repoUrl = 'https://raw.github.com/Itseez/opencv/master'
|
||||
|
||||
def get_sample(self, filename, iscolor = cv2.IMREAD_COLOR):
|
||||
if not filename in self.image_cache:
|
||||
filedata = None
|
||||
if NewOpenCVTests.repoPath is not None:
|
||||
candidate = NewOpenCVTests.repoPath + '/' + filename
|
||||
if os.path.isfile(candidate):
|
||||
with open(candidate, 'rb') as f:
|
||||
filedata = f.read()
|
||||
if filedata is None:
|
||||
filedata = urlopen(NewOpenCVTests.repoUrl + '/' + filename).read()
|
||||
self.image_cache[filename] = cv2.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor)
|
||||
return self.image_cache[filename]
|
||||
|
||||
def setUp(self):
|
||||
self.image_cache = {}
|
||||
|
||||
def hashimg(self, im):
|
||||
""" Compute a hash for an image, useful for image comparisons """
|
||||
return hashlib.md5(im.tostring()).digest()
|
||||
|
||||
if sys.version_info[:2] == (2, 6):
|
||||
def assertLess(self, a, b, msg=None):
|
||||
if not a < b:
|
||||
self.fail('%s not less than %s' % (repr(a), repr(b)))
|
||||
|
||||
def assertLessEqual(self, a, b, msg=None):
|
||||
if not a <= b:
|
||||
self.fail('%s not less than or equal to %s' % (repr(a), repr(b)))
|
||||
|
||||
def assertGreater(self, a, b, msg=None):
|
||||
if not a > b:
|
||||
self.fail('%s not greater than %s' % (repr(a), repr(b)))
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
# Tests to run first; check the handful of basic operations that the later tests rely on
|
||||
|
||||
@@ -167,4 +142,4 @@ if __name__ == '__main__':
|
||||
NewOpenCVTests.repoPath = args.repo
|
||||
random.seed(0)
|
||||
unit_argv = [sys.argv[0]] + other;
|
||||
unittest.main(argv=unit_argv)
|
||||
unittest.main(argv=unit_argv)
|
Reference in New Issue
Block a user