Skip to content

Commit 3d52e6e

Browse files
committed
Merge pull request #1968 from UV-CDAT/improve_testing_somemore
Improve testing by moving common code to testing module
2 parents 1a83c8d + 9c121a2 commit 3d52e6e

File tree

134 files changed

+648
-2218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+648
-2218
lines changed

Packages/testing/__init__.py

Whitespace-only changes.

Packages/testing/common.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def test_values_setting(gm,attributes,good_values=[],bad_values=[]):
2+
if isinstance(attributes,str):
3+
attributes=[attributes,]
4+
for att in attributes:
5+
for val in good_values:
6+
setattr(gm,att,val)
7+
for val in bad_values:
8+
try:
9+
setattr(gm,att,val)
10+
success = True
11+
except:
12+
success = False
13+
else:
14+
if success:
15+
if hasattr(gm,"g_name"):
16+
nm = gm.g_name
17+
elif hasattr(gm,"s_name"):
18+
nm = gm.s_name
19+
else:
20+
nm=gm.p_name
21+
raise Exception,"Should not be able to set %s attribute '%s' to %s" % (nm,att,repr(val))
22+
sys.exit(1)
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,32 @@
1212
import re
1313
import sys
1414
import logging
15+
import vcs
1516

1617
defaultThreshold=10.0
1718

