Skip to content

Commit 61bcc5a

Browse files
committed
add fixes for 2.0.x versions
1 parent 4c4e36e commit 61bcc5a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

python/test/test_cdo.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,14 @@ def test_outputOperators(self):
186186
'2001-01-01T19:00:00',
187187
'2001-01-01T20:00:00',
188188
'2001-01-01T21:00:00']
189-
self.assertEqual(timesExpected,
190-
cdo.showtimestamp(input="-settaxis,2001-01-01,12:00,1hour -for,1,10", autoSplit=' '))
189+
if (parse_version(cdo.version()) == parse_version('2.0.0')):
190+
# cdo-2.0.0 does not put output on a single line with '-s' like previous and later versions'
191+
timesExpected = [['2001-01-01T12:00:00', '2001-01-01T13:00:00', '2001-01-01T14:00:00', '2001-01-01T15:00:00'],
192+
['2001-01-01T16:00:00', '2001-01-01T17:00:00', '2001-01-01T18:00:00', '2001-01-01T19:00:00'],
193+
['2001-01-01T20:00:00', '2001-01-01T21:00:00']]
194+
195+
actualOutput = cdo.showtimestamp(input="-settaxis,2001-01-01,12:00,1hour -for,1,10", autoSplit=' ')
196+
self.assertEqual(timesExpected, actualOutput)
191197

192198
self.assertEqual(['P T'],cdo.showname(input="-stdatm,0"))
193199
self.assertEqual(['P','T'],cdo.showname(input="-stdatm,0",autoSplit=' '))
@@ -221,15 +227,20 @@ def test_pychain2(self):
221227
ofile1 = cdo.setname("veloc").copy.random("r1x1").add_option("-f nc").run()
222228
cdo = Cdo()
223229
ofile2 = cdo.setname("veloc", input=" -copy -random,r1x1",options = "-f nc")
224-
diff = cdo.diff(input=[ofile1, ofile2])
230+
diff = cdo.diff(input=[ofile1, ofile2], options='-s')
225231
self.assertFalse(diff, msg=diff)
226232

227233
def test_diff(self):
228234
cdo = Cdo()
229235
cdo.debug = DEBUG
230236
diffv = cdo.diffn(input = "-random,global_0.5 -random,global_0.5")
231-
self.assertEqual('random', diffv[-2].split(' ')[-1],"random")
232-
self.assertEqual('1 of 1 records differ',diffv[-1])
237+
thisVersion = parse_version(cdo.version())
238+
if (thisVersion >= parse_version('2.0.0') and thisVersion <= parse_version('2.0.5')):
239+
self.assertEqual('random', diffv[-5].split(' ')[-1],"random")
240+
self.assertEqual('1 of 1 records differ',diffv[-4])
241+
else:
242+
self.assertEqual('random', diffv[-2].split(' ')[-1],"random")
243+
self.assertEqual('1 of 1 records differ',diffv[-1])
233244

234245
def test_returnCdf(self):
235246
cdo = Cdo()
@@ -491,16 +502,17 @@ def test_errorException(self):
491502
def test_inputArray(self):
492503
cdo = Cdo()
493504
cdo.debug = DEBUG
505+
cdo.silent = True
494506
# check for file input
495507
fileA = cdo.stdatm(0,output='A_{0}'.format( random.randrange(1,100000)))
496508
fileB = cdo.stdatm(0,output='B_{0}'.format( random.randrange(1,100000)))
497509
files = [fileA,fileB]
498-
self.assertEqual(cdo.diffv(input = ' '.join(files)), cdo.diffv(input = files))
499-
self.assertEqual([],cdo.diffv(input = files))
510+
self.assertEqual(cdo.diffv(input = ' '.join(files), options='-s'), cdo.diffv(input = files, options='-s'))
511+
self.assertEqual([],cdo.diffv(input = files, options='-s'))
500512
# check for operator input
501-
self.assertEqual([],cdo.diffv(input = ["-stdatm,0","-stdatm,0"]))
513+
self.assertEqual([],cdo.diffv(input = ["-stdatm,0","-stdatm,0"], options='-s'))
502514
# check for operator input and files
503-
self.assertEqual([],cdo.diffv(input = ["-stdatm,0",fileB]))
515+
self.assertEqual([],cdo.diffv(input = ["-stdatm,0",fileB], options='-s'))
504516
rm([fileA, fileB])
505517

506518
def test_splitOps(self):
@@ -796,6 +808,8 @@ def testVerifyGrid(self):
796808
output = cdo.verifygrid(input='-topo,global_10')
797809
self.assertEqual([],output)
798810

811+
self.assertEqual(True,cdo.silent)
812+
799813
cdo.silent = False
800814
output = cdo.verifygrid(input='-topo,global_10')
801815
if parse_version('2.0.6') <= parse_version(cdo.version()):

0 commit comments

Comments
 (0)