Commits

Matthew Turk committed 51250f4

Adding a new method for testing -- hashes of the field values returned by
objects.

Comments (0)

Files changed (3)

fields_to_test.py

+# We want to test several things.  We need to be able to run the 
+
+field_list = ["Density", "Temperature", "x-velocity", "y-velocity", "z-velocity",
+                  # Now some derived fields
+                  "Pressure", "SoundSpeed", "particle_density", "Entropy",
+                  # Ghost zones
+                  "AveragedDensity", "DivV"]
+

object_field_values.py

+import hashlib
+import numpy as na
+
+from yt.utilities.answer_testing.output_tests import \
+    YTStaticOutputTest, RegressionTestException, create_test
+from yt.funcs import ensure_list
+from fields_to_test import field_list
+
+class FieldHashesDontMatch(RegressionTestException):
+    pass
+
+class YTFieldValuesTest(YTStaticOutputTest):
+    def run(self):
+        vals = self.data_object[self.field].copy()
+        vals.sort()
+        self.result = hashlib.sha256(vals.tostring()).hexdigest()
+
+    def compare(self, old_result):
+        if self.result != old_result: raise FieldHashesDontMatch
+
+class CenteredSphere(YTFieldValuesTest):
+
+    def setup(self):
+        YTFieldValuesTest.setup(self)
+        center = 0.5*(self.pf.domain_right_edge + self.pf.domain_left_edge)
+        width = (self.pf.domain_right_edge - self.pf.domain_left_edge).max()
+        self.data_object = self.pf.h.sphere(center, width/0.25)
+
+for field in field_list:
+    create_test(CenteredSphere, "centered_sphere_%s" % (field), field = field)
+
+class OffCenteredSphere(YTFieldValuesTest):
+
+    def setup(self):
+        YTFieldValuesTest.setup(self)
+        center = 0.5*(self.pf.domain_right_edge + self.pf.domain_left_edge)
+        width = (self.pf.domain_right_edge - self.pf.domain_left_edge).max()
+        self.data_object = self.pf.h.sphere(center - 0.25 * width, width/0.25)
+
+for field in field_list:
+    create_test(OffCenteredSphere, "off_centered_sphere_%s" % (field), field = field)
+
+class CornerSphere(YTFieldValuesTest):
+
+    def setup(self):
+        YTFieldValuesTest.setup(self)
+        width = (self.pf.domain_right_edge - self.pf.domain_left_edge).max()
+        self.data_object = self.pf.h.sphere(self.pf.domain_left_edge, width/0.25)
+
+for field in field_list:
+    create_test(CornerSphere, "corner_sphere_%s" % (field), field = field)
+
+
     SingleOutputTest, create_test
 from yt.utilities.answer_testing.hydro_tests import \
     TestProjection, TestGasDistribution
-
-# We want to test several things.  We need to be able to run the 
-
-fields_to_test = ["Density", "Temperature", "x-velocity", "y-velocity", "z-velocity",
-                  # Now some derived fields
-                  "Pressure", "SoundSpeed", "particle_density", "Entropy",
-                  # Ghost zones
-                  "AveragedDensity", "DivV"]
+from fields_to_test import field_list
 
 for axis in range(3):
-    for field in fields_to_test:
+    for field in field_list:
         create_test(TestProjection, "projection_test_%s_%s" % (axis, field),
                     field = field, axis = axis)
 
-for field in fields_to_test:
+for field in field_list:
     create_test(TestGasDistribution, "profile_density_test_%s" % field,
                 field_x = "Density", field_y = field)