Changeset 103
- Timestamp:
- 07/12/13 03:33:46 (7 years ago)
- Location:
- CCCC/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
CCCC/trunk/c4.py
r101 r103 62 62 self.va[v] = {} 63 63 self.va[v]['standard_name'] = 's%s' % v 64 self.va[v]['name'] = v 64 self.va[v]['long_name'] = v 65 self.va[v]['cell_methods'] = 'time: point' 65 66 self.va[v]['units'] = '1' 66 67 self.va[v]['_type'] = 'float32' … … 73 74 svals = lambda p,q: map( lambda y,z: self.da[y].__setitem__(p, z), dlist, q ) 74 75 svals( 'standard_name', ['latitude', 'longitude','time'] ) 75 svals( ' name', ['latitude', 'longitude','time'] )76 svals( 'long_name', ['latitude', 'longitude','time'] ) 76 77 svals( 'units', ['degrees_north', 'degrees_east','days since 19590101'] ) 77 78 … … 213 214 214 215 class checker: 215 def __init__(self, pcfg, cls,reader ):216 def __init__(self, pcfg, cls,reader,abortMessageCount=-1): 216 217 self.info = dummy() 217 218 self.info.pcfg = pcfg 219 self.info.abortMessageCount = abortMessageCount 218 220 self.calendar = 'None' 219 221 self.ncReader = reader … … 379 381 cl.append( string.split(b, '=' ) ) 380 382 self.attributeMappings.append( ('am001',cl, string.split(bb[1],'=') ) ) 381 print self.attributeMappings382 383 383 384 def getFileLog( self, fn, flf=None ): … … 408 409 class main: 409 410 410 def __init__(self,args=None ):411 def __init__(self,args=None,holdExceptions=False,abortMessageCount=-1,printInfo=False,monitorFileHandles = False): 411 412 logDict = {} 413 ecount = 0 412 414 c4i = c4_init(args=args) 413 415 isDummy = c4i.project[:2] == '__' … … 418 420 pcfg = config.projectConfig( c4i.project ) 419 421 ncReader = fileMetadata(dummy=isDummy) 420 cc = checker(pcfg, c4i.project, ncReader )422 cc = checker(pcfg, c4i.project, ncReader,abortMessageCount=abortMessageCount) 421 423 rec = recorder( c4i.recordFile, dummy=isDummy ) 422 monitorFileHandles = False423 424 if monitorFileHandles: 424 monitor = utils.sysMonitor()425 else: 426 monitor = None425 self.monitor = utils.sysMonitor() 426 else: 427 self.monitor = None 427 428 428 429 cal = None 429 430 430 c4i.logger.info( 'Starting batch -- number of file: %s' % (len(c4i.flist)) ) 431 431 432 cbv = utils.checkByVar( parent=cc.info,cls=c4i.project,monitor= monitor)432 cbv = utils.checkByVar( parent=cc.info,cls=c4i.project,monitor=self.monitor) 433 433 cbv.impt( c4i.flist ) 434 if printInfo: 435 print cbv.info 434 436 435 437 for f in c4i.flist: 436 438 if monitorFileHandles: 437 nofhStart = monitor.get_open_fds()439 nofhStart = self.monitor.get_open_fds() 438 440 fn = string.split(f,'/')[-1] 439 441 c4i.logger.info( 'Starting: %s' % fn ) … … 468 470 if cc.completed: 469 471 c4i.logger.info( 'Done -- error count %s' % cc.errorCount ) 472 ecount += cc.errorCount 470 473 if cc.errorCount == 0: 471 474 rec.add( f, cc.drs ) … … 473 476 rec.addErr( f, 'ERRORS FOUND | errorCount = %s' % cc.errorCount ) 474 477 else: 478 ecount += 20 475 479 c4i.logger.info( 'Done -- testing aborted because of severity of errors' ) 476 480 rec.addErr( f, 'ERRORS FOUND AND CHECKS ABORTED' ) … … 478 482 c4i.logger.error("Exception has occured" ,exc_info=1) 479 483 rec.addErr( f, 'ERROR: Exception' ) 484 if not holdExceptions: 485 raise 480 486 if monitorFileHandles: 481 nofhEnd = monitor.get_open_fds()487 nofhEnd = self.monitor.get_open_fds() 482 488 if nofhEnd > nofhStart: 483 489 print 'Open file handles: %s --- %s' % (nofhStart, nofhEnd) … … 489 495 cbv.setLogDict( logDict ) 490 496 cbv.check( recorder=rec, calendar=cc.calendar) 497 try: 498 ecount += cbv.errorCount 499 except: 500 ecount = None 491 501 rec.dumpAll() 502 if printInfo: 503 print 'Error count %s' % ecount 492 504 c4i.hdlr.close() 493 505 if __name__ == '__main__': 494 main( )506 main(printInfo=True) 495 507 496 508 -
CCCC/trunk/unitTestsS1.py
r95 r103 24 24 p.log = log 25 25 p.pcfg = config.projectConfig( "CORDEX" ) 26 p.abortMessageCount = -1 26 27 27 28 -
CCCC/trunk/unitTestsS2.py
r101 r103 25 25 p = dummy() 26 26 p.log = log 27 p.abortMessageCount = -1 27 28 p.pcfg = config.projectConfig( "__dummy" ) 28 29 … … 32 33 33 34 fn = 'v1_t1_a_b_20060101-20101231.nc' 34 testId = '# 01.001'35 testId = '#10.001' 35 36 c.check( fn ) 36 37 if c.errorCount == 0: 37 print ' Passed [%s] %s: valid file name' % (module,fn)38 print 'OK [%s] %s: valid file name with project=__dummy' % (module,fn) 38 39 else: 39 40 print 'Failed [%s] %s: valid file name' % (module,fn) 40 41 41 42 42 main( args=['-p', '__dummy'] ) 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 -
CCCC/trunk/utils_c4.py
r100 r103 85 85 self.cls = cls 86 86 self.project = cls 87 self.abortMessageCount = parent.abortMessageCount 87 88 self.monitor = monitor 88 89 ## check done earlier … … 103 104 ####################################### 104 105 self.checks = () 106 self.messageCount = 0 105 107 self.init() 106 108 … … 109 111 110 112 def logMessage(self, msg, error=False ): 113 self.messageCount += 1 114 assert self.abortMessageCount < 0 or self.abortMessageCount > self.messageCount, 'Raising error [TESTX01], perhaps for testing' 111 115 if self.parent != None and self.parent.log != None: 112 116 if error: … … 677 681 self.varInfo = {} 678 682 self.varcons = {} 679 ee = { 'standard_name':'sn%s', ' name':'n%s', 'units':'1' }683 ee = { 'standard_name':'sn%s', 'long_name':'n%s', 'units':'1' } 680 684 dir, tl, vgmap, fnpat = self.pcfg.mipVocabPars 681 685 for f in tl: … … 686 690 eeee = {} 687 691 eeee['standard_name'] = ee['standard_name'] % i 688 eeee['name'] = ee['name'] % i 692 eeee['long_name'] = ee['long_name'] % i 693 eeee['cell_methods'] = 'time: point' 689 694 eeee['units'] = ee['units'] 690 695 ar = [] … … 781 786 782 787 assert nn==n2, 'some file lost!!!!!!' 783 print'%s files, %s frequencies' % (nn,len(ee.keys()) )788 self.info = '%s files, %s frequencies' % (nn,len(ee.keys()) ) 784 789 self.ee = ee 785 790 … … 847 852 848 853 def __init__(self): 849 pass854 self.fhCountMax = 0 850 855 851 856 def get_open_fds(self): … … 864 869 lambda s: s and s[ 0 ] == 'f' and s[1: ].isdigit(), 865 870 self.procs.split( '\n' ) ) 871 self.fhCountMax = max( self.fhCountMax, len(self.ps) ) 866 872 return len( self.ps )
Note: See TracChangeset
for help on using the changeset viewer.