Changeset 6117


Ignore:
Timestamp:
Jan 6, 2009, 9:39:56 AM (10 years ago)
Author:
ole
Message:

Cleanup in caching

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/caching/caching.py

    r6071 r6117  
    407407# -----------------------------------------------------------------------------
    408408
    409 #Has mostly been moved to proper unit test
     409# Has mostly been moved to proper unit test.
     410# What remains here includes example of the
     411# cache statistics form.
    410412def test(cachedir=None,verbose=0,compression=None):
    411413  """Test the functionality of caching.
     
    424426  # Initialise
    425427  #
    426   import caching
    427   reload(caching)
     428  #import caching
     429  #reload(caching)
    428430
    429431  if not cachedir:
     
    520522    #
    521523    try:
    522       T1 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, evaluate=1, \
    523                          verbose=verbose, compression=comp)
     524      T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, evaluate=1, \
     525                   verbose=verbose, compression=comp)
    524526      if comp:                   
    525527        test_OK('Caching evaluation with compression')
     
    535537    #                           
    536538    try:                         
    537       T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    538                          compression=comp)
     539      T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     540                   compression=comp)
    539541
    540542      if comp:                   
     
    564566  #   
    565567  try:
    566     FN = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    567                        return_filename=1)   
     568    FN = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     569                 return_filename=1)   
    568570    assert(FN[:2] == 'f[')
    569571    test_OK('Return of cache filename')
     
    587589  #     
    588590  try:
    589     #T1 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     591    #T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    590592    #                   evaluate=1) 
    591     T4 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, test=1)
     593    T4 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, test=1)
    592594    assert(T1 == T4)
    593595
     
    599601  #
    600602  #try:
    601   #  caching.cache(f,'clear',verbose=verbose)
     603  #  cache(f,'clear',verbose=verbose)
    602604  #  test_OK('Clearing of cache files')
    603605  #except:
    604606  #  test_error('Clear does not work')
    605607  try:
    606     caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, clear=1)   
     608    cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, clear=1)   
    607609    test_OK('Clearing of cache files')
    608610  except:
     
    614616  #     
    615617  try:
    616     T4 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, test=1)
     618    T4 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, test=1)
    617619    assert(T4 is None)
    618620    test_OK("Option 'test' when cache absent")
     
    622624  # Test dependencies
    623625  #
    624   T1 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    625                        dependencies=DepFN) 
    626   T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    627                        dependencies=DepFN)                     
     626  T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     627               dependencies=DepFN) 
     628  T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     629               dependencies=DepFN)                     
    628630                       
    629631  if T1 == T2:
     
    634636  # Test basic wildcard dependency
    635637  #
    636   T3 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    637                        dependencies=DepFN_wildcard)                     
     638  T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     639               dependencies=DepFN_wildcard)                     
    638640   
    639641  if T1 == T3:
     
    650652  Depfile.close()
    651653 
    652   T3 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    653                        dependencies=DepFN, test = 1)                     
     654  T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     655               dependencies=DepFN, test = 1)                     
    654656 
    655657  if T3 is None:
     
    660662  # Test recomputation when dependencies have changed
    661663  #
    662   T3 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
    663                        dependencies=DepFN)                       
     664  T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, \
     665               dependencies=DepFN)                       
    664666  if T1 == T3:
    665667    test_OK('Recomputed value with changed dependencies')
     
    675677  N = 20*N   #Should be large on fast computers...
    676678  tt = time.time()
    677   T1 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose)
     679  T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose)
    678680  t1 = time.time() - tt
    679681 
    680682  tt = time.time()
    681   T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose)
     683  T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose)
    682684  t2 = time.time() - tt
    683685 
     
    706708  print_header_box('Show sample output of the caching function:')
    707709 
    708   T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=0)
    709   T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=0)
    710   T2 = caching.cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=1)
     710  T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=0)
     711  T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=0)
     712  T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=1)
    711713 
    712714  print_header_box('Show sample output of cachestat():')
     
    719721      cachestat()
    720722    except: 
    721       print 'caching.cachestat() does not work here, because it'
     723      print 'cachestat() does not work here, because it'
    722724      print 'relies on time.strptime() which is unavailable in Windows'
    723725     
     
    763765              'Bytecode has changed',
    764766              'Recomputation was requested by caller',
    765               'Cached file was unreadable']             
     767              'Cached file was unreadable']             
    766768             
    767769# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
    982984        A = raw_input('Delete (Y/N)[N] ?')
    983985      else:
    984         A = 'Y' 
    985        
     986        A = 'Y' 
     987       
    986988      if A == 'Y' or A == 'y':
    987989        for file_name in file_names:
     
    12261228        #raise Exception
    12271229        reason = 6  # Unreadable file
    1228         return None, reason 
     1230        return None, reason 
    12291231     
    12301232     
     
    12381240        #Catch e.g., file with 0 length or corrupted
    12391241        reason = 6  # Unreadable file
    1240         return None, reason
     1242        return None, reason
    12411243     
    12421244  except MemoryError:
     
    18161818            str(round(loadtime,4)) +\
    18171819            CR
    1818            
     1820           
    18191821    statfile.write(entry)
    18201822    statfile.close()
     
    18991901        if len(record) == 9:
    19001902          timestamp = record[0]
    1901        
    1902           try:
     1903       
     1904          try:
    19031905            t = mktime(strptime(timestamp))
    1904           except:
    1905             total_discarded = total_discarded + 1        
    1906             continue   
    1907              
     1906          except:
     1907            total_discarded = total_discarded + 1        
     1908            continue   
     1909             
    19081910          if t > lastday:
    19091911            lastday = t
Note: See TracChangeset for help on using the changeset viewer.