source: CCCC/trunk/unitTestsS2.py @ 103

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

added specific file handle tracking test to unit test suite 2

Line 
1
2import logging, time
3import utils_c4
4import config_c4 as config
5from c4 import fileMetadata, dummy, main
6
7#### set up log file ####
8tstring2 = '%4.4i%2.2i%2.2i' % time.gmtime()[0:3]
9testLogFile = '%s__qclog_%s.txt' % ('unitTestsS2',tstring2)
10log = logging.getLogger(testLogFile)
11fHdlr = logging.FileHandler(testLogFile,mode='w')
12fileFormatter = logging.Formatter('%(message)s')
13fHdlr.setFormatter(fileFormatter)
14log.addHandler(fHdlr)
15log.setLevel(logging.INFO)
16
17try:
18  fmd = fileMetadata(dummy=True)
19  fmd.loadNc( '/dummyPath/v1_day_a_b_1990-1991.nc')
20except:
21  print 'Failed to parse a simple dummy file path'
22  raise
23print 'OK: instantiated fileMetaData and parsed a simple dummy path'
24
25p = dummy()
26p.log = log
27p.abortMessageCount = -1
28p.pcfg = config.projectConfig( "__dummy" )
29
30
31module = 'checkFileName'
32c = utils_c4.checkFileName(parent=p)
33
34fn = 'v1_t1_a_b_20060101-20101231.nc'
35testId = '#10.001'
36c.check( fn )
37if c.errorCount == 0:
38  print 'OK [%s] %s: valid file name with project=__dummy' % (module,fn)
39else:
40  print 'Failed [%s] %s: valid file name' % (module,fn)
41
42
43testId = '#11.001'
44try:
45  m = main( args=['-p', '__dummy'], monitorFileHandles=True )
46  print 'OK [%s]: dummy run completed without exception' % testId
47except:
48  print 'Failed [%s]: dummy run triggered exception' % testId
49  raise
50
51testId = '#11.002'
52if m.monitor.fhCountMax < 10:
53  print 'OK [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
54else:
55  print 'Failed [%s]: fhCountMax = %s' % ( testId, m.monitor.fhCountMax )
56
57testId = '#11.003'
58try:
59  m = main( args=['-p', '__dummy'], abortMessageCount=10 )
60  print 'Failed [%s]: did not trigger exception' % testId
61except:
62  print 'OK [%s]: attempt to trigger exception successful' % testId
Note: See TracBrowser for help on using the repository browser.