Index: /anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
===================================================================
--- /anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py	(revision 5518)
+++ /anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py	(revision 5519)
@@ -403,5 +403,6 @@
     def test_set_vertex_values_using_general_interface_with_subset(self):
         """test_set_vertex_values_using_general_interface_with_subset(self):
-        Test that indices and polygon works
+        
+        Test that indices and polygon works (for constants values)
         """
         
@@ -435,5 +436,6 @@
 
 
-        # Another polygon (pick triangle 1 and 2 (rightmost triangles) using centroids
+        # Another polygon (pick triangle 1 and 2 (rightmost triangles) 
+        # using centroids
         polygon = [[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]]
         quantity.set_values(0.0)
@@ -457,5 +459,4 @@
                          [0,0,0]])                
         
-        #print 'done'
 
         # Test input checking
@@ -694,5 +695,10 @@
 
 
-    def XXXXtest_set_values_from_file_using_polygon(self):
+    def Xtest_set_values_from_file_using_polygon(self):
+        """test_set_values_from_file_using_polygon(self):
+        
+        Test that polygon restriction works for general points data
+        """
+        
         quantity = Quantity(self.mesh4)
 
@@ -729,5 +735,6 @@
         file.close()
 
-        # Create restricting polygon (containing vertex #4 (2,2) or centroid of triangle #1 (bce)
+        # Create restricting polygon (containing node #4 (2,2) and 
+        # centroid of triangle #1 (bce)
         polygon = [[1.0, 1.0], [4.0, 1.0],
                    [4.0, 4.0], [1.0, 4.0]]
@@ -747,5 +754,6 @@
 
         # Get indices for vertex coordinates in polygon
-        indices = inside_polygon(quantity.domain.get_vertex_coordinates(), polygon)
+        indices = inside_polygon(quantity.domain.get_vertex_coordinates(), 
+                                 polygon)
         points = take(quantity.domain.get_vertex_coordinates(), indices)
         
@@ -760,5 +768,6 @@
 
         # Check vertices outside polygon are zero
-        indices = outside_polygon(quantity.domain.get_vertex_coordinates(), polygon)        
+        indices = outside_polygon(quantity.domain.get_vertex_coordinates(), 
+                                  polygon)        
         assert allclose(take(quantity.vertex_values.flat, indices),
                              0.0)        
@@ -771,5 +780,7 @@
         
 
-    def Cache_cache_test_set_values_from_file(self):
+    def test_cache_test_set_values_from_file(self):
+        # FIXME (Ole): What is this about?
+        # I don't think it checks anything new
         quantity = Quantity(self.mesh4)
 
@@ -789,11 +800,13 @@
                        [ 3.0, 1.0]]
 
+        georef = Geo_reference(56, 0, 0)
         data_geo_spatial = Geospatial_data(data_points,
-                         geo_reference = Geo_reference(56, 0, 0))
+                                           geo_reference=georef)
+                                           
         data_points_absolute = data_geo_spatial.get_data_points(absolute=True)
         attributes = linear_function(data_points_absolute)
         att = 'spam_and_eggs'
         
-        #Create .txt file
+        # Create .txt file
         ptsfile = tempfile.mktemp(".txt")
         file = open(ptsfile,"w")
@@ -807,25 +820,27 @@
 
 
-        #Check that values can be set from file
-        quantity.set_values(filename = ptsfile,
-                            attribute_name = att, alpha = 0, use_cache=True,
-                            verbose=True)
+        # Check that values can be set from file
+        quantity.set_values(filename=ptsfile,
+                            attribute_name=att, 
+                            alpha=0, 
+                            use_cache=True,
+                            verbose=False)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
-
-        #print quantity.vertex_values.flat
-        #print answer
-
-
         assert allclose(quantity.vertex_values.flat, answer)
 
 
