Ejemplo n.º 1
0
    def run_test(self, compare_dir):
        cur_dir = os.getcwd()
        if compare_dir is None:
            compare_id = None
        else:
            compare_id = ""
            compare_dir = os.path.join(cur_dir, compare_dir,
                                       self.test_data['fulldir'])
        os.chdir(self.run_dir)
        print "Running test: %s" % self.test_data['fulldir']
        self.run_finished = os.path.exists("RunFinished")

        if os.path.exists(results_filename):
            if self.run_finished:
                print "Reading test results from file."
                res_lines = file(results_filename)
                for line in res_lines:
                    if len(line.split()) == 2:
                        this_test, this_result = line.split()
                        self.results[this_test] = bool(this_result)

        else:
            fn = self.test_data['answer_testing_script']
            if RegressionTestRunner is None:
                print "This installation of yt does not support testing, please update to the branch 'yt'."
                return
            clear_registry()

            handler = logging.FileHandler("testing.log")
            f = logging.Formatter(ufstring)
            handler.setFormatter(f)
            mylog.addHandler(handler)
            if self.run_finished:
                if fn != 'None' and fn is not None:
                    if fn.endswith(".py"): fn = fn[:-3]
                    print "Loading module %s" % (fn)
                    f, filename, desc = imp.find_module(fn, ["."])
                    project = imp.load_module(fn, f, filename, desc)
                if fn is None or fn == "None":
                    create_test(TestFieldStatistics,
                                "field_stats",
                                tolerance=1e-10)
                    create_test(TestAllProjections,
                                "all_projs",
                                tolerance=1e-10)
                rtr = RegressionTestRunner("",
                                           compare_id,
                                           compare_results_path=compare_dir)
                rtr.run_all_tests()
                self.results = rtr.passed_tests.copy()
            mylog.removeHandler(handler)
            handler.close()

        os.chdir(cur_dir)
        self.save_results()
Ejemplo n.º 2
0
from yt.mods import *
from yt.utilities.answer_testing.api import YTStaticOutputTest, create_test, run_main
import matplotlib.pyplot as plt


class TestPhotonTest(YTStaticOutputTest):
    def run(self):
        # self.pf already exists
        sl = self.pf.h.slice(2, 1.0 / 64)
        frb = FixedResolutionBuffer(sl, (0, 1, 0, 1), (200, 200))
        self.result = frb["HII_Density"]

    def compare(self, old_result):
        current_buffer = self.result
        old_buffer = old_result

        # We want our arrays to agree to some delta
        self.compare_array_delta(current_buffer, old_buffer, 5e-3)

    def plot(self):
        plt.clf()
        plt.imshow(self.result, interpolation='nearest', origin='lower')
        fn = '%s_%s.png' % (self.pf, self.field)
        plt.savefig(fn)
        return [fn]


for f in ['HI_Density', 'HII_Density', 'HI_kph']:
    create_test(TestPhotonTest, 'photon_test_%s' % f, field=f)
Ejemplo n.º 3
0
    YTStaticOutputTest, create_test
import pylab


class TestShockImage(YTStaticOutputTest):
    field = None

    def run(self):
        # self.pf already exists
        sl = self.pf.h.slice(2, 0.5)
        frb = FixedResolutionBuffer(sl, (0.0, 1.0, 0.0, 1.0), (200, 200))
        self.result = frb[self.field]

    def compare(self, old_result):
        current_buffer = self.result
        old_buffer = old_result

        # We want our arrays to agree to some delta
        self.compare_array_delta(current_buffer, old_buffer, 1e-12)

    def plot(self):
        pylab.clf()
        pylab.imshow(self.result, interpolation='nearest', origin='lower')
        fn = "%s_%s_projection.png" % (self.pf, self.field)
        pylab.savefig(fn)
        return [fn]


for field in ['Density', 'Bx', 'Pressure', 'MachNumber']:
    create_test(TestShockImage, 'rotor_test_%s' % field, field=field)
Ejemplo n.º 4
0
    def plot(self):
        plt.clf()
        plt.imshow(self.result, interpolation='nearest', origin='lower')
        fn = '%s_%s.png' % (self.pf, self.field)
        plt.savefig(fn)
        return [fn]


class TestPhotonShadowing2(YTStaticOutputTest):
    name = "photon_shadow_temp_plot"

    def run(self):
        # self.pf already exists
        sl = self.pf.h.slice(2, 0.5)
        frb = FixedResolutionBuffer(sl, (0, 1, 0, 1), (200, 200))
        self.result = frb["Temperature"]

    def compare(self, old_result):
        current_buffer = self.result
        old_buffer = old_result

        # We want our arrays to agree to some delta
        self.compare_array_delta(current_buffer, old_buffer, 5e-3)

    def plot(self):
        return []


for f in ['HI_Density', 'HII_Density', 'Temperature', 'HI_kph']:
    create_test(TestPhotonShadowing1, 'photon_shadow_test_%s' % f, field=f)
Ejemplo n.º 5
0
from yt.utilities.answer_testing.api import YTStaticOutputTest, create_test
import pylab


class TestGardinerImage(YTStaticOutputTest):
    field = None

    def run(self):
        # self.pf already exists
        sl = self.pf.h.slice(2, 0.5)
        frb = FixedResolutionBuffer(sl, (0.0, 1.0, 0.0, 1.0), (200, 200))
        self.result = frb[self.field]

    def compare(self, old_result):
        current_buffer = self.result
        old_buffer = old_result

        # We want our arrays to agree to some delta
        self.compare_array_delta(current_buffer, old_buffer, 3e-5)

    def plot(self):
        pylab.clf()
        pylab.imshow(self.result, interpolation='nearest', origin='lower')
        fn = "%s_%s_projection.png" % (self.pf, self.field)
        pylab.savefig(fn)
        return [fn]


for field in ['Density', 'Pressure', 'Bx', 'By']:
    create_test(TestGardinerImage, 'test_gardiner_%s' % field, field=field)
Ejemplo n.º 6
0
    YTStaticOutputTest, create_test
import pylab


class TestFryxellImage(YTStaticOutputTest):
    field = None

    def run(self):
        # self.pf already exists
        sl = self.pf.h.slice(2, 0.5)
        frb = FixedResolutionBuffer(sl, (0.0, 1.0, 0.0, 1.0), (200, 200))
        self.result = frb[self.field]

    def compare(self, old_result):
        current_buffer = self.result
        old_buffer = old_result

        # We want our arrays to agree to some delta
        self.compare_array_delta(current_buffer, old_buffer, 3e-5)

    def plot(self):
        pylab.clf()
        pylab.imshow(self.result, interpolation='nearest', origin='lower')
        fn = "%s_%s_projection.png" % (self.pf, self.field)
        pylab.savefig(fn)
        return [fn]


for field in ['Density', 'Pressure']:
    create_test(TestFryxellImage, 'test_fryxell_%s' % field, field=field)