source: CCCC/trunk/unitTestsS1.py @ 103

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CCCC/trunk/unitTestsS1.py@103
Revision 103, 4.5 KB checked in by mjuckes, 7 years ago (diff)

added specific file handle tracking test to unit test suite 2

Line 
1
2
3import logging, time
4import utils_c4
5import config_c4 as config
6
7
8#### set up log file ####
9tstring2 = '%4.4i%2.2i%2.2i' % time.gmtime()[0:3]
10testLogFile = '%s__qclog_%s.txt' % ('unitTests',tstring2)
11log = logging.getLogger(testLogFile)
12fHdlr = logging.FileHandler(testLogFile,mode='w')
13fileFormatter = logging.Formatter('%(message)s')
14fHdlr.setFormatter(fileFormatter)
15log.addHandler(fHdlr)
16log.setLevel(logging.INFO)
17
18class dummy:
19
20  def __init__(self):
21     pass
22
23p = dummy()
24p.log = log
25p.pcfg = config.projectConfig( "CORDEX" )
26p.abortMessageCount = -1
27
28
29module = 'checkFileName'
30c = utils_c4.checkFileName(parent=p)
31
32fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_day_20060101-20101231.nc'
33testId = '#01.001'
34c.check( fn )
35if c.errorCount == 0:
36  print 'Passed [%s] %s: valid file name' % (module,fn)
37else:
38  print 'Failed [%s] %s: valid file name' % (module,fn)
39
40testId = '#01.002'
41fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_fx.nc'
42c.check(fn)
43if c.errorCount == 0 and c.isFixed:
44  print 'Passed [%s] %s: valid file name' % (module,fn)
45else:
46  print 'Failed [%s] %s: valid file name' % (module,fn)
47
48testId = '#01.003'
49fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_3hr_2006010100-2010123100.nc'
50c.check(fn)
51if c.errorCount == 0:
52  print 'Passed [%s] %s: valid file name' % (module,fn)
53else:
54  print 'Failed [%s] %s: valid file name' % (module,fn)
55
56testId = '#01.004'
57fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_3hr_200601010030-201012310030.nc'
58c.check(fn)
59if c.errorCount == 0:
60  print 'Passed [%s] %s: valid file name' % (module,fn)
61else:
62  print 'Failed [%s] %s: valid file name' % (module,fn)
63
64testId = '#01.005'
65fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_day_200601010030-201012310030.nc'
66c.check(fn)
67if c.errorCount == 0:
68  print 'Failed to detect bad file name: [%s] %s ' % (module,fn)
69else:
70  print 'OK -- detected bad file name: [%s] %s' % (module,fn)
71
72c = utils_c4.checkStandardDims(parent=p)
73module = 'checkStandardDims'
74c.check( 'tas', 'day', {},{}, False )
75if c.errorCount == 0:
76  print 'Failed [%s]: failed to detect empty dictionaries' % module
77else:
78  print 'OK -- detected error in standard dims'
79
80c = utils_c4.checkByVar(parent=p)
81module = 'checkByVar (regex)'
82c.check( norun=True )
83import re
84r1 = re.compile( c.pats['subd'][0] )
85for x in ['200401010000','2004010100']:
86  m = r1.match( x )
87  if m:
88     print 'OK -- passed [%s] %s for sub-daily data' % (module,x)
89  else:
90     print 'Failed to match correct sub-daily time range element [%s] %s' % (module,x)
91
92for x in ['200401010040','2004010200']:
93  m = r1.match( x )
94  if not m:
95     print 'OK -- correctly failed [%s] %s for sub-daily data' % (module,x)
96  else:
97     print 'Failed to detect bad sub-daily time range element [%s] %s' % (module,x)
98
99r1 = re.compile( c.pats['sem'][0] )
100for x in ['199012','199101']:
101  m = r1.match( x )
102  if m:
103     print 'OK -- passed [%s] %s for seasonal data' % (module,x)
104  else:
105     print 'Failed to match correct seasonal time range element [%s] %s' % (module,x)
106
107for x in ['199011','199112']:
108  m = r1.match( x )
109  if not m:
110     print 'OK -- correctly failed [%s] %s for seasonal data' % (module,x)
111  else:
112     print 'Failed to detect bad seasonal time range element [%s] %s' % (module,x)
113
114r1 = re.compile( c.pats['mon'][0] )
115for x in ['199101']:
116  m = r1.match( x )
117  if m:
118     print 'OK -- passed [%s] %s for daily data' % (module,x)
119  else:
120     print 'Failed to match correct daily time range element [%s] %s -- %s' % (module,x,c.pats['day'][0])
121
122
123c = utils_c4.checkGrids(parent=p)
124c.interpolatedGrids = config.interpolatedGrids
125
126lat = map( lambda x: -46.25 + x*0.5, range(185) )
127lon = map( lambda x: -25.25 + x*0.5, range(173) )
128da = {'lat':{'_data':lat,'units':'degrees_north','long_name':'latitude','standard_name':'latitude','_type':'float64'}, 'lon':{'_data':lon,'units':'degrees_east','long_name':'longitude','standard_name':'longitude','_type':'float64'} }
129c.check( 'tas','AFR-44i', da, {'tas':{} } )
130if c.errorCount == 0:
131  print 'OK -- passed a correct grid'
132else:
133  print 'Failed -- reported errors on correct grid'
134lat = map( lambda x: -46.25 + x*0.5, range(180) )
135lon = map( lambda x: -25.25 + x*0.5, range(172) )
136da = {'lat':{'_data':lat,'units':'degrees_north','long_name':'latitude','standard_name':'latitude','_type':'float64'}, 'lon':{'_data':lon,'units':'degrees_east','long_name':'longitude','standard_name':'longitude','_type':'float64'} }
137c.check( 'tas','AFR-44i', da, {'tas':{} } )
138if c.errorCount == 0:
139  print 'Failed -- passed a bad grid'
140else:
141  print 'OK -- detected a bad grid'
Note: See TracBrowser for help on using the repository browser.