Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests! #12

Merged
merged 35 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d83ec96
Ported cdtest01 to unittest, removed old test infrastructure
Oct 3, 2016
1d711b9
ported cdtest02
Oct 3, 2016
e8595b9
Added convenience methods to basetest, converted cdtest03
Oct 4, 2016
5ce3eff
Refactored run function to save the import of unittest on each script
Oct 4, 2016
0055b26
Converted cdtest04 to unittest
Oct 4, 2016
4e0e429
Moved data files to subdirectory, using new getDataFile function on b…
Oct 4, 2016
150989c
Converted CDTest05 to unittest; does not pass
Oct 4, 2016
f9ba6ca
Moved CDScan test over to unittest
Oct 4, 2016
f3bfaa1
Changing tactic; now just porting everything over in one big test (fo…
Oct 4, 2016
a81058e
Converted cdtest08 to unittest; two failing checks at end of test
Oct 5, 2016
7933743
Converted cdtest10 to unittest
Oct 5, 2016
992deb9
Converted cdtest11 to unittest
Oct 5, 2016
0b51c6e
Converted cdtest12 to unittest
Oct 5, 2016
6c6c14f
Converted cdtest13 to unittest
Oct 5, 2016
0c89ac5
Converted cdtest14 to unittest
Oct 5, 2016
b407662
Converted cdtest15
Oct 5, 2016
9bfeb08
Converted cdtest17
Oct 5, 2016
4b94022
Converted cdtest18, it currently fails
Oct 5, 2016
3309e1c
Converted cdtest19; might be wrong, we'll figure it out
Oct 5, 2016
2961ff2
Converted cdtest20
Oct 5, 2016
19a9a77
Renamed tests appropriately
Oct 5, 2016
71605e4
Converted test_all_formats
Oct 5, 2016
f42f655
Converted createcopy_lose_dtype
Oct 5, 2016
3b2749b
Converted del attributes
Oct 5, 2016
80ead47
Made single regresison test file for all of the misc regression tests
Oct 5, 2016
7af3926
Added more regression tests
Oct 5, 2016
db4b57b
Converted compression test
Oct 5, 2016
ea14acf
Completed test migration to unittest
Oct 5, 2016
df8e1ea
Test suite is runnable
Oct 5, 2016
b54ccb9
Refactored first half of mv2
Oct 5, 2016
fffac90
Continued refactor of test_mv2
Oct 6, 2016
76c5bc7
Finished refactor of MV2
Oct 6, 2016
103fd86
more test now passing
doutriaux1 Oct 12, 2016
b351d51
run_test exit with non 0 if error happened
doutriaux1 Oct 26, 2016
b39a098
test can be passed as full path to it
doutriaux1 Oct 26, 2016
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
41 changes: 41 additions & 0 deletions Test/basetest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest
import shutil
import numpy
import tempfile
import cdms2
import os


class CDMSBaseTest(unittest.TestCase):
def getFile(self, path, mode="r"):
f = cdms2.open(path, mode)
self.files.append(f)
return f

def getDataFile(self, name):
pth = os.path.dirname(os.path.abspath(__file__))
return self.getFile(os.path.join(pth, "data", name))

def getTempFile(self, path, mode="r"):
return self.getFile(os.path.join(self.tempdir, path), mode)

def setUp(self):
global cdms2
cdms2 = reload(cdms2)
self.orig_cwd = os.getcwd()
self.files = []
self.NTIME = 3
self.NLAT = 16
self.NLON = 32
self.test_arr = numpy.ma.arange(float(2 * self.NTIME * self.NLAT * self.NLON))
self.test_arr.shape = (2, self.NTIME, self.NLAT, self.NLON)
self.tempdir = tempfile.mkdtemp()

def tearDown(self):
for f in self.files:
f.close()
os.chdir(self.orig_cwd)
shutil.rmtree(self.tempdir)

def run():
unittest.main()
13 changes: 0 additions & 13 deletions Test/cdtest.py

This file was deleted.

File renamed without changes.
104 changes: 104 additions & 0 deletions Test/data/cdtest13.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0"?>
<!DOCTYPE dataset SYSTEM "http://www-pcmdi.llnl.gov/software/cdms/cdml.dtd">
<dataset
cdms_filemap ="[[[bounds_lat,bounds_lon,lat,lon,sample],[[-,-,-,-,sampleCurveGrid4.nc]]]]"
institution ="Program for Climate Model Diagnosis and Intercomparison (PCMDI)"
directory =""
Conventions ="CF-1.0"
id ="none"
history ="[2003-9-9 14:55:26] genSampleCgrid4.py
[2003-9-10 21:31:3] /idoru/cdat/dev/bin/cdscan -x cdtest13.xml sampleCurveGrid4.nc"
>
<attr datatype="String" name="source">Analytic data</attr>
<attr datatype="String" name="title">Sample data on a curvilinear grid</attr>
<axis
datatype ="Float"
units =""
length ="4"
id ="nvert"
>
[ 0. 1. 2. 3.]
</axis>
<axis
datatype ="Float"
units =""
length ="48"
id ="x"
>
[ 0. 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.]
</axis>
<axis
datatype ="Float"
units =""
length ="32"
id ="y"
>
[ 0. 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.]
</axis>
<variable
datatype ="Double"
id ="bounds_lat"
>
<domain
>
<domElem start="0" length="32" name="y"/>
<domElem start="0" length="48" name="x"/>
<domElem start="0" length="4" name="nvert"/>
</domain>
</variable>
<variable
datatype ="Double"
id ="bounds_lon"
>
<domain
>
<domElem start="0" length="32" name="y"/>
<domElem start="0" length="48" name="x"/>
<domElem start="0" length="4" name="nvert"/>
</domain>
</variable>
<variable
datatype ="Double"
units ="degrees_north"
id ="lat"
long_name ="latitude"
>
<attr datatype="String" name="bounds">bounds_lat</attr>
<domain
>
<domElem start="0" length="32" name="y"/>
<domElem start="0" length="48" name="x"/>
</domain>
</variable>
<variable
datatype ="Double"
units ="degrees_east"
id ="lon"
long_name ="longitude"
>
<attr datatype="String" name="bounds">bounds_lon</attr>
<domain
>
<domElem start="0" length="32" name="y"/>
<domElem start="0" length="48" name="x"/>
</domain>
</variable>
<variable
datatype ="Double"
units ="m/s"
id ="sample"
long_name ="Sample variable"
>
<attr datatype="String" name="coordinates">lon lat</attr>
<domain
>
<domElem start="0" length="32" name="y"/>
<domElem start="0" length="48" name="x"/>
</domain>
</variable>
</dataset>
725 changes: 725 additions & 0 deletions Test/data/cdtest14.xml

Large diffs are not rendered by default.

Binary file added Test/data/dvtest1.dat
Binary file not shown.
Binary file added Test/data/dvtest1.dic
Binary file not shown.
Binary file added Test/data/ps.wrap.test.0E.nc
Binary file not shown.
Binary file added Test/data/readonly.nc
Binary file not shown.
Binary file added Test/data/sampleCurveGrid4.nc
Binary file not shown.
Binary file added Test/data/sampleGenGrid3.nc
Binary file not shown.
Binary file added Test/data/tas_mo_clim.nc
Binary file not shown.
Binary file added Test/data/tdata.hdf
Binary file not shown.
67 changes: 67 additions & 0 deletions Test/data/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<!DOCTYPE dataset SYSTEM "http://www-pcmdi.llnl.gov/software/cdms/cdml.dtd">
<dataset
Conventions ="CF-1.0"
cdms_filemap ="[[[u],[[0,1,-,-,-,u_2000.nc],[1,2,-,-,-,u_2001.nc],[2,3,-,-,-,u_2002.nc]]],[[v],[[0,1,-,-,-,v_2000.nc],[1,2,-,-,-,v_2001.nc],[2,3,-,-,-,v_2002.nc]]]]"
directory =""
calendar ="gregorian"
id ="test"
>
<axis
datatype ="Double"
units ="degrees_north"
length ="16"
id ="latitude"
>
[-90. -78. -66. -54. -42. -30. -18. -6. 6. 18. 30. 42. 54. 66. 78.
90.]
</axis>
<axis
datatype ="Double"
units ="degrees_east"
length ="32"
id ="longitude"
>
[ 0. 11.25 22.5 33.75 45. 56.25 67.5 78.75 90.
101.25 112.5 123.75 135. 146.25 157.5 168.75 180. 191.25
202.5 213.75 225. 236.25 247.5 258.75 270. 281.25 292.5
303.75 315. 326.25 337.5 348.75]
</axis>
<axis
name_in_file ="time"
datatype ="Double"
partition ="[0 1 1 2 2 3]"
length ="3"
units ="days since 2000-1-1"
calendar ="gregorian"
id ="time"
>
[ 0. 366. 731.]
</axis>
<variable
datatype ="Double"
units ="m/s"
missing_value ="-99.9"
id ="u"
>
<domain
>
<domElem start="0" length="3" name="time"/>
<domElem start="0" length="16" name="latitude"/>
<domElem start="0" length="32" name="longitude"/>
</domain>
</variable>
<variable
datatype ="Double"
units ="m/s"
missing_value ="-99.9"
id ="v"
>
<domain
>
<domElem start="0" length="3" name="time"/>
<domElem start="0" length="16" name="latitude"/>
<domElem start="0" length="32" name="longitude"/>
</domain>
</variable>
</dataset>
30 changes: 30 additions & 0 deletions Test/data/testgrib2.ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
dset ^testgrib2.grib2
index ^testgrib2.idx
undef 9.999E+20
title testgrib2.grib2
* produced by g2ctl v0.0.4o
* griddef=1:0:(10 x 20):grid_template=0:winds(N/S) lat-lon grid:(10 x 20) units 1e-06 input WE:SN output WE:SN res 48 lat -63.000000 to -53.500000 by 0.500000 lon 4.500000 to 9.000000 by 0.500000 #points=200:winds(N/S)

dtype grib2
ydef 20 linear -63.000000 0.5
xdef 10 linear 4.500000 0.500000
tdef 15 linear 12Z23sep2009 3hr
zdef 1 linear 1 1
vars 16
DIRPWsfc 0,1,1 10,0,10 ** surface Primary Wave Direction [deg]
HTSGWsfc 0,1,1 10,0,3 ** surface Significant Height of Combined Wind Waves and Swell [m]
PERPWsfc 0,1,1 10,0,11 ** surface Primary Wave Mean Period [s]
SWDIR_1 0,241,1 10,0,7 ** 1 in sequence Direction of Swell Waves [deg]
SWDIR_2 0,241,2 10,0,7 ** 2 in sequence Direction of Swell Waves [deg]
SWELL_1 0,241,1 10,0,8 ** 1 in sequence Significant Height of Swell Waves [m]
SWELL_2 0,241,2 10,0,8 ** 2 in sequence Significant Height of Swell Waves [m]
SWPER_1 0,241,1 10,0,9 ** 1 in sequence Mean Period of Swell Waves [s]
SWPER_2 0,241,2 10,0,9 ** 2 in sequence Mean Period of Swell Waves [s]
UGRDsfc 0,1,1 0,2,2 ** surface U-Component of Wind [m/s]
VGRDsfc 0,1,1 0,2,3 ** surface V-Component of Wind [m/s]
WDIRsfc 0,1,1 0,2,0 ** surface Wind Direction (from which blowing) [deg]
WINDsfc 0,1,1 0,2,1 ** surface Wind Speed [m/s]
WVDIRsfc 0,1,1 10,0,4 ** surface Direction of Wind Waves [deg]
WVHGTsfc 0,1,1 10,0,5 ** surface Significant Height of Wind Waves [m]
WVPERsfc 0,1,1 10,0,6 ** surface Mean Period of Wind Waves [s]
ENDVARS
Binary file added Test/data/testgrib2.grib2
Binary file not shown.
Binary file added Test/data/testgrib2.idx
Binary file not shown.
Binary file added Test/data/testpp.pp
Binary file not shown.
Binary file added Test/data/u_2000.nc
Binary file not shown.
Binary file added Test/data/u_2001.nc
Binary file not shown.
Binary file added Test/data/u_2002.nc
Binary file not shown.
Binary file added Test/data/v_2000.nc
Binary file not shown.
Binary file added Test/data/v_2001.nc
Binary file not shown.
Binary file added Test/data/v_2002.nc
Binary file not shown.
64 changes: 0 additions & 64 deletions Test/genTestDataset.py

This file was deleted.

27 changes: 27 additions & 0 deletions Test/test_all_formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import cdms2
import os
import sys
import cdat_info
import basetest


class TestFormats(basetest.CDMSBaseTest):
def testPP(self):
f = self.getDataFile('testpp.pp')

def testHDF(self):
if cdat_info.CDMS_INCLUDE_HDF == "yes":
f = self.getDataFile("tdata.hdf")

def testDRS(self):
f = self.getDataFile("dvtest1.dic")

def testDAP(self):
f = cdms2.open('http://test.opendap.org/opendap/hyrax/data/nc/coads_climatology.nc')
f.close()

def testGRIB2(self):
f = self.getDataFile("testgrib2.ctl")

if __name__ == "__main__":
basetest.run()
Loading