Skip to content

Commit

Permalink
Using common module for regression testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aashish24 committed May 13, 2016
1 parent 11fc132 commit d1906cb
Show file tree
Hide file tree
Showing 118 changed files with 569 additions and 2,057 deletions.
Empty file added Packages/testing/__init__.py
Empty file.
23 changes: 21 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,28 @@
import re
import sys
import logging
import vcs

defaultThreshold=10.0

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

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

def run(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
vcsinst.png(fname)
sys.exit(check_result_image(fname, baseline, threshold))

def run_wo_terminate(vcsinst, fname, baseline=sys.argv[1], threshold=defaultThreshold):
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 +72,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, threshold=defaultThreshold,
baseline=True, cleanup=True):
testImage = image_from_file(fname)
if testImage is None:
print "Testing image missing, test failed."
Expand Down
14 changes: 14 additions & 0 deletions Packages/testing/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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': 'testing',},
install_requires=['numpy','vcs', 'vtk'],
)
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])
27 changes: 3 additions & 24 deletions testing/vcs/test_vcs_1d_in_boxfill.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@

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))

b = x.createboxfill()

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


fnm = "test_1d_in_boxfill.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_in_boxfill.png", sys.argv[1])
33 changes: 3 additions & 30 deletions testing/vcs/test_vcs_1d_marker_not_shown_if_xaxis_flipped.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
import vcs
import numpy
import MV2
import cdms2
import sys
import os

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()
data = MV2.array([4,5,6,7,1,3,7,9,])+230.

p = cdms2.createAxis([2,5,100,200,500,800,850,1000])

data.setAxis(0,p)

data.id="jim"

gm=x.create1d()

gm.linewidth=0
gm.datawc_x1=1000
gm.datawc_x2=0

gm.markersize=30

x.plot(data,gm,bg=1)

fnm = "test_1d_marker_not_shown_if_xaxis_flipped.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_marker_not_shown_if_xaxis_flipped.png", sys.argv[1])
26 changes: 5 additions & 21 deletions testing/vcs/test_vcs_1d_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
src=sys.argv[1]
pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage
import testing.regression as regression

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
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,17 +26,5 @@

data=MV2.masked_where(MV2.logical_and(data>-4,data<-2),data)

#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_missing.png"
x.png(fnm)

print "fnm:",fnm
print "src:",src
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
sys.exit(ret)
x.plot(data, yx, bg=1)
regression.run(x, "test_vcs_1d_missing.png", src)
15 changes: 4 additions & 11 deletions testing/vcs/test_vcs_animate_boxfill.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import vcs
import cdms2
import os
import sys
import time
import vcs, numpy, cdms2, MV2, os, sys, time, testing.regression as regression

pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

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

gm=x.createboxfill()
x.plot(s,gm,bg=1)
x.animate.create()
Expand All @@ -26,8 +20,7 @@
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
ret += regression.check_result_image(p,os.path.join(pth,os.path.split(p)[1]))
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
Expand Down
23 changes: 8 additions & 15 deletions testing/vcs/test_vcs_animate_isofill.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import vcs
import cdms2
import os
import sys
import time

import vcs, numpy, cdms2, MV2, os, sys, time, testing.regression as regression

pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt",slice(0,12)) # read only 12 times steps to speed up things

x=vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")
f = cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s = f("clt",slice(0,12)) # read only 12 times steps to speed up things

x = regression.init()
gm=x.createisofill()
x.plot(s,gm,bg=1)
x.animate.create()
Expand All @@ -26,8 +19,8 @@
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
ret += regression.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),
regression.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
Expand Down
Loading

0 comments on commit d1906cb

Please sign in to comment.