Changeset 9489
- Timestamp:
- Jan 22, 2015, 4:22:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/caching/caching.py
r8820 r9489 463 463 set_option('compression', compression) 464 464 except: 465 test_error('Set option failed')465 log_test_error('Set option failed') 466 466 467 467 try: … … 505 505 Depfile.write('We are the knights who say NI!') 506 506 Depfile.close() 507 test_OK('Wrote file %s' %DepFN)507 log_test_OK('Wrote file %s' %DepFN) 508 508 except: 509 test_error('Could not open file %s for writing - check your environment' \509 log_test_error('Could not open file %s for writing - check your environment' \ 510 510 % DepFN) 511 511 … … 515 515 set_option('savestat',0) 516 516 assert(options['savestat'] == 0) 517 test_OK('Set option')517 log_test_OK('Set option') 518 518 except: 519 test_error('Set option failed')519 log_test_error('Set option failed') 520 520 521 521 # Make some test input arguments … … 544 544 verbose=verbose, compression=comp) 545 545 if comp: 546 test_OK('Caching evaluation with compression')546 log_test_OK('Caching evaluation with compression') 547 547 else: 548 test_OK('Caching evaluation without compression')548 log_test_OK('Caching evaluation without compression') 549 549 except: 550 550 if comp: 551 test_error('Caching evaluation with compression failed - try caching.test(compression=0)')551 log_test_error('Caching evaluation with compression failed - try caching.test(compression=0)') 552 552 else: 553 test_error('Caching evaluation failed - try caching.test(verbose=1)')553 log_test_error('Caching evaluation failed - try caching.test(verbose=1)') 554 554 555 555 # Retrieve … … 560 560 561 561 if comp: 562 test_OK('Caching retrieval with compression')562 log_test_OK('Caching retrieval with compression') 563 563 else: 564 test_OK('Caching retrieval without compression')564 log_test_OK('Caching retrieval without compression') 565 565 except: 566 566 if comp: 567 test_error('Caching retrieval with compression failed - try caching.test(compression=0)')567 log_test_error('Caching retrieval with compression failed - try caching.test(compression=0)') 568 568 else: 569 test_error('Caching retrieval failed - try caching.test(verbose=1)')569 log_test_error('Caching retrieval failed - try caching.test(verbose=1)') 570 570 571 571 # Reference result … … 575 575 if T1 == T2 and T2 == T3: 576 576 if comp: 577 test_OK('Basic caching functionality (with compression)')577 log_test_OK('Basic caching functionality (with compression)') 578 578 else: 579 test_OK('Basic caching functionality (without compression)')579 log_test_OK('Basic caching functionality (without compression)') 580 580 else: 581 test_error('Cached result does not match computed result')581 log_test_error('Cached result does not match computed result') 582 582 583 583 … … 588 588 return_filename=1) 589 589 assert(FN[:2] == 'f[') 590 test_OK('Return of cache filename')590 log_test_OK('Return of cache filename') 591 591 except: 592 test_error('Return of cache filename failed')592 log_test_error('Return of cache filename failed') 593 593 594 594 # Test existence of cachefiles … … 598 598 (argsfile,compressed1) = myopen(CD+FN+'_'+file_types[1],"rb",compression) 599 599 (admfile,compressed2) = myopen(CD+FN+'_'+file_types[2],"rb",compression) 600 test_OK('Presence of cache files')600 log_test_OK('Presence of cache files') 601 601 datafile.close() 602 602 argsfile.close() 603 603 admfile.close() 604 604 except: 605 test_error('Expected cache files did not exist')605 log_test_error('Expected cache files did not exist') 606 606 607 607 # Test 'test' function when cache is present … … 613 613 assert(T1 == T4) 614 614 615 test_OK("Option 'test' when cache file present")615 log_test_OK("Option 'test' when cache file present") 616 616 except: 617 test_error("Option 'test' when cache file present failed")617 log_test_error("Option 'test' when cache file present failed") 618 618 619 619 # Test that 'clear' works … … 621 621 #try: 622 622 # cache(f,'clear',verbose=verbose) 623 # test_OK('Clearing of cache files')623 # log_test_OK('Clearing of cache files') 624 624 #except: 625 # test_error('Clear does not work')625 # log_test_error('Clear does not work') 626 626 try: 627 627 cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, clear=1) 628 test_OK('Clearing of cache files')628 log_test_OK('Clearing of cache files') 629 629 except: 630 test_error('Clear does not work')630 log_test_error('Clear does not work') 631 631 632 632 … … 637 637 T4 = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=verbose, test=1) 638 638 assert(T4 is None) 639 test_OK("Option 'test' when cache absent")639 log_test_OK("Option 'test' when cache absent") 640 640 except: 641 test_error("Option 'test' when cache absent failed")641 log_test_error("Option 'test' when cache absent failed") 642 642 643 643 # Test dependencies … … 649 649 650 650 if T1 == T2: 651 test_OK('Basic dependencies functionality')651 log_test_OK('Basic dependencies functionality') 652 652 else: 653 test_error('Dependencies do not work')653 log_test_error('Dependencies do not work') 654 654 655 655 # Test basic wildcard dependency … … 659 659 660 660 if T1 == T3: 661 test_OK('Basic dependencies with wildcard functionality')661 log_test_OK('Basic dependencies with wildcard functionality') 662 662 else: 663 test_error('Dependencies with wildcards do not work')663 log_test_error('Dependencies with wildcards do not work') 664 664 665 665 … … 675 675 676 676 if T3 is None: 677 test_OK('Changed dependencies recognised')677 log_test_OK('Changed dependencies recognised') 678 678 else: 679 test_error('Changed dependencies not recognised')679 log_test_error('Changed dependencies not recognised') 680 680 681 681 # Test recomputation when dependencies have changed … … 684 684 dependencies=DepFN) 685 685 if T1 == T3: 686 test_OK('Recomputed value with changed dependencies')686 log_test_OK('Recomputed value with changed dependencies') 687 687 else: 688 test_error('Recomputed value with changed dependencies failed')688 log_test_error('Recomputed value with changed dependencies failed') 689 689 690 690 # Performance test (with statistics) … … 705 705 if T1 == T2: 706 706 if t1 > t2: 707 test_OK('Performance test: relative time saved = %s pct' \707 log_test_OK('Performance test: relative time saved = %s pct' \ 708 708 %str(round((t1-t2)*100/t1,2))) 709 709 else: 710 test_error('Basic caching failed for new problem')710 log_test_error('Basic caching failed for new problem') 711 711 712 712 # Test presence of statistics file … … 719 719 fid = open(CD+FN,'r') 720 720 fid.close() 721 test_OK('Statistics files present')721 log_test_OK('Statistics files present') 722 722 except: 723 test_OK('Statistics files cannot be opened')723 log_test_OK('Statistics files cannot be opened') 724 724 725 725 print_header_box('Show sample output of the caching function:') … … 741 741 'time.strptime() which is unavailable in Windows') 742 742 743 test_OK('Caching self test completed')743 log_test_OK('Caching self test completed') 744 744 745 745 … … 767 767 # arguments. 768 768 textwidth3 = 16 # Initial width of separation lines. Is modified. 769 textwidth4 = 50 # Text width in test_OK()769 textwidth4 = 50 # Text width in log_test_OK() 770 770 statsfile = '.cache_stat' # Basefilename for cached statistics. 771 771 # It will reside in the chosen cache directory. … … 2495 2495 # ----------------------------------------------------------------------------- 2496 2496 2497 def test_OK(msg):2497 def log_test_OK(msg): 2498 2498 """Print OK msg if test is OK. 2499 2499 2500 2500 USAGE 2501 test_OK(message)2501 log_test_OK(message) 2502 2502 """ 2503 2503 … … 2510 2510 # ----------------------------------------------------------------------------- 2511 2511 2512 def test_error(msg):2512 def log_test_error(msg): 2513 2513 """Print error if test fails. 2514 2514 2515 2515 USAGE 2516 test_error(message)2516 log_test_error(message) 2517 2517 """ 2518 2518
Note: See TracChangeset
for help on using the changeset viewer.