[Yt-svn] yt-commit r1793 - in trunk: . yt yt/extensions/enzo_test
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Tue Jul 6 11:36:07 PDT 2010
Author: mturk
Date: Tue Jul 6 11:36:06 2010
New Revision: 1793
URL: http://yt.enzotools.org/changeset/1793
Log:
Backporting updates to enzo_test from hg, fixing command_line time plotting
(from JS)
Modified:
trunk/setup.py
trunk/yt/command_line.py
trunk/yt/extensions/enzo_test/__init__.py
trunk/yt/extensions/enzo_test/hydro_tests.py
trunk/yt/extensions/enzo_test/output_tests.py
trunk/yt/extensions/enzo_test/runner.py
Modified: trunk/setup.py
==============================================================================
--- trunk/setup.py (original)
+++ trunk/setup.py Tue Jul 6 11:36:06 2010
@@ -58,6 +58,7 @@
'pdf' : ['pypdf']},
entry_points = { 'console_scripts' : [
'yt = yt.command_line:run_main',
+ 'enzo_test = yt.extensions.enzo_test:run_main',
]},
author="Matthew J. Turk",
author_email="matthewturk at gmail.com",
Modified: trunk/yt/command_line.py
==============================================================================
--- trunk/yt/command_line.py (original)
+++ trunk/yt/command_line.py Tue Jul 6 11:36:06 2010
@@ -472,7 +472,7 @@
if opts.grids: pc.plots[-1].modify["grids"]()
if opts.time:
time = pf['InitialTime']*pf['Time']*pf['years']
- pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2f yr'%time)
+ pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time)
pc.set_width(opts.width, opts.unit)
pc.set_cmap(opts.cmap)
if opts.zlim: pc.set_zlim(*opts.zlim)
Modified: trunk/yt/extensions/enzo_test/__init__.py
==============================================================================
--- trunk/yt/extensions/enzo_test/__init__.py (original)
+++ trunk/yt/extensions/enzo_test/__init__.py Tue Jul 6 11:36:06 2010
@@ -23,7 +23,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
+import runner, output_tests
+from runner import RegressionTestRunner, run_main
+
from output_tests import RegressionTest, SingleOutputTest, \
MultipleOutputTest, YTStaticOutputTest, create_test
-
-from runner import RegressionTestRunner, run
Modified: trunk/yt/extensions/enzo_test/hydro_tests.py
==============================================================================
--- trunk/yt/extensions/enzo_test/hydro_tests.py (original)
+++ trunk/yt/extensions/enzo_test/hydro_tests.py Tue Jul 6 11:36:06 2010
@@ -1,6 +1,6 @@
import matplotlib; matplotlib.use("Agg")
import pylab
-from output_tests import SingleOutputTest, YTSTaticOutputTest, create_test
+from output_tests import SingleOutputTest, YTStaticOutputTest, create_test
class TestProjection(YTStaticOutputTest):
Modified: trunk/yt/extensions/enzo_test/output_tests.py
==============================================================================
--- trunk/yt/extensions/enzo_test/output_tests.py (original)
+++ trunk/yt/extensions/enzo_test/output_tests.py Tue Jul 6 11:36:06 2010
@@ -1,6 +1,16 @@
from yt.mods import *
-test_registry = {}
+# We first create our dictionary of tests to run. This starts out empty, and
+# as tests are imported it will be filled.
+class TestRegistry(dict):
+ def __new__(cls, *p, **k):
+ if not '_the_instance' in cls.__dict__:
+ cls._the_instance = dict.__new__(cls)
+ return cls._the_instance
+
+test_registry = TestRegistry()
+
+# The exceptions we raise, related to the character of the failure.
class RegressionTestException(Exception):
pass
@@ -26,32 +36,61 @@
class __metaclass__(type):
# This ensures that all the tests are auto-registered if they have a
- # name.
-
+ # name. If they do not have a name, they are considered to be base
+ # classes to be overridden and implemented by someone else.
def __init__(cls, name, b, d):
type.__init__(cls, name, b, d)
if cls.name is not None:
test_registry[cls.name] = cls
def setup(self):
+ """
+ This function must be defined if the problem requires additional setup.
+ Note that for the most part this will be defined in base classes where
+ subclasses will only implement 'run'.
+ """
pass
def run(self):
+ """
+ This function must generate a result value, of any type, and store it
+ in self.result.
+ """
pass
def compare(self, old_result):
+ """
+ This function must accept `old_result` and compare it somehow against
+ the value stored in `self.result`. If the result is a failure, it must
+ raise an exception. Otherwise it is considered to be a success.
+ """
pass
def plot(self):
+ """
+ This function can optionally plot the contents of `self.result`.
+ """
pass
def compare_array_delta(self, a1, a2, acceptable):
+ """
+ This is a helper function. It accepts two numpy arrays and compares
+ the maximum relative difference. If the maximum relative difference is
+ greater than `acceptable` it is considered a failure and an appropriate
+ exception is raised.
+ """
delta = na.abs(a1 - a2)/(a1 + a2)
if delta.max() > acceptable:
raise ArrayDelta(delta, acceptable)
return True
def compare_value_delta(self, v1, v2, acceptable):
+ """
+ This is a helper function. It accepts two floating point values and
+ calculates the maximum relative different. If the maximum relative
+ difference is greater than `acceptable` it is considered a failure and
+ an appropriate exception is raised.
+ """
delta = na.abs(v1 - v2)/(v1 + v2)
if delta > acceptable:
raise ValueDelta(delta, acceptable)
@@ -61,6 +100,10 @@
output_type = 'single'
def __init__(self, filename):
+ """
+ This test mechanism is designed to accept a single filename and
+ evaluate it, not necessarily utilizing yt's functionality to do so.
+ """
self.filename = filename
class MultipleOutputTest(RegressionTest):
@@ -69,6 +112,10 @@
io_log_header = "DATASET WRITTEN"
def __init__(self, io_log):
+ """
+ This test mechanism is designed to accept an OutputLog file and then
+ iterate over it, evaluating every single dataset individually.
+ """
self.io_log = io_log
def __iter__(self):
@@ -76,6 +123,12 @@
yield line[len(self.io_log_header):].strip()
def create_test(base, new_name, **attrs):
+ """
+ This function accepts a base class of a test, sets some attributes on it,
+ and then registers a new test. It's a fast way of registering multiple
+ tests that share the same testing logic but that differ on a few parameters
+ or combinations of parameters.
+ """
new_name = "%s_%s" % (base.__name__, new_name)
attrs['name'] = new_name
return type(new_name, (base,), attrs)
@@ -86,6 +139,10 @@
self.pf = load(self.filename)
def pixelize(self, data, field, edges = None, dims = (512, 512)):
+ """
+ This is a helper function that returns a 2D array of the specified
+ source, in the specified field, at the specified spatial extent.
+ """
xax = lagos.x_dict[self.axis]
yax = lagos.y_dict[self.axis]
@@ -99,19 +156,35 @@
return frb
def compare_data_arrays(self, d1, d2, tol = 1e-7):
+ """
+ This is a helper function. It accepts two dictionaries of numpy arrays
+ and compares the maximum relative difference of every array. If the
+ maximum relative difference is greater than `acceptable` it is
+ considered a failure and an appropriate exception is raised.
+ """
for field in d1.keys():
self.compare_array_delta(d1[field], d2[field], tol)
@property
def sim_center(self):
+ """
+ This returns the center of the domain.
+ """
return 0.5*(self.pf["DomainRightEdge"] + self.pf["DomainLeftEdge"])
@property
def max_dens_location(self):
+ """
+ This is a helper function to return the location of the most dense
+ point.
+ """
return self.pf.h.find_max("Density")[1]
@property
def entire_simulation(self):
+ """
+ Return an unsorted array of values that cover the entire domain.
+ """
return self.pf.h.all_data()
Modified: trunk/yt/extensions/enzo_test/runner.py
==============================================================================
--- trunk/yt/extensions/enzo_test/runner.py (original)
+++ trunk/yt/extensions/enzo_test/runner.py Tue Jul 6 11:36:06 2010
@@ -1,4 +1,5 @@
import os, shelve, cPickle, sys
+import yt.cmdln as cmdln
from output_tests import test_registry, MultipleOutputTest, \
RegressionTestException
@@ -99,14 +100,43 @@
print "Running '%s'" % (test_name)
self.run_test(line.strip())
-def run():
- # This should be made to work with the optparse library
- if sys.argv[-1] == "-f":
- first_runner = RegressionTestRunner("first")
- first_runner.run_all_tests()
- else:
- second_runner = RegressionTestRunner("second", "first")
- second_runner.run_all_tests()
+class EnzoTestRunnerCommands(cmdln.Cmdln):
+ name = "enzo_tests"
+
+ def do_store(self, subcmd, opts, name, *test_modules):
+ """
+ ${cmd_name}: Run and store a new dataset.
+
+ ${cmd_usage}
+ ${cmd_option_list}
+ """
+ sys.path.insert(0, ".")
+ for fn in test_modules:
+ if fn.endswith(".py"): fn = fn[:-3]
+ print "Loading module %s" % (fn)
+ __import__(fn)
+ test_runner = RegressionTestRunner(name)
+ test_runner.run_all_tests()
+
+ def do_compare(self, subcmd, opts, reference, comparison, *test_modules):
+ """
+ ${cmd_name}: Compare a reference dataset against a new dataset. The
+ new dataset will be run regardless of whether it exists or not.
+
+ ${cmd_usage}
+ ${cmd_option_list}
+ """
+ sys.path.insert(0, ".")
+ for fn in test_modules:
+ if fn.endswith(".py"): fn = fn[:-3]
+ print "Loading module %s" % (fn)
+ __import__(fn)
+ test_runner = RegressionTestRunner(comparison, reference)
+ test_runner.run_all_tests()
+
+def run_main():
+ etrc = EnzoTestRunnerCommands()
+ sys.exit(etrc.main())
if __name__ == "__main__":
- run()
+ run_main()
More information about the yt-svn
mailing list