Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Packages/testing/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions Packages/testing/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def test_values_setting(gm,attributes,good_values=[],bad_values=[]):
if isinstance(attributes,str):
attributes=[attributes,]
for att in attributes:
for val in good_values:
setattr(gm,att,val)
for val in bad_values:
try:
setattr(gm,att,val)
success = True
except:
success = False
else:
if success:
if hasattr(gm,"g_name"):
nm = gm.g_name
elif hasattr(gm,"s_name"):
nm = gm.s_name
else:
nm=gm.p_name
raise Exception,"Should not be able to set %s attribute '%s' to %s" % (nm,att,repr(val))
sys.exit(1)
28 changes: 26 additions & 2 deletions testing/checkimage.py → Packages/testing/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,32 @@
import re
import sys
import logging
import vcs

defaultThreshold=10.0

def init(*args, **kwargs):
testingDir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(testingDir)

vcsinst = vcs.init(*args, **kwargs)
vcsinst.setantialiasing(0)
vcsinst.drawlogooff()

if ('bg' in kwargs and kwargs['bg']) or ('bg' not in kwargs):
vcsinst.setbgoutputdimensions(1200, 1091, units="pixels")
return vcsinst

def run(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
"""Export plot to a png and exit after comparsion."""
vcsinst.png(fname)
sys.exit(check_result_image(fname, baseline, threshold))

def run_wo_terminate(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
"""Export plot to a png and return comparison with baseline."""
vcsinst.png(fname)
return check_result_image(fname, baseline, threshold)

def image_compare(testImage, baselineImage):
imageDiff = vtk.vtkImageDifference()
imageDiff.SetInputData(testImage)
Expand Down Expand Up @@ -53,8 +76,8 @@ def find_alternates(fname):
results.append(os.path.join(dirname, i))
return results

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


def main():
if len(sys.argv) != 4:
print "Error:"
Expand Down
13 changes: 13 additions & 0 deletions Packages/testing/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os, sys
from distutils.core import setup
import cdat_info

sys.path.append(os.environ.get('BUILD_DIR',"build"))

setup(name="testing",
version=cdat_info.Version,
description="Testing infrastructure for cdat",
url="http://uvcdat.llnl.gov",
packages=['testing'],
package_dir = {'testing': '', }
)
1 change: 1 addition & 0 deletions Packages/vcs/vcs/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
# Python < 3 DeprecationWarning ignored by default
warnings.simplefilter('default')


class SIGNAL(object):

def __init__(self, name=None):
Expand Down
11 changes: 6 additions & 5 deletions installation/control.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is used to control the behavior of install.py.

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

# List of packages to be built
packages = [
packages = [
"Packages/pydebug",
"Packages/cdtime",
"Packages/demo",
"Packages/help",
"Packages/regrid2",
"Packages/cdms2",
"Packages/esg",
"Packages/cdms2",
"Packages/esg",
"Packages/ncml",
"Packages/DV3D",
"Packages/vcs",
"Packages/vcsaddons",
"Packages/cdutil",
"Packages/unidata",
"Packages/xmgrace",
"Packages/genutil",
"Packages/genutil",
"Packages/Thermo",
"Packages/WK",
"Packages/gui_support",
"Packages/distarray",
"Packages/testing",
]
6 changes: 3 additions & 3 deletions testing/dv3d/TestManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TestingDir=os.path.dirname(__file__)
pth = os.path.join(TestingDir,"..")
sys.path.append(pth)
import checkimage
import testing.regression as regression

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

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

if interactive:
print "Type <Enter> to continue and update ref image ( type 'n' to skip update )."
Expand Down
6 changes: 3 additions & 3 deletions testing/metrics/diags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import cdms2, numpy
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import testing.regression as regression
import argparse, pdb

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

#initialize to successful graphics check
Expand Down
17 changes: 3 additions & 14 deletions testing/regrid/testEsmfRegridPeriodictyRegional.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import vcs,cdms2
import os,sys
import EzTemplate
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import os, sys, vcs, cdms2, EzTemplate, testing.regression as regression

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

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

x=regression.init()
t=x.createtemplate()
t.blank()
t.data.priority=1
Expand All @@ -60,7 +51,5 @@
x.plot(s_regrid2,M.get(),gm,bg=1)
x.plot(s_esmf_lin,M.get(),gm,bg=1)
x.plot(s_esmf_con,M.get(),gm,bg=1)
x.png("esmf_issue_1125")

ret = checkimage.check_result_image("esmf_issue_1125.png",png,checkimage.defaultThreshold)
sys.exit(ret)
ret = regression.run(x, "esmf_issue_1125.png", png)
20 changes: 3 additions & 17 deletions testing/vcs/test_fewer_colors_than_levels.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import vcs,cdms2,sys,os

baselineImage = sys.argv[1]

pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import os, sys, cdms2, vcs, testing.regression as regression

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

canvas = vcs.init()
canvas.setantialiasing(0)
canvas.setbgoutputdimensions(1200, 1091, units="pixels")
canvas.drawlogooff()
canvas = regression.init()

boxfill = canvas.createboxfill()

Expand All @@ -21,9 +12,4 @@

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

testImage = os.path.abspath("test_fewer_colors_than_levels.png")
canvas.png(testImage)

ret = checkimage.check_result_image(testImage, baselineImage, checkimage.defaultThreshold)

sys.exit(ret)
regression.run(canvas, "test_fewer_colors_than_levels.png")
21 changes: 7 additions & 14 deletions testing/vcs/test_vcs_1D_datawc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()

x.setbgoutputdimensions(1200,1091,units="pixels")
import testing.regression as regression

x = regression.init()
yx =x.createyxvsx()

data = """-11.14902417 -9.17390922 -7.29515002
data = """-11.14902417 -9.17390922 -7.29515002
-7.51774549 -8.63608171
-10.4827395 -9.93859485 -7.3394366 -5.39241468 -5.74825567
-6.74967902 -7.09622319 -5.93836983 -4.04592997 -2.65591499
Expand All @@ -30,14 +28,9 @@
data = MV2.array(data)
yx.datawc_x1 = 0
yx.datawc_x2 = 80
yx.datawc_y1 =-12
yx.datawc_y2 = 12
yx.datawc_y1 =-12
yx.datawc_y2 = 12


x.plot(data,yx,bg=1)
fnm = "test_vcs_1D_datawc.png"
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)
regression.run(x, "test_vcs_1D_datawc.png", src)
29 changes: 5 additions & 24 deletions testing/vcs/test_vcs_1D_datawc_missing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@

import vcs,numpy,cdms2,MV2,os,sys
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import vcs, numpy, cdms2, MV2, os, sys, testing.regression as regression

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

yx =x.createyxvsx()
x = regression.init()
yx = x.createyxvsx()

data = """
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
0.059503571833625334
0.059503571833625334 0.05664014775641405 0.05193557222118004
0.04777129850801233 0.0407139313814465 0.029382624830271705
Expand Down Expand Up @@ -42,16 +34,5 @@
""".split()
data = numpy.array(data,dtype=numpy.float)
data = MV2.masked_less(data,-900)
#yx.datawc_x1 = 0
#yx.datawc_x2 = 80
##yx.datawc_y1 =-12
#yx.datawc_y2 = 12


x.plot(data,yx,bg=1)
fnm = "test_vcs_1D_datawc_missing.png"
x.png(fnm)
print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)
regression.run(x, "test_vcs_1D_datawc_missing.png")
30 changes: 4 additions & 26 deletions testing/vcs/test_vcs_1D_with_manyDs.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@

import vcs,numpy,os,sys
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
import vcs, numpy, cdms2, MV2, os, sys, testing.regression as regression

x = regression.init()
d = numpy.sin(numpy.arange(100))
d=numpy.reshape(d,(10,10))


d = numpy.reshape(d,(10,10))
one = x.create1d()

x.plot(d,one,bg=1)


fnm = "test_1D_with_manyDs.png"
x.png(fnm)

print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)



regression.run(x, "test_1D_with_manyDs.png", sys.argv[1])
Loading