forked from sightmachine/SimpleCV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_optional.py
More file actions
148 lines (127 loc) · 3.73 KB
/
Copy pathtest_optional.py
File metadata and controls
148 lines (127 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# /usr/bin/python
# To run this test you need python nose tools installed
# Run test just use:
# nosetest test_optional.py
#
import os, sys, pickle
from SimpleCV import *
from nose.tools import with_setup, nottest
SHOW_WARNING_TESTS = False # show that warnings are working - tests will pass but warnings are generated.
#colors
black = Color.BLACK
white = Color.WHITE
red = Color.RED
green = Color.GREEN
blue = Color.BLUE
###############
# TODO -
# Examples of how to do profiling
# Examples of how to do a single test -
# UPDATE THE VISUAL TESTS WITH EXAMPLES.
# Fix exif data
# Turn off test warnings using decorators.
# Write a use the tests doc.
#images
barcode = "../sampleimages/barcode.png"
testimage = "../sampleimages/9dots4lines.png"
testimage2 = "../sampleimages/aerospace.jpg"
whiteimage = "../sampleimages/white.png"
blackimage = "../sampleimages/black.png"
testimageclr = "../sampleimages/statue_liberty.jpg"
testbarcode = "../sampleimages/barcode.png"
testoutput = "../sampleimages/9d4l.jpg"
tmpimg = "../sampleimages/tmpimg.jpg"
greyscaleimage = "../sampleimages/greyscale.jpg"
logo = "../sampleimages/simplecv.png"
logo_inverted = "../sampleimages/simplecv_inverted.png"
ocrimage = "../sampleimages/ocr-test.png"
circles = "../sampleimages/circles.png"
webp = "../sampleimages/simplecv.webp"
#alpha masking images
topImg = "../sampleimages/RatTop.png"
bottomImg = "../sampleimages/RatBottom.png"
maskImg = "../sampleimages/RatMask.png"
alphaMaskImg = "../sampleimages/RatAlphaMask.png"
alphaSrcImg = "../sampleimages/GreenMaskSource.png"
#standards path
standard_path = "./standard/"
#These function names are required by nose test, please leave them as is
def setup_context():
img = Image(testimage)
def destroy_context():
img = ""
@with_setup(setup_context, destroy_context)
def test_detection_barcode():
try:
import zbar
except:
return None
img1 = Image(testimage)
img2 = Image(testbarcode)
if( SHOW_WARNING_TESTS ):
nocode = img1.findBarcode()
if nocode: #we should find no barcode in our test image
assert False
code = img2.findBarcode()
code.draw()
if code.points:
pass
result = [img1,img2]
name_stem = "test_detection_barcode"
perform_diff(result,name_stem)
else:
pass
def test_detection_ocr():
img = Image(ocrimage)
foundtext = img.readText()
print foundtext
if(len(foundtext) <= 1):
assert False
else:
pass
def test_image_webp_load():
#only run if webm suppport exist on system
try:
import webm
except:
if( SHOW_WARNING_TESTS ):
logger.warning("Couldn't run the webp test as optional webm library required")
pass
else:
img = Image(webp)
if len(img.toString()) <= 1:
assert False
else:
pass
def test_image_webp_save():
#only run if webm suppport exist on system
try:
import webm
except:
if( SHOW_WARNING_TESTS ):
logger.warning("Couldn't run the webp test as optional webm library required")
pass
else:
img = Image('simplecv')
tf = tempfile.NamedTemporaryFile(suffix=".webp")
if img.save(tf.name):
pass
else:
assert False
def test_screenshot():
try:
import pyscreenshot
except:
if( SHOW_WARNING_TESTS ):
logger.warning("Couldn't run the pyscreenshot test. Install pyscreenshot library")
pass
sc = ScreenCamera()
res = sc.getResolution()
img = sc.getImage()
crop = (res[0]/4,res[1]/4,res[0]/2,res[1]/2)
sc.setROI(crop)
cropImg = sc.getImage()
if img and cropImg :
assert True
else:
assert False