Changeset 78


Ignore:
Timestamp:
23/10/13 09:27:07 (7 years ago)
Author:
mjuckes
Message:

cleaned up unitTestsS1.py a little

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/unitTestsS1.py

    r77 r78  
    11 
    22 
     3import logging, time 
    34import utils_c4 
    45 
    5 c = utils_c4.checkFileName() 
     6#### set up log file #### 
     7tstring2 = '%4.4i%2.2i%2.2i' % time.gmtime()[0:3] 
     8testLogFile = '%s__qclog_%s.txt' % ('unitTests',tstring2) 
     9log = logging.getLogger(testLogFile) 
     10fHdlr = logging.FileHandler(testLogFile,mode='w') 
     11fileFormatter = logging.Formatter('%(message)s') 
     12fHdlr.setFormatter(fileFormatter) 
     13log.addHandler(fHdlr) 
     14log.setLevel(logging.INFO) 
     15 
     16class dummy: 
     17 
     18  def __init__(self): 
     19     pass 
     20 
     21p = dummy() 
     22p.log = log 
     23 
     24 
     25module = 'checkFileName' 
     26c = utils_c4.checkFileName(parent=p) 
    627 
    728fn = 'ps_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_SMHI-RCA4_x1_day_20060101-20101231.nc' 
     
    930c.check( fn ) 
    1031if c.errorCount == 0: 
    11   print 'Passed %s: valid file name' % fn 
     32  print 'Passed [%s] %s: valid file name' % (module,fn) 
    1233else: 
    13   print 'Failed %s: valid file name' % fn 
     34  print 'Failed [%s] %s: valid file name' % (module,fn) 
    1435 
    1536testId = '#01.002' 
     
    1738c.check(fn) 
    1839if c.errorCount == 0 and c.isFixed: 
    19   print 'Passed %s: valid file name' % fn 
     40  print 'Passed [%s] %s: valid file name' % (module,fn) 
    2041else: 
    21   print 'Failed %s: valid file name' % fn 
     42  print 'Failed [%s] %s: valid file name' % (module,fn) 
    2243 
    2344testId = '#01.003' 
     
    2546c.check(fn) 
    2647if c.errorCount == 0: 
    27   print 'Passed %s: valid file name' % fn 
     48  print 'Passed [%s] %s: valid file name' % (module,fn) 
    2849else: 
    29   print 'Failed %s: valid file name' % fn 
     50  print 'Failed [%s] %s: valid file name' % (module,fn) 
    3051 
    3152testId = '#01.004' 
     
    3354c.check(fn) 
    3455if c.errorCount == 0: 
    35   print 'Passed %s: valid file name' % fn 
     56  print 'Passed [%s] %s: valid file name' % (module,fn) 
    3657else: 
    37   print 'Failed %s: valid file name' % fn 
     58  print 'Failed [%s] %s: valid file name' % (module,fn) 
    3859 
    3960testId = '#01.005' 
     
    4162c.check(fn) 
    4263if c.errorCount == 0: 
    43   print 'Failed to detect bad file name: %s ' % fn 
     64  print 'Failed to detect bad file name: [%s] %s ' % (module,fn) 
    4465else: 
    45   print 'OK -- detected bad file name: %s' % fn 
     66  print 'OK -- detected bad file name: [%s] %s' % (module,fn) 
    4667 
    4768c = utils_c4.checkByVar() 
     69module = 'checkByVar (regex)' 
    4870c.check( norun=True ) 
    4971import re 
     
    5274  m = r1.match( x ) 
    5375  if m: 
    54      print 'OK -- passed %s for sub-daily data' % x 
     76     print 'OK -- passed [%s] %s for sub-daily data' % (module,x) 
    5577  else: 
    56      print 'Failed to match correct sub-daily time range element %s' % x 
     78     print 'Failed to match correct sub-daily time range element [%s] %s' % (module,x) 
    5779 
    5880for x in ['200401010040','2004010200']: 
    5981  m = r1.match( x ) 
    6082  if not m: 
    61      print 'OK -- correctly failed %s for sub-daily data' % x 
     83     print 'OK -- correctly failed [%s] %s for sub-daily data' % (module,x) 
    6284  else: 
    63      print 'Failed to detect bad sub-daily time range element %s' % x 
     85     print 'Failed to detect bad sub-daily time range element [%s] %s' % (module,x) 
    6486 
    6587 
Note: See TracChangeset for help on using the changeset viewer.