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