source: branches/numpy/anuga/caching/test_caching.py @ 6553

Last change on this file since 6553 was 6553, checked in by rwilson, 15 years ago

Merged trunk into numpy, all tests and validations work.

File size: 26.1 KB
Line 
1
2import unittest
3
4from copy import deepcopy
5       
6from anuga.caching import *
7from anuga.caching.dummy_classes_for_testing import Dummy, Dummy_memorytest
8
9import numpy as num
10
11
12# Define a test function to be cached
13#
14def f(a,b,c,N,x=0,y='abcdefg'):
15  """f(a,b,c,N)
16     Do something time consuming and produce a complex result.
17  """
18
19  import string
20
21  B = []
22  for n in range(N):
23    s = str(n+2.0/(n + 4.0))+'.a'*10
24    B.append((a,b,c,s,n,x,y))
25  return(B)
26 
27def f_numeric(A, B):
28  """Operation on numeric arrays
29  """
30 
31  return 3.1*A + B + 1
32 
33 
34def f_object(A, B):
35  """Operation of objecs of class Dummy
36  """
37 
38  return A.value+B.value, A.another+B.another
39 
40
41def f_generic(A):
42  return A
43 
44def clear_and_create_cache(Dummy, verbose=False):
45
46  a = cache(Dummy, 'clear', verbose=verbose)
47  a = cache(Dummy, args=(9,10),
48            verbose=verbose)
49     
50
51def retrieve_cache(Dummy, verbose=False):
52  if verbose: print 'Check that cache is there'
53 
54  X = cache(Dummy, args=(9,10), test=1,
55            verbose=verbose)     
56           
57  msg = 'Cached value was not found'
58  assert X is not None, msg
59
60     
61
62   
63
64class Test_Caching(unittest.TestCase):
65    def setUp(self):
66        set_option('verbose', 0)  #Why
67
68        pass
69
70    def tearDown(self):
71        pass
72
73    def test_simple(self):
74        """Check set_option (and switch stats off)
75        """
76
77        set_option('savestat', 0)
78        assert options['savestat'] == 0
79        set_option('verbose', 0)
80        assert options['verbose'] == 0       
81       
82
83    def test_basic_caching(self):
84
85        verbose=False
86        # Make some test input arguments
87        #
88        N = 5000  #Make N fairly small here
89
90        a = [1,2]
91        b = ('Thou shalt count the number three',4)
92        c = {'Five is right out': 6, (7,8): 9}
93        x = 3
94        y = 'holy hand granate'
95
96        # Test caching
97        #
98
99        comprange = 2
100
101        for comp in range(comprange):
102 
103            # Evaluate and store
104            #
105            T1 = cache(f, (a,b,c,N), {'x':x, 'y':y}, evaluate=1, \
106                       compression=comp, verbose=verbose)
107
108            # Retrieve
109            #                           
110            T2 = cache(f, (a,b,c,N), {'x':x, 'y':y}, compression=comp) 
111
112            # Reference result
113            #   
114            T3 = f(a,b,c,N,x=x,y=y)  # Compute without caching
115
116
117            assert T1 == T2, 'Cached result does not match computed result'
118            assert T2 == T3, 'Cached result does not match computed result'
119           
120
121           
122    def test_caching_of_numeric_arrays(self):
123        """test_caching_of_numeric_arrays
124       
125        Test that numeric arrays can be recognised by caching even if their id's are different
126        """
127       
128        verbose = False
129       
130        # Make some test input arguments
131        A0 = num.arange(5)
132        B0 = num.array([1.1, 2.2, 0.0, -5, -5])
133       
134        A1 = A0.copy()
135        B1 = B0.copy()
136       
137        # Check that their ids are different
138        assert id(A0) != id(A1)
139        assert id(B0) != id(B1)       
140       
141       
142        # Test caching
143        comprange = 2
144        for comp in range(comprange):
145 
146            # Evaluate and store
147            T1 = cache(f_numeric, (A0, B0), evaluate=1,
148                       compression=comp, verbose=verbose)
149
150            # Retrieve
151            T2 = cache(f_numeric, (A1, B1), 
152                       compression=comp, test=1, verbose=verbose) 
153                       
154            # Check for presence of cached result
155            msg = 'Different array objects with same contents were not recognised'           
156            assert T2 is not None, msg
157
158            # Reference result
159            T3 = f_numeric(A0, B0) # Compute without caching
160
161
162            assert num.alltrue(T1 == T2), 'Cached result does not match computed result'
163            assert num.alltrue(T2 == T3), 'Cached result does not match computed result'
164           
165
166    def test_hash_collision(self):
167        """Test that hash collisons are dealt with correctly"""
168       
169        verbose = False
170       
171        # Make test input arguments
172        A0 = num.arange(5)*1.0
173        B = ('x', 15)
174       
175        # Create different A that hashes to the same address (having the same average)
176        A1 = num.array([2.0, 2.0, 2.0, 2.0, 2.0])       
177       
178        assert myhash(A0) == myhash(A1)
179           
180           
181        # Test caching
182        comprange = 2
183        for comp in range(comprange):
184       
185            # Clear
186            cache(f_numeric, (A0, A0), clear=1,
187                  compression=comp, verbose=verbose)       
188            cache(f_numeric, (A1, A1), clear=1,
189                  compression=comp, verbose=verbose)                         
190 
191 
192            # Evaluate and store
193            T1 = cache(f_numeric, (A0, A0), evaluate=1,
194                       compression=comp, verbose=verbose)
195
196           
197            # Check that A1 doesn't trigger retrieval of the previous result
198            # even though it hashes to the same address
199            T2 = cache(f_numeric, (A1, A1), 
200                       compression=comp, verbose=verbose) 
201           
202            T1_ref = f_numeric(A0, A0)
203            T2_ref = f_numeric(A1, A1)
204
205            assert num.alltrue(T1 == T1_ref)
206            assert num.alltrue(T2 == T2_ref)
207
208
209    def test_caching_of_dictionaries(self):
210        """test_caching_of_dictionaries
211       
212        Real example from ANUGA that caused some
213        hashing problems
214        """
215   
216
217        verbose = False #True
218       
219        D = {'point_attributes': None, 
220             'use_cache': True, 
221             'vertex_coordinates': None, 
222             'verbose': True, 
223             'max_read_lines': 500, 
224             'acceptable_overshoot': 1.01, 
225             'mesh': None, 
226             'data_origin': None, 
227             'alpha': 0.02, 
228             'mesh_origin': None, 
229             'attribute_name': None, 
230             'triangles': None}         
231       
232        DD = deepcopy(D) # Mangles the dictionary ordering
233       
234        assert myhash(DD) == myhash(D)
235
236        # Also test caching now that we are at it
237        comprange = 2
238        for comp in range(comprange):
239 
240            # Evaluate and store using D
241            T1 = cache(f_generic, D, evaluate=1,
242                       compression=comp, verbose=verbose)
243
244            # Retrieve using copy (DD)
245            T2 = cache(f_generic, DD, 
246                       compression=comp, test=1, verbose=verbose) 
247                       
248            # Check for presence of cached result
249            msg = 'Cached object was not found'           
250            assert T2 is not None, msg
251
252            # Reference result
253            T3 = f_generic(D) # Compute without caching
254
255           
256            msg = 'Cached result does not match computed result' 
257           
258            # Compare dictionaries
259            for key in T1:
260                assert T1[key] == T2[key]
261                assert T2[key] == T3[key]               
262               
263           
264           
265           
266
267    def test_caching_of_objects(self):
268        """test_caching_of_objects
269       
270        Test that Objecs can be recognised as input variabelse
271        by caching even if their id's are different
272        """
273   
274
275        verbose = False
276       
277        # Make some test input arguments
278        A0 = Dummy(5, 7)
279        B0 = Dummy(2.2, -5)
280       
281        A0.new_attribute = 'x' 
282        B0.new_attribute = 'x'       
283       
284        A1 = deepcopy(A0)
285        B1 = deepcopy(B0)       
286       
287        # Check that their ids are different
288        assert id(A0) != id(A1)
289        assert id(B0) != id(B1)       
290       
291       
292        # Test caching
293        comprange = 2
294        for comp in range(comprange):
295 
296            # Evaluate and store
297            T1 = cache(f_object, (A0, B0), evaluate=1,
298                       compression=comp, verbose=verbose)
299
300            # Retrieve
301            T2 = cache(f_object, (A1, B1), 
302                       compression=comp, 
303                       test=1, 
304                       verbose=verbose) 
305                       
306            # Check for presence of cached result
307            msg = 'Different objects with same attributes were not recognised'
308            assert T2 is not None, msg
309
310            # Reference result
311            T3 = f_object(A0, B0) # Compute without caching
312
313
314            assert T1 == T2, 'Cached result does not match computed result'
315            assert T2 == T3, 'Cached result does not match computed result'
316           
317
318    def test_caching_of_circular_structures(self):
319        """test_caching_of_circular_structures
320       
321        Test that Caching doesn't recurse infinitely in case of
322        circular or self-referencing structures
323        """
324       
325        verbose = False
326       
327        # Create input argument
328        A = Dummy(5, 7)
329        B = {'x': 10, 'A': A}
330        C = [B, 15]
331        A.value = C # Make it circular
332        A.x = [1,2,C,5,A] # More circular and self referential
333       
334        AA = deepcopy(A)
335
336        # Test caching
337        comprange = 2
338        for comp in range(comprange):
339 
340            # Evaluate and store
341            T1 = cache(f_generic, A, 
342                       evaluate=1,
343                       compression=comp, verbose=verbose)
344
345            # Retrieve
346            T2 = cache(f_generic, AA, 
347                       compression=comp, 
348                       test=1, verbose=verbose) 
349                       
350            # Check for presence of cached result
351            msg = 'Cached object was not found'           
352            assert T2 is not None, msg
353
354            # Reference result
355            T3 = f_generic(A) # Compute without caching
356
357           
358            msg = 'Cached result does not match computed result' 
359            assert str(T1) == str(T2), msg
360            assert str(T2) == str(T3), msg
361                                   
362           
363    def test_caching_of_callable_objects(self):
364        """test_caching_of_callable_objects(self)
365       
366        Test that caching will discern between calls of
367        two different instances of a callable object with the same input.
368       
369        This cause problems with add_quantity in ANUGA in changeset:6225
370        where a previous instance of Polygon_function was picked up.
371        """
372
373        class call:
374       
375          def __init__(self, a, b):
376            self.a = a
377            self.b = b
378           
379          def __call__(self, x):
380            return self.a*x + self.b
381
382           
383        f1 = call(2, 3)
384        f2 = call(5, 7)
385
386
387        # Check that hash value of callable objects don't change
388        # FIXME (Ole): The hash values do appear to change when OS
389        # and/or dependencies are upgraded
390        if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']:
391          # 64 bit hash values
392          f1hash = 1914027059797211698
393          f2hash = 1914027059807087171
394        else:
395          f1hash = -758136387
396          f2hash = -11221564     
397         
398        assert myhash(f1) == f1hash
399        assert myhash(f2) == f2hash
400       
401        bc1 = get_bytecode(f1)
402        bc2 = get_bytecode(f2)
403       
404        #print 'bc1', bc1
405        #print 'bc2', bc2
406       
407        msg = 'Byte code should be different'
408        assert bc1 != bc2, msg
409
410       
411        x = num.arange(10).astype(num.float)
412       
413        ref1 = f1(x)
414        ref2 = f2(x)
415
416        # Clear cache for f1(x) and f2(x) and verify that all is clear
417        cache(f1, x, clear=True, verbose=False)
418        flag = cache(f1, x, test=True, verbose=False)       
419        assert flag is None
420       
421        cache(f2, x, clear=True, verbose=False)
422        flag = cache(f2, x, test=True, verbose=False)       
423        assert flag is None       
424       
425        # Run f1(x) and cache
426        res1 = cache(f1, x, verbose=False)
427        assert num.allclose(res1, ref1)       
428       
429        # Test that f1(x) has been cached correctly
430        res1 = cache(f1, x, test=True, verbose=False)               
431        assert num.allclose(res1, ref1)               
432       
433        # Test that f2(x) is still clear
434        cache(f2, x, clear=True, verbose=False)
435        flag = cache(f2, x, test=True, verbose=False)       
436        assert flag is None               
437       
438        # Run f2(x) and test result
439        res2 = cache(f2, x, verbose=False)
440        msg = 'Wrong result for f2(x)'
441        assert num.allclose(res2, ref2), msg
442       
443
444       
445       
446    def test_uniqueness_of_hash_values(self):
447        """test_uniqueness_of_hash_values(self):
448       
449        Test that Caching can handle a realistic
450        complex structure by hashing it consistently and
451        uniquely.
452        """
453       
454        verbose = False
455       
456        # Create input argument
457        A = Dummy(5, 7)
458        B = {'x': 10, 'A': A}
459        C = [B, num.array([1.2, 3, 5, 0.1])]
460        A.value = C # Make it circular
461
462        # Create identical but separate object   
463        AA = Dummy(None, None)
464        BB = {'A': AA, 'x': 10}
465        CC = [BB, num.array([1.200, 3.000, 5.00, 1.0/10])]
466        AA.value = CC # Make it circular
467        AA.another = 3+4       
468       
469       
470        assert myhash(A) == myhash(AA)     
471           
472           
473       
474        # Also test caching now that we are at it
475        comprange = 2
476        for comp in range(comprange):
477 
478            # Evaluate and store using A
479            T1 = cache(f_generic, A, evaluate=1,
480                       compression=comp, verbose=verbose)
481
482            # Retrieve using copy (AA)
483            T2 = cache(f_generic, AA, 
484                       compression=comp, test=1, verbose=verbose) 
485                       
486            # Check for presence of cached result
487            msg = 'Cached object was not found'           
488            assert T2 is not None, msg
489
490            # Reference result
491            T3 = f_generic(A) # Compute without caching
492
493           
494            msg = 'Cached result does not match computed result' 
495            assert str(T1) == str(T2), msg
496            assert str(T2) == str(T3), msg
497           
498           
499
500    def test_caching_of_simple_circular_dictionaries(self):
501        """test_caching_of_circular_structures
502       
503        Test that Caching doesn't recurse infinitely in case of
504        circular or self-referencing structures
505        """
506       
507        verbose = False #True
508       
509        # Create input argument
510        A = {'x': 10, 'B': None}
511        B = [A, 15]
512        A['B'] = B # Make it circular
513       
514        # Test caching
515        comprange = 2
516        for comp in range(comprange):
517 
518            # Evaluate and store
519            T1 = cache(f_generic, A, evaluate=1,
520                       compression=comp, verbose=verbose)
521                       
522
523            # Retrieve
524            T2 = cache(f_generic, A, 
525                       compression=comp, test=1, verbose=verbose) 
526                       
527            # Check for presence of cached result
528            msg = 'Cached object was not found'           
529            assert T2 is not None, msg
530
531            # Reference result
532            T3 = f_generic(A) # Compute without caching
533
534
535            msg = 'Cached result does not match computed result'
536            assert str(T1) == str(T2), msg
537            assert str(T2) == str(T3), msg
538
539           
540           
541    def test_cachefiles(self):
542        """Test existence of cachefiles
543        """       
544        N = 5000  #Make N fairly small here
545
546        a = [1,2]
547        b = ('Thou shalt count the number three',4)
548        c = {'Five is right out': 6, (7,8): 9}
549        x = 3
550        y = 'holy hand granate'
551
552       
553        FN = cache(f,(a,b,c,N), {'x':x, 'y':y}, verbose=0, \
554                  return_filename = 1)
555
556
557        assert FN[:2] == 'f['
558
559        CD = checkdir(cachedir)
560        compression = 1
561
562        (datafile,compressed0) = myopen(CD+FN+'_'+file_types[0],"rb",compression)
563        (argsfile,compressed1) = myopen(CD+FN+'_'+file_types[1],"rb",compression)
564        (admfile,compressed2) =  myopen(CD+FN+'_'+file_types[2],"rb",compression)
565
566        datafile.close()
567        argsfile.close()
568        admfile.close()
569
570    def test_test(self):       
571        """Test 'test' function when cache is present
572        """
573       
574        verbose = False
575       
576        N = 5 
577
578        a = [1,2]
579        b = ('Thou shalt count the number three',4)
580        c = {'Five is right out': 6, (7,8): 9}
581        x = 3
582        y = 'holy hand granate'
583       
584
585        T1 = cache(f, (a,b,c,N), {'x':x, 'y':y}, 
586                   evaluate=1, 
587                   verbose=verbose)
588       
589        T2 = cache(f, (a,b,c,N), {'x':x, 'y':y}, 
590                   test=1,
591                   verbose=verbose)
592                   
593                   
594        # Check for presence of cached result
595        msg = 'Different objects with same attributes were not recognised'
596        assert T2 is not None, msg                   
597                   
598        assert T1 == T2, "Option 'test' when cache file present failed"     
599
600
601    def test_clear(self):       
602        """Test that 'clear' works
603        """
604
605        N = 5000  #Make N fairly small here
606
607        a = [1,2]
608        b = ('Thou shalt count the number three',4)
609        c = {'Five is right out': 6, (7,8): 9}
610        x = 3
611        y = 'holy hand granate'
612       
613
614        T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, evaluate = 1)
615       
616       
617        cache(f, (a,b,c,N), {'x':x, 'y':y}, clear = 1)   
618
619 
620        # Test 'test' function when cache is absent
621       
622       
623        T4 = cache(f, (a,b,c,N), {'x':x, 'y':y}, test=1)
624        #print 'T4', T4
625        assert T4 is None, "Option 'test' when cache absent failed"
626
627
628    def test_dependencies(self):
629       
630        # Make a dependency file
631        CD = checkdir(cachedir)       
632
633        DepFN = CD + 'testfile.tmp'
634        DepFN_wildcard = CD + 'test*.tmp'
635        Depfile = open(DepFN,'w')
636        Depfile.write('We are the knights who say NI!')
637        Depfile.close()
638
639       
640        # Test
641        #
642
643        N = 5000  #Make N fairly small here
644
645        a = [1,2]
646        b = ('Thou shalt count the number three',4)
647        c = {'Five is right out': 6, (7,8): 9}
648        x = 3
649        y = 'holy hand granate'
650       
651        T1 = cache(f,(a,b,c,N), {'x':x, 'y':y}, dependencies=DepFN) 
652        T2 = cache(f,(a,b,c,N), {'x':x, 'y':y}, dependencies=DepFN)                     
653                       
654        assert T1 == T2, 'Dependencies do not work'
655
656
657        # Test basic wildcard dependency
658        T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, dependencies=DepFN_wildcard)                     
659   
660        assert T1 == T3, 'Dependencies with wildcards do not work'
661
662
663        # Test that changed timestamp in dependencies triggers recomputation
664 
665        # Modify dependency file
666        Depfile = open(DepFN,'a')
667        Depfile.write('You must cut down the mightiest tree in the forest with a Herring')
668        Depfile.close()
669 
670        T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, dependencies=DepFN, test = 1)
671       
672        assert T3 is None, 'Changed dependencies not recognised'
673 
674        # Test recomputation when dependencies have changed
675        #
676        T3 = cache(f,(a,b,c,N), {'x':x, 'y':y}, dependencies=DepFN)                       
677        assert T1 == T3, 'Recomputed value with changed dependencies failed'
678
679    #def test_performance(self):       
680    #    """Performance test (with statistics)
681    #    Don't really rely on this as it will depend on specific computer.
682    #    """
683    #
684    #    import time
685    #    set_option('savestat', 1)
686    #
687    #    N = 300000   #Should be large on fast computers...
688    #    a = [1,2]
689    #    b = ('Thou shalt count the number three',4)
690    #    c = {'Five is right out': 6, (7,8): 9}
691    #    x = 3
692    #    y = 'holy hand granate'
693    #     
694    #   
695    #    tt = time.time()
696    #    T1 = cache(f,(a,b,c,N), {'x':x, 'y':y})
697    #    t1 = time.time() - tt
698    #
699    #    tt = time.time()
700    #    T2 = cache(f,(a,b,c,N), {'x':x, 'y':y})
701    #    t2 = time.time() - tt
702     
703    #    assert T1 == T2
704    #     assert t1 > t2, 'WARNING: Performance a bit low - this could be specific to current platform. Try to increase N in this test'
705    #    #test_OK('Performance test: relative time saved = %s pct' \
706    #    #        %str(round((t1-t2)*100/t1,2)))
707
708
709    def test_statsfile(self):                   
710        """Test presence of statistics file
711        """
712        import os, string
713        statsfile  = '.cache_stat'  # Basefilename for cached statistics.
714       
715        CD = checkdir(cachedir)               
716        DIRLIST = os.listdir(CD)
717        SF = []
718        for FN in DIRLIST:
719            if string.find(FN,statsfile) >= 0:
720                try:
721                    fid = open(CD+FN,'r')
722                    fid.close()
723                except:
724                    raise 'Statistics files cannot be opened'         
725 
726         
727
728    # def test_network_cachedir(self):
729
730#         #set_option('cachedir', 'H:\\.python_cache\\')
731#         set_option('cachedir', 'V:\\2\\cit\\.python_cache\\')
732#         set_option('verbose', 1)
733
734       
735#         # Make some test input arguments
736#         #
737#         N = 5000  #Make N fairly small here
738
739#         a = [1,2]
740#         b = ('Thou shalt count the number three',4)
741#         c = {'Five is right out': 6, (7,8): 9}
742#         x = 3
743#         y = 'holy hand granate'
744
745#         # Test caching
746#         #
747
748#         comprange = 2
749
750#         for comp in range(comprange):
751 
752#             # Evaluate and store
753#             #
754#             T1 = cache(f, (a,b,c,N), {'x':x, 'y':y}, evaluate=1, \
755#                        compression=comp)
756
757#             # Retrieve
758#             #                           
759#             T2 = cache(f, (a,b,c,N), {'x':x, 'y':y}, compression=comp)
760
761#             # Reference result
762#             #   
763#             T3 = f(a,b,c,N,x=x,y=y)  # Compute without caching
764
765
766#             assert T1 == T2, 'Cached result does not match computed result'
767#             assert T2 == T3, 'Cached result does not match computed result'
768             
769
770
771    def Will_fail_test_objects(self):
772      """
773      This test shows how instances can't be effectively cached.
774      myhash uses hash which uses id which uses the memory address.
775     
776      This will be a NIL problem once caching can handle instances with different id's and
777      identical content.
778     
779      The test is disabled.
780      """
781     
782
783     
784      verbose = True
785      #verbose = False
786
787      for i in range(2):
788        if verbose: print "clear cache"
789        a = cache(Dummy, 'clear')
790       
791        if verbose: print "cache for first time"
792        a = cache(Dummy, args=(9,10), verbose=verbose)
793        hash_value = myhash(a)
794       
795        #print "hash_value",hash_value
796        if verbose: print "cache for second time"
797        a = cache(Dummy, args=(9,10), verbose=verbose)
798       
799        #print "myhash(a)",myhash(a)
800        assert hash_value == myhash(a)
801
802
803    # This test works in the caching dir and in anuga_core, but not in the
804    # anuga_core/source/anuga dir
805    # This has to do with pickle (see e.g. http://telin.ugent.be/~slippens/drupal/pickleproblem)
806    # The error message is
807    # PicklingError: Can't pickle test_caching.Dummy: it's not the same object as test_caching.Dummy
808    #
809    # This problem was fixed by moving the class into the separate module
810   
811    def test_objects_are_created(self):
812      """
813      This test shows how instances can be created from cache
814      as long as input arguments are unchanged.
815
816      Such instances will have different id's and cannot be currently be used as input
817      arguments in subsequent caches. However, this is still useful.
818
819      Do it for all combinations of compression
820
821      """
822
823      verbose = False
824     
825      for compression_store in [False, True]:
826        for compression_retrieve in [False, True]:       
827       
828          if verbose: print 'clear cache'
829          a = cache(Dummy, 'clear')
830       
831          if verbose: print 'cache for first time'
832          a_ref = cache(Dummy, args=(9,10),
833                        compression=compression_store,
834                        verbose=verbose)
835         
836          if verbose: print 'Check that cache is there'
837          assert cache(Dummy, args=(9,10), test=1,
838                       compression=compression_retrieve,
839                       verbose=verbose)
840                       
841          if verbose: print 'Check cached result'
842          a = cache(Dummy, args=(9,10),
843                    compression=compression_store,
844                    verbose=verbose)                       
845          assert a.__dict__ == a_ref.__dict__
846
847
848
849    # NOTE (Ole): This test has been commented out because,
850    #             although the test will pass (not anymore!)
851    #             inside the caching dir and also at the anuga_core level,
852    #             it won't pass at the anuga_core/source/anuga level.
853    # It may have to do with the comments above.
854    #
855    # But this is a very nice test to run occasionally within the caching
856    # area
857    def Xtest_objects_are_created_memory(self):
858      """
859     
860      This test shows how instances can be created from cache
861      as long as input arguments are unchanged - even if the class
862      lives in different memory locations.
863
864      This is using cache created in the main program below
865      """
866
867      verbose = True #False
868
869      # Redefine class Dummy_memorytest
870      class Dummy_memorytest:
871        def __init__(self, value, another):
872          self.value = value     
873
874      # Make sure that class has been redefined to another address
875      print
876      print 'Initial_addr  ', initial_addr
877      print 'Redefined addr', `Dummy_memorytest`
878      msg = 'Redefined class ended up at same memory location as '
879      msg += 'original class making this test irrelevant. Try to run '
880      msg += 'it again and see if this error goes away.'
881      msg += 'If it persists contact Ole.Nielsen@ga.gov.au'
882      assert initial_addr != `Dummy_memorytest`, msg   
883
884     
885      retrieve_cache(Dummy_memorytest, verbose=verbose)     
886         
887# Cache created for use with 'test_objects_are_created_memory'
888#initial_addr = `Dummy_memorytest`
889#clear_and_create_cache(Dummy_memorytest, verbose=False)
890 
891
892
893#-------------------------------------------------------------
894if __name__ == "__main__":
895    suite = unittest.makeSuite(Test_Caching, 'test')
896    runner = unittest.TextTestRunner()
897    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.