Changeset 4333
- Timestamp:
- Mar 28, 2007, 5:11:05 PM (17 years ago)
- Location:
- anuga_core/source/anuga/caching
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/caching/caching.py
r4279 r4333 1454 1454 funcname = string.join(tmp) 1455 1455 1456 # Truncate memory address as in 1457 # class __main__.Dummy at 0x00A915D0 1458 index = funcname.find('at 0x') 1459 if index >= 0: 1460 funcname = funcname[:index+5] # Keep info that there is an address 1461 1456 1462 funcname = nospace(funcname) 1457 1463 return(funcname) -
anuga_core/source/anuga/caching/test_caching.py
r4272 r4333 21 21 22 22 class Dummy: 23 def __init__(self, value, another):23 def __init__(self, value, another): 24 24 self.value = value 25 26 27 class Dummy_memorytest: 28 def __init__(self, value, another): 29 self.value = value 30 31 32 def clear_and_create_cache(Dummy, verbose=False): 33 a = cache(Dummy, 'clear', verbose=verbose) 34 35 a = cache(Dummy, args=(9,10), 36 verbose=verbose) 37 38 39 def retrieve_cache(Dummy, verbose=False): 40 if verbose: print 'Check that cache is there' 41 assert cache(Dummy, args=(9,10), test=1, 42 verbose=verbose) 43 44 45 25 46 26 47 class Test_Caching(unittest.TestCase): 27 48 def setUp(self): 28 49 set_option('verbose', 0) #Why 29 50 30 51 pass 31 52 … … 45 66 def test_basic_caching(self): 46 67 47 68 verbose=False 48 69 # Make some test input arguments 49 70 # … … 66 87 # 67 88 T1 = cache(f, (a,b,c,N), {'x':x, 'y':y}, evaluate=1, \ 68 compression=comp )89 compression=comp, verbose=verbose) 69 90 70 91 # Retrieve … … 304 325 """ 305 326 verbose = True 306 verbose = False327 #verbose = False 307 328 308 329 for i in range(2): 309 330 if verbose: print "clear cache" 310 a = cache(Dummy,'clear') 331 a = cache(Dummy, 'clear') 332 311 333 if verbose: print "cache for first time" 312 a = cache(Dummy, args=(9,10) ,verbose=verbose)334 a = cache(Dummy, args=(9,10), verbose=verbose) 313 335 hash_value = myhash(a) 336 314 337 #print "hash_value",hash_value 315 338 if verbose: print "cache for second time" 316 a = cache(Dummy,args=(9,10) ,verbose=verbose) 339 a = cache(Dummy, args=(9,10), verbose=verbose) 340 317 341 #print "myhash(a)",myhash(a) 318 342 assert hash_value == myhash(a) 319 343 344 345 def test_objects_are_created(self): 346 """ 347 However, this test shows how instances can be created from cache 348 as long as input arguments are unchanged. 349 350 Such instances will have different id's and cannot be used as input 351 arguments in subsequent caches. However, this is still useful. 352 353 Do it for all combinations of compression 354 355 """ 356 357 verbose = False 358 359 for compression_store in [False, True]: 360 for compression_retrieve in [False, True]: 361 362 if verbose: print 'clear cache' 363 a = cache(Dummy, 'clear') 364 365 if verbose: print 'cache for first time' 366 a = cache(Dummy, args=(9,10), 367 compression=compression_store, 368 verbose=verbose) 369 370 if verbose: print 'Check that cache is there' 371 assert cache(Dummy, args=(9,10), test=1, 372 compression=compression_retrieve, 373 verbose=verbose) 374 375 376 377 378 def test_objects_are_created_memory(self): 379 """ 320 380 381 This test shows how instances can be created from cache 382 as long as input arguments are unchanged - even if the class 383 lives in different memory locations. 384 385 This is using cache created in the main program 386 387 """ 388 389 verbose = False 390 391 # Redefine class Dummy_memorytest 392 class Dummy_memorytest: 393 def __init__(self, value, another): 394 self.value = value 395 396 retrieve_cache(Dummy_memorytest, verbose=verbose) 397 398 399 400 401 321 402 322 403 … … 324 405 #------------------------------------------------------------- 325 406 if __name__ == "__main__": 407 408 # Cache created for test_objects_are_created_memory to make sure it has a different memory address 409 clear_and_create_cache(Dummy_memorytest, verbose=False) 410 326 411 suite = unittest.makeSuite(Test_Caching,'test') 327 412 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.