def can_run_sim(sim_fn, sim_type, file_check=False): issue_deprecation_warning( "This function is no longer used in the " "yt project testing framework and is " "targeted for deprecation.", since="4.0.0", removal="4.1.0", ) result_storage = AnswerTestingTest.result_storage if isinstance(sim_fn, SimulationTimeSeries): return result_storage is not None path = ytcfg.get("yt", "test_data_dir") if not os.path.isdir(path): return False if file_check: return os.path.isfile(os.path.join(path, sim_fn)) and result_storage is not None try: load_simulation(sim_fn, sim_type) except FileNotFoundError: if ytcfg.get("yt", "internals", "strict_requires"): if result_storage is not None: result_storage["tainted"] = True raise return False return result_storage is not None
def test_load_simulation_unidentified_data_file(tmp_path_with_empty_file): tmp_path, empty_file_path = tmp_path_with_empty_file with pytest.raises(YTSimulationNotIdentified): load_simulation( empty_file_path, "unregistered_simulation_type", )
def test_load_simulation_not_a_file(simtype, tmp_path): # it is preferable to report the most important problem in an error message # (missing data is worse than a typo insimulation_type) # so we make sure the error raised is not YTSimulationNotIdentified, # even with an absurd simulation type with pytest.raises(FileNotFoundError): load_simulation(tmp_path / "not_a_file", simtype)
def can_run_sim(sim_fn, sim_type, file_check=False): r""" Validates whether or not a given input can be used as a simulation time-series object. """ path = ytcfg.get("yt", "test_data_dir") if not os.path.isdir(path): return False if file_check: return os.path.isfile(os.path.join(path, sim_fn)) try: load_simulation(sim_fn, sim_type) except FileNotFoundError: return False return True
def sim_dir_load(sim_fn, path=None, sim_type="Enzo", find_outputs=False): if path is None and not os.path.exists(sim_fn): raise OSError if os.path.exists(sim_fn) or not path: path = "." return load_simulation( os.path.join(path, sim_fn), sim_type, find_outputs=find_outputs )
def can_run_sim(sim_fn, sim_type, file_check=False): result_storage = AnswerTestingTest.result_storage if isinstance(sim_fn, SimulationTimeSeries): return result_storage is not None path = ytcfg.get("yt", "test_data_dir") if not os.path.isdir(path): return False if file_check: return os.path.isfile(os.path.join( path, sim_fn)) and result_storage is not None try: load_simulation(sim_fn, sim_type) except FileNotFoundError: if ytcfg.get("yt", "internals", "strict_requires"): if result_storage is not None: result_storage["tainted"] = True raise return False return result_storage is not None
def __init__(self, parameter_filename, simulation_type, find_outputs=False): self.parameter_filename = parameter_filename self.simulation_type = simulation_type self.simulation = load_simulation(parameter_filename, simulation_type, find_outputs=find_outputs) self.cosmology = Cosmology( hubble_constant=(self.simulation.hubble_constant), omega_matter=self.simulation.omega_matter, omega_lambda=self.simulation.omega_lambda)