-        #Check that values can be set from file using default attribute
-        quantity.set_values(filename = ptsfile, alpha = 0)
+        # Check that values can be set from file using default attribute
+        quantity.set_values(filename=ptsfile, 
+                            alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
-        #checking cache
-        #quantity.set_values(filename = ptsfile,
-         #                   attribute_name = att, alpha = 0, use_cache=True,
-          #                  verbose=True)
+        # Check cache
+        quantity.set_values(filename=ptsfile,
+                            attribute_name=att, 
+                            alpha=0, 
+                            use_cache=True,
+                            verbose=False)
+        
+        
         #Cleanup
         import os
@@ -858,6 +873,7 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = txt_file,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=txt_file,
+                            attribute_name=att, 
+                            alpha=0)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
 
@@ -869,5 +885,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = txt_file, alpha = 0)
+        quantity.set_values(filename=txt_file, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -902,6 +918,6 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = txt_file,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=txt_file,
+                            attribute_name=att, alpha=0)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
 
@@ -913,5 +929,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = txt_file, alpha = 0)
+        quantity.set_values(filename=txt_file, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -958,6 +974,6 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = pts_file,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=pts_file,
+                            attribute_name=att, alpha=0)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
         #print "quantity.vertex_values.flat", quantity.vertex_values.flat
@@ -967,5 +983,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = txt_file, alpha = 0)
+        quantity.set_values(filename=txt_file, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -1040,6 +1056,6 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = pts_file,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=pts_file,
+                            attribute_name=att, alpha=0)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
         #print "quantity.vertex_values.flat", quantity.vertex_values.flat
@@ -1049,5 +1065,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = txt_file, alpha = 0)
+        quantity.set_values(filename=txt_file, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -1120,6 +1136,6 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = ptsfile,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=ptsfile,
+                            attribute_name=att, alpha=0)
         answer = linear_function(quantity.domain.get_vertex_coordinates())
 
@@ -1128,5 +1144,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = ptsfile, alpha = 0)
+        quantity.set_values(filename=ptsfile, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -1197,6 +1213,6 @@
 
         #Check that values can be set from file
-        quantity.set_values(filename = ptsfile,
-                            attribute_name = att, alpha = 0)
+        quantity.set_values(filename=ptsfile,
+                            attribute_name=att, alpha=0)
         answer = linear_function(quantity.domain. \
                                  get_vertex_coordinates(absolute=True))
@@ -1207,5 +1223,5 @@
 
         #Check that values can be set from file using default attribute
-        quantity.set_values(filename = ptsfile, alpha = 0)
+        quantity.set_values(filename=ptsfile, alpha=0)
         assert allclose(quantity.vertex_values.flat, answer)
 
@@ -1227,5 +1243,5 @@
 
         quantity2 = Quantity(self.mesh4)
-        quantity2.set_values(quantity = quantity1)
+        quantity2.set_values(quantity=quantity1)
         assert allclose(quantity2.vertex_values,
                         [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
@@ -1247,4 +1263,33 @@
 
 
+    def Xtest_set_values_from_quantity_using_polygon(self):
+        """test_set_values_from_quantity_using_polygon(self):
+        
+        Check that polygon can be used to restrict set_values when
+        using another quantity as argument.
+        """
+        
+        # Create restricting polygon (containing node #4 (2,2) and 
+        # centroid of triangle #1 (bce)
+        polygon = [[1.0, 1.0], [4.0, 1.0],
+                   [4.0, 4.0], [1.0, 4.0]]
+        assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4)                   
+        
+        quantity1 = Quantity(self.mesh4)
+        quantity1.set_vertex_values([0,1,2,3,4,5])
+
+        assert allclose(quantity1.vertex_values,
+                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
+
+
+        quantity2 = Quantity(self.mesh4)
+        quantity2.set_values(quantity=quantity1,
+                             polygon=polygon)
+                             
+        msg = 'Only node #4(e) at (2,2) should have values applied '
+        assert allclose(quantity2.vertex_values,
+                        [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg        
+                        #bac,     bce,     ecf,     dbe
+                        
 
 
