Пример #1
0
 def deferred_init(self):
     """Initialize CRDS and PySYNPHOT after module import and basic script
     object construction.
     """
     self.crds_cache = os.path.abspath(
         os.path.join(self.args.synphot_dir, "crds"))
     config.override_crds_paths(self.crds_cache)
     os.environ["PYSYN_CDBS"] = self.args.synphot_dir
     utils.clear_function_caches()
Пример #2
0
 def deferred_init(self):
     """Initialize CRDS and PySYNPHOT after module import and basic script
     object construction.
     """
     self.crds_cache = os.path.abspath(os.path.join(
         self.args.synphot_dir, "crds"))
     config.override_crds_paths(self.crds_cache)
     os.environ["PYSYN_CDBS"] = self.args.synphot_dir
     utils.clear_function_caches()
Пример #3
0
def setup(cache=CRDS_SHARED_GROUP_CACHE, url=None, clear_existing=True, observatory=None):
    """Reset the CRDS configuration state to support testing given the supplied parameters."""
    log.set_test_mode()
    old_state = config.get_crds_state()
    old_state["CRDS_CWD"] = os.getcwd()
    if clear_existing:
        config.clear_crds_state()
    new_state = dict(old_state)
    new_state["CRDS_CWD"] = HERE
    if url is not None:
        new_state["CRDS_SERVER_URL"] = url
    if cache is not None:
        new_state["CRDS_PATH"] = cache
    if observatory is not None:
        new_state["CRDS_OBSERVATORY"] = observatory
    config.set_crds_state(new_state)
    utils.clear_function_caches()
    return old_state
Пример #4
0
def cleanup(old_state):
    """Strictly speaking test cleanup is more than restoring CRDS state."""
    config.set_crds_state(old_state)
    utils.clear_function_caches()
Пример #5
0
    config.set_crds_state(new_state)
    utils.clear_function_caches()
    return old_state

def cleanup(old_state):
    """Strictly speaking test cleanup is more than restoring CRDS state."""
    config.set_crds_state(old_state)
    utils.clear_function_caches()

# ==============================================================================

def run_and_profile(name, case, globs={}, locs={}):
    """Using `name` for a banner and divider,  execute code string `case` in the
    global namespace,  both evaled printing result and under the profiler.
    """
    utils.clear_function_caches()
    log.divider()
    log.divider(name + " example")
    log.divider()
    print(eval(case, globs, locs))
    utils.clear_function_caches()
    log.divider()
    log.divider(name + " profile")
    log.divider()
    cProfile.run(case, "profile.stats")
    stats = pstats.Stats('profile.stats')
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats(100)
    os.remove('profile.stats')