Changeset 4198


Ignore:
Timestamp:
Jan 30, 2007, 1:36:06 PM (17 years ago)
Author:
duncan
Message:

fix in cache. None was giving different hashes, on some linux boxes

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r4171 r4198  
    537537        os.remove(ptsfile)
    538538
     539    def Cache_cache_test_set_values_from_file(self):
     540        quantity = Quantity(self.mesh4)
     541
     542        #Get (enough) datapoints
     543        data_points = [[ 0.66666667, 0.66666667],
     544                       [ 1.33333333, 1.33333333],
     545                       [ 2.66666667, 0.66666667],
     546                       [ 0.66666667, 2.66666667],
     547                       [ 0.0, 1.0],
     548                       [ 0.0, 3.0],
     549                       [ 1.0, 0.0],
     550                       [ 1.0, 1.0],
     551                       [ 1.0, 2.0],
     552                       [ 1.0, 3.0],
     553                       [ 2.0, 1.0],
     554                       [ 3.0, 0.0],
     555                       [ 3.0, 1.0]]
     556
     557        data_geo_spatial = Geospatial_data(data_points,
     558                         geo_reference = Geo_reference(56, 0, 0))
     559        data_points_absolute = data_geo_spatial.get_data_points(absolute=True)
     560        attributes = linear_function(data_points_absolute)
     561        att = 'spam_and_eggs'
     562       
     563        #Create .txt file
     564        ptsfile = tempfile.mktemp(".txt")
     565        file = open(ptsfile,"w")
     566        file.write(" x,y," + att + " \n")
     567        for data_point, attribute in map(None, data_points_absolute
     568                                         ,attributes):
     569            row = str(data_point[0]) + ',' + str(data_point[1]) \
     570                  + ',' + str(attribute)
     571            file.write(row + "\n")
     572        file.close()
     573
     574
     575        #Check that values can be set from file
     576        quantity.set_values(filename = ptsfile,
     577                            attribute_name = att, alpha = 0, use_cache=True,
     578                            verbose=True)
     579        answer = linear_function(quantity.domain.get_vertex_coordinates())
     580
     581        #print quantity.vertex_values.flat
     582        #print answer
     583
     584
     585        assert allclose(quantity.vertex_values.flat, answer)
     586
     587
     588        #Check that values can be set from file using default attribute
     589        quantity.set_values(filename = ptsfile, alpha = 0)
     590        assert allclose(quantity.vertex_values.flat, answer)
     591
     592        #checking cache
     593        #quantity.set_values(filename = ptsfile,
     594         #                   attribute_name = att, alpha = 0, use_cache=True,
     595          #                  verbose=True)
     596        #Cleanup
     597        import os
     598        os.remove(ptsfile)
    539599
    540600    def test_set_values_from_file_with_georef1(self):
     
    17021762if __name__ == "__main__":
    17031763    suite = unittest.makeSuite(Test_Quantity, 'test')
     1764
     1765    #suite = unittest.makeSuite(Test_Quantity, 'Cache_cache_test_set_values_from_file')
    17041766    #print "restricted test"
    17051767    #suite = unittest.makeSuite(Test_Quantity,'test_set_values_from_file_with_georef2')
  • anuga_core/source/anuga/caching/caching.py

    r3715 r4198  
    13231323  import types
    13241324
     1325  # On some architectures None gets different hash values
     1326  if T is None:
     1327    return(1)
     1328
    13251329  # Get hash vals for hashable entries
    13261330  #
     
    13691373  for k in range(len(keys)):
    13701374    try:
    1371       h = hash(D[keys[k]])
     1375      h = myhash(D[keys[k]])
    13721376      hvals.append(h)
    13731377    except:
Note: See TracChangeset for help on using the changeset viewer.