def test_load_sample_small_dataset(tmp_data_dir, caplog): ds = load_sample("ToroShockTube", progressbar=False, timeout=30) assert isinstance(ds, EnzoDataset) text = textwrap.dedent(f""" 'ToroShockTube' is not available locally. Looking up online. Downloading from https://yt-project.org/data/ToroShockTube.tar.gz Untaring downloaded file to '{str(tmp_data_dir)}' Parameters: current_time = 0.2 Parameters: domain_dimensions = [100 1 1] Parameters: domain_left_edge = [0. 0. 0.] Parameters: domain_right_edge = [1. 1. 1.] Parameters: cosmological_simulation = 0 """).strip("\n") expected = [("yt", 20, message) for message in text.split("\n")] assert caplog.record_tuples == expected caplog.clear() # loading a second time should not result in a download request ds2 = load_sample("ToroShockTube") assert isinstance(ds2, EnzoDataset) text = textwrap.dedent(f""" Sample dataset found in '{os.path.join(str(tmp_data_dir), 'ToroShockTube')}' Parameters: current_time = 0.2 Parameters: domain_dimensions = [100 1 1] Parameters: domain_left_edge = [0. 0. 0.] Parameters: domain_right_edge = [1. 1. 1.] Parameters: cosmological_simulation = 0 """).strip("\n") expected = [("yt", 20, message) for message in text.split("\n")] assert caplog.record_tuples == expected
def test_load_sample_timeout(tmp_data_dir, caplog): from requests.exceptions import ConnectTimeout, ReadTimeout # note that requests is a direct dependency to pooch, # so we don't need to mark it in a decorator. with pytest.raises((ConnectTimeout, ReadTimeout)): load_sample("IsolatedGalaxy", progressbar=False, timeout=0.00001)
def test_data_dir_broken(): # check that load_sample still works if the test_data_dir # isn't properly set, in which case we should dl to the # cwd and issue a warning. msg = (r"Storage directory from yt config doesn't exist " r"\(currently set to '/does/not/exist'\)\. " r"Current working directory will be used instead\.") with pytest.warns(UserWarning, match=msg): load_sample("ToroShockTube")
def test_typo_filename(): wrong_name = "Isolatedgalaxy" with pytest.raises( ValueError, match=re.escape( f"'{wrong_name}' is not an available dataset. Did you mean 'IsolatedGalaxy' ?" ), ): load_sample(wrong_name, timeout=1)
def test_load_sample_small_dataset(fn, archive, exact_loc, class_: str, tmp_data_dir, caplog): ds = load_sample(fn, progressbar=False, timeout=30) assert type(ds).__name__ == class_ text = textwrap.dedent(f""" '{fn.replace('/', os.path.sep)}' is not available locally. Looking up online. Downloading from https://yt-project.org/data/{archive} Untaring downloaded file to '{str(tmp_data_dir)}' """).strip("\n") expected = [("yt", 20, message) for message in text.split("\n")] assert caplog.record_tuples[:3] == expected caplog.clear() # loading a second time should not result in a download request ds2 = load_sample(fn) assert type(ds2).__name__ == class_ assert caplog.record_tuples[0] == ( "yt", 20, f"Sample dataset found in '{os.path.join(str(tmp_data_dir), *exact_loc.split('/'))}'", )
def test_unknown_filename(): fake_name = "these_are_not_the_files_your_looking_for" with pytest.raises(ValueError, match=f"'{fake_name}' is not an available dataset."): load_sample(fake_name)
def test_unknown_filename(): fake_name = "these_are_not_the_files_your_looking_for" with pytest.raises(KeyError) as err: load_sample(fake_name) assert err.exc == f"Could not find '{fake_name}' in the registry."