19+
def init(*args, **kwargs):
20+
testingDir = os.path.join(os.path.dirname(__file__), "..")
21+
sys.path.append(testingDir)
22+
23+
vcsinst = vcs.init(*args, **kwargs)
24+
vcsinst.setantialiasing(0)
25+
vcsinst.drawlogooff()
26+
27+
if ('bg' in kwargs and kwargs['bg']) or ('bg' not in kwargs):
28+
vcsinst.setbgoutputdimensions(1200, 1091, units="pixels")
29+
return vcsinst
30+
31+
def run(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
32+
"""Export plot to a png and exit after comparsion."""
33+
vcsinst.png(fname)
34+
sys.exit(check_result_image(fname, baseline, threshold))
35+
36+
def run_wo_terminate(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
37+
"""Export plot to a png and return comparison with baseline."""
38+
vcsinst.png(fname)
39+
return check_result_image(fname, baseline, threshold)
40+
1841
def image_compare(testImage, baselineImage):
1942
imageDiff = vtk.vtkImageDifference()
2043
imageDiff.SetInputData(testImage)
@@ -53,8 +76,8 @@ def find_alternates(fname):
5376
results.append(os.path.join(dirname, i))
5477
return results
5578

56-
def check_result_image(fname, baselinefname, threshold = defaultThreshold,
57-
baseline = True, cleanup=True):
79+
def check_result_image(fname, baselinefname=sys.argv[1], threshold=defaultThreshold,
80+
baseline=True, cleanup=True):
5881
testImage = image_from_file(fname)
5982
if testImage is None:
6083
print "Testing image missing, test failed."
@@ -119,6 +142,7 @@ def printDart(name, type, value, suff=""):
119142
printDart("ValidImage", "image/png", os.path.abspath(bestFilename), "File")
120143
return -1
121144

145+
122146
def main():
123147
if len(sys.argv) != 4:
124148
print "Error:"

Packages/testing/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os, sys
2+
from distutils.core import setup
3+
import cdat_info
4+
5+
sys.path.append(os.environ.get('BUILD_DIR',"build"))
6+
7+
setup(name="testing",
8+
version=cdat_info.Version,
9+
description="Testing infrastructure for cdat",
10+
url="http://uvcdat.llnl.gov",
11+
packages=['testing'],
12+
package_dir = {'testing': '', }
13+
)

Packages/vcs/vcs/Canvas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
# Python < 3 DeprecationWarning ignored by default
7777
warnings.simplefilter('default')
7878

79+
7980
class SIGNAL(object):
8081

8182
def __init__(self, name=None):

installation/control.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is used to control the behavior of install.py.
22

33
# The search path is used if the X11 directories aren't configured.
4-
x11search = ['/usr/X11R6', '/usr/X11R6.5.1',
4+
x11search = ['/usr/X11R6', '/usr/X11R6.5.1',
55
'/usr/X11R6.4','/usr','/usr/openwin','/opt']
66
# Here is where they are on OSF1 and perhaps similar systems
77
x11OSF1lib = ['/usr/lib/X11', '/usr/lib']
@@ -48,24 +48,25 @@
4848
make_code = 'make'
4949

5050
# List of packages to be built
51-
packages = [
51+
packages = [
5252
"Packages/pydebug",
5353
"Packages/cdtime",
5454
"Packages/demo",
5555
"Packages/help",
5656
"Packages/regrid2",
57-
"Packages/cdms2",
58-
"Packages/esg",
57+
"Packages/cdms2",
58+
"Packages/esg",
5959
"Packages/ncml",
6060
"Packages/DV3D",
6161
"Packages/vcs",
6262
"Packages/vcsaddons",
6363
"Packages/cdutil",
6464
"Packages/unidata",
6565
"Packages/xmgrace",
66-
"Packages/genutil",
66+
"Packages/genutil",
6767
"Packages/Thermo",
6868
"Packages/WK",
6969
"Packages/gui_support",
7070
"Packages/distarray",
71+
"Packages/testing",
7172
]

testing/dv3d/TestManager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
TestingDir=os.path.dirname(__file__)
1111
pth = os.path.join(TestingDir,"..")
1212
sys.path.append(pth)
13-
import checkimage
13+
import testing.regression as regression
1414

1515
DefaultSampleFile = "geos5-sample.nc"
1616
DefaultSampleVar = "uwnd"
@@ -128,8 +128,8 @@ def test( self, interactive=False ):
128128
test_image = '.'.join( [ self.name, 'test', 'png' ] )
129129
self.canvas.png( test_image, width = 900, height = 600 )
130130

131-
ret = checkimage.check_result_image( test_image, self.image_name,\
132-
checkimage.defaultThreshold+3. )
131+
ret = regression.check_result_image( test_image, self.image_name,\
132+
regression.defaultThreshold+3. )
133133

134134
if interactive:
135135
print "Type <Enter> to continue and update ref image ( type 'n' to skip update )."

testing/metrics/diags_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import cdms2, numpy
1313
pth = os.path.join(os.path.dirname(__file__),"..")
1414
sys.path.append(pth)
15-
import checkimage
15+
import testing.regression as regression
1616
import argparse, pdb
1717

1818
class DiagTest(object):
@@ -95,7 +95,7 @@ def closeness( self, varname, filename, rtol, atol ):
9595
def execute(self, test_str, imagefilename, imagethreshold, ncfiles, rtol, atol):
9696
print test_str
9797
if imagethreshold is None: # user didn't specify a value
98-
imagethreshold = checkimage.defaultThreshold
98+
imagethreshold = regression.defaultThreshold
9999
# Silence annoying messages about how to set the NetCDF file type. Anything will do.
100100
cdms2.setNetcdfShuffleFlag(0)
101101
cdms2.setNetcdfDeflateFlag(0)
@@ -118,7 +118,7 @@ def execute(self, test_str, imagefilename, imagethreshold, ncfiles, rtol, atol):
118118
imagebaselinefname = os.path.join( self.baselinepath, imagefilename )
119119
#pdb.set_trace()
120120
print "OK THRESHOLD IS:",imagethreshold
121-
graphics_result = checkimage.check_result_image( imagefname, imagebaselinefname, imagethreshold )
121+
graphics_result = regression.check_result_image( imagefname, imagebaselinefname, imagethreshold )
122122
print "Graphics file", imagefname, "match difference:", graphics_result
123123

124124
#initialize to successful graphics check

testing/regrid/testEsmfRegridPeriodictyRegional.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import vcs,cdms2
2-
import os,sys
3-
import EzTemplate
4-
pth = os.path.join(os.path.dirname(__file__),"..")
5-
sys.path.append(pth)
6-
import checkimage
1+
import os, sys, vcs, cdms2, EzTemplate, testing.regression as regression
72

83
data = sys.argv[1]
94
png = sys.argv[2]
@@ -38,11 +33,7 @@
3833
s_esmf_con = s.regrid(grid_dest,regridTool="esmf",regridMethod="conservative")
3934
s_esmf_lin.id = "ESMF Conservative"
4035

41-
x=vcs.init()
42-
x.setantialiasing(0)
43-
x.drawlogooff()
44-
x.setbgoutputdimensions(1200,1091,units="pixels")
45-
36+
x=regression.init()
4637
t=x.createtemplate()
4738
t.blank()
4839
t.data.priority=1
@@ -60,7 +51,5 @@
6051
x.plot(s_regrid2,M.get(),gm,bg=1)
6152
x.plot(s_esmf_lin,M.get(),gm,bg=1)
6253
x.plot(s_esmf_con,M.get(),gm,bg=1)
63-
x.png("esmf_issue_1125")
6454

65-
ret = checkimage.check_result_image("esmf_issue_1125.png",png,checkimage.defaultThreshold)
66-
sys.exit(ret)
55+
ret = regression.run(x, "esmf_issue_1125.png", png)
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import vcs,cdms2,sys,os
2-
3-
baselineImage = sys.argv[1]
4-
5-
pth = os.path.join(os.path.dirname(__file__),"..")
6-
sys.path.append(pth)
7-
import checkimage
1+
import os, sys, cdms2, vcs, testing.regression as regression
82

93
dataset = cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
104
data = dataset("clt")
115

12-
canvas = vcs.init()
13-
canvas.setantialiasing(0)
14-
canvas.setbgoutputdimensions(1200, 1091, units="pixels")
15-
canvas.drawlogooff()
6+
canvas = regression.init()
167

178
boxfill = canvas.createboxfill()
189

@@ -21,9 +12,4 @@
2112

2213
canvas.plot(data, boxfill, bg=1)
2314

24-
testImage = os.path.abspath("test_fewer_colors_than_levels.png")
25-
canvas.png(testImage)
26-
27-
ret = checkimage.check_result_image(testImage, baselineImage, checkimage.defaultThreshold)
28-
29-
sys.exit(ret)
15+
regression.run(canvas, "test_fewer_colors_than_levels.png")

0 commit comments

Comments
 (0)