Commit efc4caca authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

deleted old unused python tests

parent d502808c
from cdo import *
def createInputFiles(nfiles,resolution,cdo,cdoOptions):
timeDefaults = '-settunits,days -settaxis,20010101,12:00:00'
randomEnlarge = lambda resolution: '-mul -random,'+resolution+' -enlarge,'+resolution
fileList = {}
cdo.debug = False
FileKeys = ['1d','2d','3d','1d_withTime','2d_withTime','3d_withTime']
for i,key in enumerate(FileKeys):
fileList[key] = []
if '1d' == key:
# vertical levels only
for j in xrange(0,nfiles):
fileList[key].append(cdo.stdatm(0,10,20,50, options = cdoOptions))
elif '2d' == key:
for j in xrange(0,nfiles):
fileList[key].append(cdo.setcode(130,input = "-setname,'T' -random,"+resolution, options = cdoOptions))
elif '3d' == key:
for j in xrange(0,nfiles):
fileList[key].append(cdo.enlarge(resolution, input = '-stdatm,0,10,20,50', options = cdoOptions))
elif '1d_withTime' == key:
# temporal axis only
for j in xrange(0,nfiles):
fileList[key].append(cdo.setcode(130,input = cdo.setname('T',input = timeDefaults+' -for,1,400', options = cdoOptions)))
elif '2d_withTime' == key:
for j in xrange(0,nfiles):
fileList[key].append(cdo.setcode(130,input = cdo.setname('T',input = randomEnlarge(resolution) +' ' +timeDefaults+ ' -for,1,400', options = cdoOptions)))
elif '3d_withTime' == key:
for j in xrange(0,nfiles):
fileList[key].append(cdo.enlarge(resolution, input = '-mul '+timeDefaults+ ' -stdatm,0,10,20 -for,1,400', options = cdoOptions))
return fileList
if __name__ == '__main__':
cdo = Cdo()
a = createInputFiles(5,'r36x18',cdo,'-f nc')
for i,value in enumerate(a):
files = a[value]
for f in files:
print(' '.join([value,f,os.path.exists(f).__str__()]))
#!/usr/bin/env python
import unittest
from cdo import *
import testStreams
class TestArith(unittest.TestCase):
def test_add(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.add(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_sub(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.sub(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_mul(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.mul(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_div(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.div(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_min(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.min(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_max(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.max(input = ' '.join(files[0:2]))
self.assertEqual("","")
def test_atan2(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.atan2(input = ' '.join(files[0:2]))
self.assertEqual("","")
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
import unittest
from cdo import *
import testStreams
class TestArithc(unittest.TestCase):
def test_addc(self):
cdo = Cdo()
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.addc('2.718281828459045',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_subc(self):
cdo = Cdo()
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.subc('2.718281828459045',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_mulc(self):
cdo = Cdo()
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.mulc('2.718281828459045',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_divc(self):
cdo = Cdo()
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.divc('2.718281828459045',input = ' '.join(files[0:1]))
self.assertEqual("","")
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
import unittest
from cdo import *
import testStreams
class TestSelvar(unittest.TestCase):
def test_selparam(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.selparam('130',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_delparam(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.delparam('130',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selcode(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.selcode('130',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_delcode(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.delcode('130',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selname(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.selname('T',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_delname(self):
cdo = Cdo()
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.delname('T',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selstdname(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.selstdname('T',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_sellevel(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
if '1d_withTime' == value:
continue
result = cdo.sellevel('0,10,20,50,100,200,500,1000,2000,5000,10000',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_sellevidx(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
if '1d_withTime' == value:
continue
result = cdo.sellevidx('1',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selgrid(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.selgrid('1',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selzaxis(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
if '1d_withTime' == value:
continue
result = cdo.selzaxis('1',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_selltype(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
if '1d_withTime' == value:
continue
result = cdo.selltype('105',input = ' '.join(files[0:1]))
self.assertEqual("","")
def test_seltabnum(self):
cdo = Cdo()
cdo.debug = True
testFiles = testStreams.createInputFiles(4,'r2x2',cdo,'-f nc')
for i,value in enumerate(testFiles):
files = testFiles[value]
result = cdo.seltabnum('128',input = ' '.join(files[0:1]))
self.assertEqual("","")
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
#!/usr/bin/env python
import unittest
from cdo import *
class TestDiff(unittest.TestCase):
def test_diff(self):
cdo = Cdo()
diffv = cdo.diffn(input = "-const,4,r1x1 -const,2,r1x1")
self.assertEqual(diffv[1].split(' ')[-1],"const")
self.assertEqual(diffv[1].split(' ')[-3],"0.50000")
diff = cdo.diff(input = "-const,4,r1x1 -const,2,r1x1")
self.assertEqual(diff[1].split(' ')[-3],"0.50000")
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
import unittest
from cdo import *
class TestInfo(unittest.TestCase):
# check operators: (s)infov,showlevel
def test_info(self):
cdo = Cdo()
info = cdo.sinfo(input = "-stdatm,0")
self.assertEqual("File format: GRIB",info[0])
sinfov = cdo.sinfov(input = "-stdatm,0,10,20,50,100,500,1000",options = "-f nc")
self.assertEqual("P",sinfov[2].split(' ')[-1])
self.assertEqual("T",sinfov[3].split(' ')[-1])
infov = cdo.infov( input = "-stdatm,0,10,20,50,100,500,1000",options = "-f nc")
self.assertEqual("1013.2", infov[1].split(' ')[-15])
self.assertEqual("T", infov[-1].split(' ')[-1])
units = cdo.showunit( input = "-stdatm,0", options = "-f nc")
self.assertEqual(["hPa","K"],units[0].split(' '))
levels = cdo.showlevel(input = "-stdatm,0")
self.assertEqual([0,0],map(float,levels))
levels = cdo.showlevel(input = "-stdatm,10,20,30")[0].split(' ')
self.assertEqual([10,20,30],map(float,levels))
code = cdo.showcode(input="-topo,r1x1")
self.assertEqual("-1",code[0])
code = cdo.showcode(input="-setcode,111 -topo,r1x1")
self.assertEqual("111",code[0])
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
import unittest
from cdo import *
class TestIntgridbil(unittest.TestCase):
def test_intrgidbil(self):
# dummy
self.assertEqual(0,0)
def test_global(self):
# cdo cmd:
# cdo -f nc intgridbil,global_.1 -topo result.nc
cdo = Cdo()
cdo.intgridbil('global_.1',input="-topo",output="result.nc",options="-f nc")
# dummy, TODO cdo diff
self.assertEqual(0,0)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment