Beispiel #1
0
def run_thread_function(name, scriptname, test_data_path):
    """Run a regression test from the sherpa-test-data submodule.

    Parameters
    ----------
    name : string
       The name of the science thread to run (e.g., pha_read,
       radpro). The name should match the corresponding thread
       name in the sherpa-test-data submodule. See examples below.
    scriptname : string
       The suffix of the test script file name, usually "fit.py."
    test_data_path : string
       The path to the test data folder

    Returns
    -------
    localsyms : dict
        Any variables created by the script (includes model
        components).

    Examples
    --------
    Regression test script file names have the structure
    "name-scriptname.py." By default, scriptname is set to "fit.py."
    For example, if one wants to run the regression test
    "pha_read-fit.py," they would write

    >>> run_thread("pha_read")

    If the regression test name is "lev3fft-bar.py," they would do

    >>> run_thread("lev3fft", scriptname="bar.py")

    """
    from sherpa.astro import ui

    scriptname = name + "-" + scriptname
    cwd = os.getcwd()
    os.chdir(test_data_path)

    localsyms = {}

    def assign_model(name, val):
        localsyms[name] = val

    old_assign_model = ui.get_model_autoassign_func()

    try:
        with open(scriptname, "rb") as fh:
            cts = fh.read()
        ui.set_model_autoassign_func(assign_model)
        exec(compile(cts, scriptname, 'exec'), {}, localsyms)
    finally:
        ui.set_model_autoassign_func(old_assign_model)
        os.chdir(cwd)

    return localsyms
Beispiel #2
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     self.locals = {}
     cwd = os.getcwd()
     os.chdir(self.make_path('ciao4.3', name))
     try:
         execfile(scriptname, {}, self.locals)
     finally:
         os.chdir(cwd)
Beispiel #3
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     self.locals = {}
     cwd = os.getcwd()
     os.chdir(self.make_path('ciao4.3', name))
     try:
         execfile(scriptname, {}, self.locals)
     finally:
         os.chdir(cwd)
Beispiel #4
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     super(test_threads, self).run_thread(name, scriptname=scriptname)
Beispiel #5
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     super(test_more_ui, self).run_thread(name, scriptname=scriptname)
Beispiel #6
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     self.locals = {}
     os.chdir(os.path.join(self.datadir, 'ciao4.3', name))
     execfile(scriptname, {}, self.locals)
Beispiel #7
0
 def run_thread(self, name, scriptname='fit.py'):
     ui.clean()
     ui.set_model_autoassign_func(self.assign_model)
     self.locals = {}
     os.chdir(os.path.join(self.datadir, 'ciao4.3', name))
     execfile(scriptname, {}, self.locals)
Beispiel #8
0
def run_thread_function(name, scriptname, test_data_path):
    """Run a regression test from the sherpa-test-data submodule.

    Parameters
    ----------
    name : string
       The name of the science thread to run (e.g., pha_read,
       radpro). The name should match the corresponding thread
       name in the sherpa-test-data submodule. See examples below.
    scriptname : string
       The suffix of the test script file name, usually "fit.py."
    test_data_path : string
       The path to the test data folder

    Returns
    -------
    localsyms : dict
        Any model parameters created by the script.

    Examples
    --------
    Regression test script file names have the structure
    "name-scriptname.py." By default, scriptname is set to "fit.py."
    For example, if one wants to run the regression test
    "pha_read-fit.py," they would write

    >>> run_thread("pha_read")

    If the regression test name is "lev3fft-bar.py," they would do

    >>> run_thread("lev3fft", scriptname="bar.py")

    """
    from sherpa.astro import ui

    scriptname = name + "-" + scriptname
    cwd = os.getcwd()
    os.chdir(test_data_path)

    # Need to add to localsyms so that the scripts can work, but we
    # do not need (for now) to return all the local symbols, so
    # also have a version just for model parameters.
    #
    localsyms = {}
    modelsyms = {}

    def assign_model(name, val):
        localsyms[name] = val
        modelsyms[name] = val

    old_assign_model = ui.get_model_autoassign_func()

    try:
        with open(scriptname, "rb") as fh:
            cts = fh.read()
        ui.set_model_autoassign_func(assign_model)
        exec(compile(cts, scriptname, 'exec'), {}, localsyms)
    finally:
        ui.set_model_autoassign_func(old_assign_model)
        os.chdir(cwd)

    return modelsyms