source: CCCC/trunk/ceda_cc/unitTestsS2.py @ 276

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CCCC/trunk/ceda_cc/unitTestsS2.py@276
Revision 276, 3.6 KB checked in by mjuckes, 5 years ago (diff)

cleaned up unit tests and handling of fixed files

Line 
1import logging, time, os
2import utils_c4
3import config_c4 as config
4from c4 import fileMetadata, dummy, main
5from xceptions import *
6
7from file_utils import installedSupportedNetcdf
8
9#### set up log file ####
10tstring2 = '%4.4i%2.2i%2.2i' % time.gmtime()[0:3]
11testLogFile = '%s__qclog_%s.txt' % ('unitTestsS2',tstring2)
12log = logging.getLogger(testLogFile)
13fHdlr = logging.FileHandler(testLogFile,mode='w')
14fileFormatter = logging.Formatter('%(message)s')
15fHdlr.setFormatter(fileFormatter)
16log.addHandler(fHdlr)
17log.setLevel(logging.INFO)
18
19try:
20  fmd = fileMetadata(dummy=True)
21  fmd.loadNc( '/dummyPath/v1_day_a_b_1990-1991.nc')
22except:
23  print 'Failed to parse a simple dummy file path'
24  raise baseException( 'Failed to parse a simple dummy file path' )
25print 'OK: instantiated fileMetaData and parsed a simple dummy path'
26
27p = dummy()
28p.log = log
29p.abortMessageCount = -1
30p.pcfg = config.projectConfig( "__dummy" )
31
32
33module = 'checkFileName'
34c = utils_c4.checkFileName(parent=p)
35
36fn = 'v1_t1_a_b_20060101-20101231.nc'
37testId = '#10.001'
38c.check( fn )
39if c.errorCount == 0:
40  print 'OK: [%s] %s: valid file name with project=__dummy' % (module,fn)
41else:
42  print 'Failed [%s] %s: valid file name' % (module,fn)
43
44testId = '#11.001'
45try:
46  m = main( args=['-p', '__dummy'], monitorFileHandles=True )
47  print 'OK: [%s]: dummy run completed without exception' % testId
48except:
49  print 'Failed [%s]: dummy run triggered exception' % testId
50  raise baseException( 'Failed [%s]: dummy run triggered exception' % testId )
51
52testId = '#11.002'
53if m.monitor.fhCountMax < 10:
54  print 'OK: [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
55else:
56  print 'Failed [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
57
58testId = '#11.003'
59try:
60  m = main( args=['-p', '__dummy'], abortMessageCount=10 )
61  print 'Failed [%s]: did not trigger exception' % testId
62except:
63  print 'OK: [%s]: attempt to trigger exception successful' % testId
64
65
66extras = [
67( '/data/work/cmip5/output1/pr_20110323/pr_3hr_HadGEM2-ES_historical_r2i1p1_196001010130-196412302230.nc', 'CMIP5', 0 ),
68('/data/work/cmip5/output1/pr_20110323/pr_3hr_HadGEM2-ES_historical_r2i1p1_200001010130-200412302230.nc', 'CMIP5', 0 ) ]
69
70
71kt = 0
72for e in extras:
73  kt += 1
74  if os.path.isfile( e[0] ):
75    if 'cdms2' in installedSupportedNetcdf:
76      testId = '#20.%3.3i' % kt
77      m = main( args=['-p', e[1], '-f', e[0], '--force-cdms2','--ld', 'ld_test1' ], abortMessageCount=10 )
78      if m.ok:
79         print 'OK: [%s]: successfully checked test file with cdms2' % testId
80      else:
81         print 'Failed [%s]: incorrect test results' % testId
82
83    testId = '#21.%3.3i' % kt
84    m = main( args=['-p', e[1], '-f', e[0], '--force-ncq','--ld', 'ld_test2' ], abortMessageCount=10 )
85    if m.ok:
86       print 'OK: [%s]: successfully checked test file with ncq3' % testId
87    else:
88       print 'Failed [%s]: incorrect test results' % testId
89
90    if 'netCDF4' in installedSupportedNetcdf:
91      testId = '#22.%3.3i' % kt
92      m = main( args=['-p', e[1], '-f', e[0], '--force-pync4','--ld', 'ld_test3' ], abortMessageCount=10 )
93      if m.ok:
94         print 'OK: [%s]: successfully checked test file with python NetCDF4' % testId
95      else:
96         print 'Failed [%s]: incorrect test results' % testId
97
98    if 'Scientific' in installedSupportedNetcdf:
99      testId = '#23.%3.3i' % kt
100      m = main( args=['-p', e[1], '-f', e[0], '--force-scientific','--ld', 'ld_test4' ], abortMessageCount=10 )
101      if m.ok:
102         print 'OK: [%s]: successfully checked test file with python Scientific' % testId
103      else:
104         print 'Failed [%s]: incorrect test results' % testId
105     
106   
Note: See TracBrowser for help on using the repository browser.