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

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

drastically reduced content of c4.py -- moved code to c4_run.py

Line 
1import logging, time, os, sys
2import utils_c4
3import config_c4 as config
4from c4_run 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
44if sys.version_info >= (2,7):
45  ## monitoting file handles uses a "subprocess" method which is not available in python 2.6
46  testId = '#11.001'
47  try:
48    m = main( args=['-p', '__dummy'], monitorFileHandles=True )
49    print 'OK: [%s]: dummy run completed without exception' % testId
50  except:
51    print 'Failed [%s]: dummy run triggered exception' % testId
52    raise
53    raise baseException( 'Failed [%s]: dummy run triggered exception' % testId )
54
55  testId = '#11.002'
56  if m.monitor.fhCountMax < 15:
57    print 'OK: [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
58  else:
59    print 'Failed [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
60
61testId = '#11.003'
62try:
63  m = main( args=['-p', '__dummy'], abortMessageCount=10 )
64  print 'Failed [%s]: did not trigger exception' % testId
65except:
66  print 'OK: [%s]: attempt to trigger exception successful' % testId
67
68
69extras = [
70( '/data/work/cmip5/output1/pr_20110323/pr_3hr_HadGEM2-ES_historical_r2i1p1_196001010130-196412302230.nc', 'CMIP5', 0 ),
71('/data/work/cmip5/output1/pr_20110323/pr_3hr_HadGEM2-ES_historical_r2i1p1_200001010130-200412302230.nc', 'CMIP5', 0 ) ]
72
73
74kt = 0
75for e in extras:
76  kt += 1
77  if os.path.isfile( e[0] ):
78    if 'cdms2' in installedSupportedNetcdf:
79      testId = '#20.%3.3i' % kt
80      m = main( args=['-p', e[1], '-f', e[0], '--force-cdms2','--ld', 'ld_test1' ], abortMessageCount=10 )
81      if m.ok:
82         print 'OK: [%s]: successfully checked test file with cdms2' % testId
83      else:
84         print 'Failed [%s]: incorrect test results' % testId
85
86    testId = '#21.%3.3i' % kt
87    m = main( args=['-p', e[1], '-f', e[0], '--force-ncq','--ld', 'ld_test2' ], abortMessageCount=10 )
88    if m.ok:
89       print 'OK: [%s]: successfully checked test file with ncq3' % testId
90    else:
91       print 'Failed [%s]: incorrect test results' % testId
92
93    if 'netCDF4' in installedSupportedNetcdf:
94      testId = '#22.%3.3i' % kt
95      m = main( args=['-p', e[1], '-f', e[0], '--force-pync4','--ld', 'ld_test3' ], abortMessageCount=10 )
96      if m.ok:
97         print 'OK: [%s]: successfully checked test file with python NetCDF4' % testId
98      else:
99         print 'Failed [%s]: incorrect test results' % testId
100
101    if 'Scientific' in installedSupportedNetcdf:
102      testId = '#23.%3.3i' % kt
103      m = main( args=['-p', e[1], '-f', e[0], '--force-scientific','--ld', 'ld_test4' ], abortMessageCount=10 )
104      if m.ok:
105         print 'OK: [%s]: successfully checked test file with python Scientific' % testId
106      else:
107         print 'Failed [%s]: incorrect test results' % testId
108     
109   
Note: See TracBrowser for help on using the repository browser.