From 7791839f22beb2688db13573badf196927cf5148 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 3 Sep 2017 12:01:25 +0000 Subject: [PATCH] python(test): tests filtering --- modules/python/test/test.py | 34 ++----------------- modules/python/test/test_calibration.py | 5 +++ modules/python/test/test_camshift.py | 6 +++- modules/python/test/test_dft.py | 6 +++- modules/python/test/test_digits.py | 6 +++- modules/python/test/test_facedetect.py | 6 +++- .../python/test/test_feature_homography.py | 6 +++- modules/python/test/test_fitline.py | 6 +++- modules/python/test/test_gaussian_mix.py | 6 +++- modules/python/test/test_goodfeatures.py | 6 +++- modules/python/test/test_grabcut.py | 6 +++- modules/python/test/test_houghcircles.py | 6 +++- modules/python/test/test_houghlines.py | 6 +++- modules/python/test/test_kmeans.py | 6 +++- modules/python/test/test_legacy.py | 4 +-- modules/python/test/test_letter_recog.py | 6 +++- modules/python/test/test_lk_homography.py | 4 +++ modules/python/test/test_lk_track.py | 6 +++- modules/python/test/test_misc.py | 3 +- modules/python/test/test_morphology.py | 5 ++- modules/python/test/test_mser.py | 3 ++ modules/python/test/test_peopledetect.py | 5 ++- modules/python/test/test_shape.py | 3 ++ modules/python/test/test_squares.py | 5 ++- modules/python/test/test_stitching.py | 3 ++ modules/python/test/test_texture_flow.py | 3 ++ modules/python/test/test_umat.py | 3 +- modules/python/test/test_watershed.py | 5 ++- modules/python/test/tests_common.py | 29 ++++++++++++++-- 29 files changed, 140 insertions(+), 58 deletions(-) diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 215786137f..7d9bba4fc2 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -1,21 +1,9 @@ #!/usr/bin/env python from __future__ import print_function -import unittest -import random -import time -import math -import sys -import array -import tarfile -import hashlib + import os -import getopt -import operator -import functools -import numpy as np -import cv2 -import argparse +import unittest # Python 3 moved urlopen to urllib.requests try: @@ -25,7 +13,6 @@ except ImportError: from tests_common import NewOpenCVTests -# Tests to run first; check the handful of basic operations that the later tests rely on basedir = os.path.abspath(os.path.dirname(__file__)) @@ -34,19 +21,4 @@ def load_tests(loader, tests, pattern): return tests if __name__ == '__main__': - parser = argparse.ArgumentParser(description='run OpenCV python tests') - parser.add_argument('--repo', help='use sample image files from local git repository (path to folder), ' - 'if not set, samples will be downloaded from github.com') - parser.add_argument('--data', help=' use data files from local folder (path to folder), ' - 'if not set, data files will be downloaded from docs.opencv.org') - args, other = parser.parse_known_args() - print("Testing OpenCV", cv2.__version__) - print("Local repo path:", args.repo) - NewOpenCVTests.repoPath = args.repo - try: - NewOpenCVTests.extraTestDataPath = os.environ['OPENCV_TEST_DATA_PATH'] - except KeyError: - print('Missing opencv extra repository. Some of tests may fail.') - random.seed(0) - unit_argv = [sys.argv[0]] + other - unittest.main(argv=unit_argv) + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_calibration.py b/modules/python/test/test_calibration.py index f946a5bb9d..396ec23106 100644 --- a/modules/python/test/test_calibration.py +++ b/modules/python/test/test_calibration.py @@ -66,3 +66,8 @@ class calibration_test(NewOpenCVTests): self.assertLess(abs(rms - 0.196334638034), eps) self.assertLess(cv2.norm(camera_matrix - cameraMatrixTest, cv2.NORM_L1), normCamEps) self.assertLess(cv2.norm(dist_coefs - distCoeffsTest, cv2.NORM_L1), normDistEps) + + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_camshift.py b/modules/python/test/test_camshift.py index 96ab58ae12..91d45b09bb 100644 --- a/modules/python/test/test_camshift.py +++ b/modules/python/test/test_camshift.py @@ -89,4 +89,8 @@ class camshift_test(NewOpenCVTests): def test_camshift(self): self.prepareRender() - self.runTracker() \ No newline at end of file + self.runTracker() + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_dft.py b/modules/python/test/test_dft.py index f796939970..a1284d3846 100644 --- a/modules/python/test/test_dft.py +++ b/modules/python/test/test_dft.py @@ -43,4 +43,8 @@ class dft_test(NewOpenCVTests): img_backTest = cv2.normalize(img_backTest, 0.0, 1.0, cv2.NORM_MINMAX) img_back = cv2.normalize(img_back, 0.0, 1.0, cv2.NORM_MINMAX) - self.assertLess(cv2.norm(img_back - img_backTest), eps) \ No newline at end of file + self.assertLess(cv2.norm(img_back - img_backTest), eps) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_digits.py b/modules/python/test/test_digits.py index 2643d05adf..1204526e1e 100644 --- a/modules/python/test/test_digits.py +++ b/modules/python/test/test_digits.py @@ -194,4 +194,8 @@ class digits_test(NewOpenCVTests): self.assertLess(cv2.norm(confusionMatrixes[1] - confusionSVM, cv2.NORM_L1), normEps) self.assertLess(errors[0] - 0.034, eps) - self.assertLess(errors[1] - 0.018, eps) \ No newline at end of file + self.assertLess(errors[1] - 0.018, eps) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_facedetect.py b/modules/python/test/test_facedetect.py index aa86a4ff58..c2e58b01eb 100644 --- a/modules/python/test/test_facedetect.py +++ b/modules/python/test/test_facedetect.py @@ -85,4 +85,8 @@ class facedetect_test(NewOpenCVTests): eyes_matches += 1 self.assertEqual(faces_matches, 2) - self.assertEqual(eyes_matches, 2) \ No newline at end of file + self.assertEqual(eyes_matches, 2) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_feature_homography.py b/modules/python/test/test_feature_homography.py index c8c5daed03..b9902ca34e 100644 --- a/modules/python/test/test_feature_homography.py +++ b/modules/python/test/test_feature_homography.py @@ -157,4 +157,8 @@ class PlaneTracker: keypoints, descrs = self.detector.detectAndCompute(frame, None) if descrs is None: # detectAndCompute returns descs=None if no keypoints found descrs = [] - return keypoints, descrs \ No newline at end of file + return keypoints, descrs + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_fitline.py b/modules/python/test/test_fitline.py index 7de9573385..b8045667a0 100644 --- a/modules/python/test/test_fitline.py +++ b/modules/python/test/test_fitline.py @@ -63,4 +63,8 @@ class fitline_test(NewOpenCVTests): refVec = (np.float32(p1) - p0) / cv2.norm(np.float32(p1) - p0) for i in range(len(lines)): - self.assertLessEqual(cv2.norm(refVec - lines[i][0:2], cv2.NORM_L2), eps) \ No newline at end of file + self.assertLessEqual(cv2.norm(refVec - lines[i][0:2], cv2.NORM_L2), eps) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_gaussian_mix.py b/modules/python/test/test_gaussian_mix.py index ac6ec43b07..7ee39b3cbe 100644 --- a/modules/python/test/test_gaussian_mix.py +++ b/modules/python/test/test_gaussian_mix.py @@ -57,4 +57,8 @@ class gaussian_mix_test(NewOpenCVTests): cv2.norm(covs[i] - ref_distrs[j][1], cv2.NORM_L2) / cv2.norm(ref_distrs[j][1], cv2.NORM_L2) < covEps): matches_count += 1 - self.assertEqual(matches_count, cluster_n) \ No newline at end of file + self.assertEqual(matches_count, cluster_n) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_goodfeatures.py b/modules/python/test/test_goodfeatures.py index 5356ebaf29..c874147194 100644 --- a/modules/python/test/test_goodfeatures.py +++ b/modules/python/test/test_goodfeatures.py @@ -33,4 +33,8 @@ class TestGoodFeaturesToTrack_test(NewOpenCVTests): self.assertTrue(len(r0) > len(r1)) # Increasing thresh should monly truncate result list for i in range(len(r1)): - self.assertTrue(cv2.norm(r1[i][0] - r0[i][0])==0) \ No newline at end of file + self.assertTrue(cv2.norm(r1[i][0] - r0[i][0])==0) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_grabcut.py b/modules/python/test/test_grabcut.py index 38211f7d89..908a70beaa 100644 --- a/modules/python/test/test_grabcut.py +++ b/modules/python/test/test_grabcut.py @@ -64,4 +64,8 @@ class grabcut_test(NewOpenCVTests): exp_mask2 = self.scaleMask(mask) cv2.imwrite(self.extraTestDataPath + '/cv/grabcut/exp_mask2py.png', exp_mask2) - self.assertEqual(self.verify(self.scaleMask(mask), exp_mask2), True) \ No newline at end of file + self.assertEqual(self.verify(self.scaleMask(mask), exp_mask2), True) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_houghcircles.py b/modules/python/test/test_houghcircles.py index 23900d4c19..794730b5e6 100644 --- a/modules/python/test/test_houghcircles.py +++ b/modules/python/test/test_houghcircles.py @@ -77,4 +77,8 @@ class houghcircles_test(NewOpenCVTests): matches_counter += 1 self.assertGreater(float(matches_counter) / len(testCircles), .5) - self.assertLess(float(len(circles) - matches_counter) / len(circles), .75) \ No newline at end of file + self.assertLess(float(len(circles) - matches_counter) / len(circles), .75) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_houghlines.py b/modules/python/test/test_houghlines.py index 9f056ce3e6..315c5980b9 100644 --- a/modules/python/test/test_houghlines.py +++ b/modules/python/test/test_houghlines.py @@ -62,4 +62,8 @@ class houghlines_test(NewOpenCVTests): if linesDiff(testLines[i], lines[j]) < eps: matches_counter += 1 - self.assertGreater(float(matches_counter) / len(testLines), .7) \ No newline at end of file + self.assertGreater(float(matches_counter) / len(testLines), .7) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_kmeans.py b/modules/python/test/test_kmeans.py index 512d535c6c..8c7d37b22a 100644 --- a/modules/python/test/test_kmeans.py +++ b/modules/python/test/test_kmeans.py @@ -67,4 +67,8 @@ class kmeans_test(NewOpenCVTests): for i in range(cluster_n): confidence = getMainLabelConfidence(labels[offset : (offset + clusterSizes[i])], cluster_n) offset += clusterSizes[i] - self.assertGreater(confidence, 0.9) \ No newline at end of file + self.assertGreater(confidence, 0.9) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_legacy.py b/modules/python/test/test_legacy.py index 6206a3d7a8..ff7cfa15ff 100644 --- a/modules/python/test/test_legacy.py +++ b/modules/python/test/test_legacy.py @@ -84,6 +84,6 @@ class Hackathon244Tests(NewOpenCVTests): self.check_close_pairs(mc, mc0, 5) self.assertLessEqual(abs(mr - mr0), 5) + if __name__ == '__main__': - import unittest - unittest.main() + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_letter_recog.py b/modules/python/test/test_letter_recog.py index 83657ecbb5..c34559c1e0 100644 --- a/modules/python/test/test_letter_recog.py +++ b/modules/python/test/test_letter_recog.py @@ -164,4 +164,8 @@ class letter_recog_test(NewOpenCVTests): test_rate = np.mean(classifier.predict(samples[train_n:]) == responses[train_n:].astype(int)) self.assertLess(train_rate - testErrors[Model][0], eps) - self.assertLess(test_rate - testErrors[Model][1], eps) \ No newline at end of file + self.assertLess(test_rate - testErrors[Model][1], eps) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_lk_homography.py b/modules/python/test/test_lk_homography.py index 4dbcb798d5..30d8fbe82b 100644 --- a/modules/python/test/test_lk_homography.py +++ b/modules/python/test/test_lk_homography.py @@ -94,3 +94,7 @@ class lk_homography_test(NewOpenCVTests): self.p0 = cv2.goodFeaturesToTrack(frame_gray, **feature_params) self.assertEqual(isForegroundHomographyFound, True) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_lk_track.py b/modules/python/test/test_lk_track.py index 655a92f3a8..f66faee289 100644 --- a/modules/python/test/test_lk_track.py +++ b/modules/python/test/test_lk_track.py @@ -108,4 +108,8 @@ class lk_track_test(NewOpenCVTests): self.prev_gray = frame_gray if self.frame_idx > 300: - break \ No newline at end of file + break + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index 3eba9746f2..08535d4a30 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -19,5 +19,4 @@ class Bindings(NewOpenCVTests): boost.isClassifier() # from ml::StatModel if __name__ == '__main__': - import unittest - unittest.main() + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_morphology.py b/modules/python/test/test_morphology.py index 309c80cfd2..bfffc88b02 100644 --- a/modules/python/test/test_morphology.py +++ b/modules/python/test/test_morphology.py @@ -48,4 +48,7 @@ class morphology_test(NewOpenCVTests): for mode in modes: res = update(mode) - self.assertEqual(self.hashimg(res), referenceHashes[mode]) \ No newline at end of file + self.assertEqual(self.hashimg(res), referenceHashes[mode]) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_mser.py b/modules/python/test/test_mser.py index a95f7ee0dd..bf878e5f4f 100644 --- a/modules/python/test/test_mser.py +++ b/modules/python/test/test_mser.py @@ -67,3 +67,6 @@ class mser_test(NewOpenCVTests): self.assertEqual(nmsers, len(boxes)) self.assertLessEqual(minRegs, nmsers) self.assertGreaterEqual(maxRegs, nmsers) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_peopledetect.py b/modules/python/test/test_peopledetect.py index cd70dc2f7d..08d39abc71 100644 --- a/modules/python/test/test_peopledetect.py +++ b/modules/python/test/test_peopledetect.py @@ -59,4 +59,7 @@ class peopledetect_test(NewOpenCVTests): if intersectionRate(found_rect, testPeople[j][0]) > eps or intersectionRate(found_rect, testPeople[j][1]) > eps: matches += 1 - self.assertGreater(matches, 0) \ No newline at end of file + self.assertGreater(matches, 0) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_shape.py b/modules/python/test/test_shape.py index 218b8e0209..e396b6276c 100644 --- a/modules/python/test/test_shape.py +++ b/modules/python/test/test_shape.py @@ -21,3 +21,6 @@ class shape_test(NewOpenCVTests): self.assertAlmostEqual(d1, 26.4196891785, 3, "HausdorffDistanceExtractor") self.assertAlmostEqual(d2, 0.25804194808, 3, "ShapeContextDistanceExtractor") + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_squares.py b/modules/python/test/test_squares.py index a6921efcc6..c70cf87493 100644 --- a/modules/python/test/test_squares.py +++ b/modules/python/test/test_squares.py @@ -93,4 +93,7 @@ class squares_test(NewOpenCVTests): matches_counter += 1 self.assertGreater(matches_counter / len(testSquares), 0.9) - self.assertLess( (len(squares) - matches_counter) / len(squares), 0.2) \ No newline at end of file + self.assertLess( (len(squares) - matches_counter) / len(squares), 0.2) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_stitching.py b/modules/python/test/test_stitching.py index d8faaec261..6d6c52d378 100644 --- a/modules/python/test/test_stitching.py +++ b/modules/python/test/test_stitching.py @@ -18,3 +18,6 @@ class stitching_test(NewOpenCVTests): self.assertAlmostEqual(pano.shape[0], 685, delta=100, msg="rows: %r" % list(pano.shape)) self.assertAlmostEqual(pano.shape[1], 1025, delta=100, msg="cols: %r" % list(pano.shape)) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_texture_flow.py b/modules/python/test/test_texture_flow.py index b0f55207c5..c4bbce23fc 100644 --- a/modules/python/test/test_texture_flow.py +++ b/modules/python/test/test_texture_flow.py @@ -42,3 +42,6 @@ class texture_flow_test(NewOpenCVTests): for i in range(len(textureVectors)): self.assertTrue(cv2.norm(textureVectors[i], cv2.NORM_L2) < eps or abs(cv2.norm(textureVectors[i], cv2.NORM_L2) - d) < eps) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_umat.py b/modules/python/test/test_umat.py index 50dc53fdc4..f9f5645243 100644 --- a/modules/python/test/test_umat.py +++ b/modules/python/test/test_umat.py @@ -83,5 +83,4 @@ class UMat(NewOpenCVTests): # self.assertTrue(np.allclose(data, data_umat)) if __name__ == '__main__': - import unittest - unittest.main() + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/test_watershed.py b/modules/python/test/test_watershed.py index 0a1d222f41..9e424e0d8b 100644 --- a/modules/python/test/test_watershed.py +++ b/modules/python/test/test_watershed.py @@ -30,4 +30,7 @@ class watershed_test(NewOpenCVTests): refSegments = segments.copy() cv2.imwrite(self.extraTestDataPath + '/cv/watershed/wshed_segments.png', refSegments) - self.assertLess(cv2.norm(segments - refSegments, cv2.NORM_L1) / 255.0, 50) \ No newline at end of file + self.assertLess(cv2.norm(segments - refSegments, cv2.NORM_L1) / 255.0, 50) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/python/test/tests_common.py b/modules/python/test/tests_common.py index 7a7e3ba841..33568382ea 100644 --- a/modules/python/test/tests_common.py +++ b/modules/python/test/tests_common.py @@ -2,10 +2,13 @@ from __future__ import print_function -import unittest -import sys -import hashlib import os +import sys +import unittest +import hashlib +import random +import argparse + import numpy as np import cv2 @@ -62,6 +65,26 @@ class NewOpenCVTests(unittest.TestCase): if not a > b: self.fail('%s not greater than %s' % (repr(a), repr(b))) + @staticmethod + def bootstrap(): + parser = argparse.ArgumentParser(description='run OpenCV python tests') + parser.add_argument('--repo', help='use sample image files from local git repository (path to folder), ' + 'if not set, samples will be downloaded from github.com') + parser.add_argument('--data', help=' use data files from local folder (path to folder), ' + 'if not set, data files will be downloaded from docs.opencv.org') + args, other = parser.parse_known_args() + print("Testing OpenCV", cv2.__version__) + print("Local repo path:", args.repo) + NewOpenCVTests.repoPath = args.repo + try: + NewOpenCVTests.extraTestDataPath = os.environ['OPENCV_TEST_DATA_PATH'] + except KeyError: + print('Missing opencv extra repository. Some of tests may fail.') + random.seed(0) + unit_argv = [sys.argv[0]] + other + unittest.main(argv=unit_argv) + + def intersectionRate(s1, s2): x1, y1, x2, y2 = s1