def test_version_matches(self, proper_version, dataset): """ Try re-loading the dataset and verify that it is possible with a matching version number. """ dataset(base_path=proper_version.data_path.parent) # Make sure the data were not re-downloaded self.check_dataset(proper_version, redownloaded=False)
def test_doesnt_delete_extra_files(self, no_version, dataset): """ Make sure an extra file that was added doesn't get harmed by the re-download process. """ path = no_version.station_path / "test.txt" with open(path, "w") as f: f.write("ijkl") with pytest.warns(UserWarning): # this emits a warning dataset(base_path=no_version.data_path.parent) # First make sure the data were re-downloaded self.check_dataset(no_version, redownloaded=True) # Now make sure the dummy file didn't get destroyed with open(path) as f: assert f.read() == "ijkl"
def new_dataset(self, dataset, tmpdir_factory) -> DataSet: """ Init a copy of each dataset and set its base directory to a temp directory to force download. """ td = Path(tmpdir_factory.mktemp("datasets")) ds = dataset(base_path=td) return ds
def dummy_dataset(self, tmpdir_factory, dataset): """ Instantiate our simple dataset for the first data download. """ newdir = Path(tmpdir_factory.mktemp("new_ds")) ds = dataset(base_path=newdir) ds.create_sha256_hash() return ds
def test_listed_files(self, low_version, dataset): """Make sure the download directory is listed in exception.""" expected = str(low_version.data_path) with pytest.raises(DataVersionError) as e: dataset(base_path=low_version.data_path.parent) assert expected in str(e.value.args[0])
def test_corrupt_version_file(self, corrupt_version, dataset): """Make sure a bogus version file will trigger a re-download""" with pytest.warns(UserWarning): dataset(base_path=corrupt_version.data_path.parent) # Make sure the data were re-downloaded self.check_dataset(corrupt_version, redownloaded=True)
def test_deleted_files(self, re_download, dataset): """Make sure the dataset can be re-downloaded if proper files were deleted""" dataset(base_path=re_download.data_path.parent) # Make sure the data were re-downloaded self.check_dataset(re_download, redownloaded=True)
def test_no_version(self, no_version, dataset): """Make sure a missing version file will trigger a re-download""" with pytest.warns(UserWarning): dataset(base_path=no_version.data_path.parent) # Make sure the data were re-downloaded self.check_dataset(no_version, redownloaded=True)
def test_version_less(self, low_version, dataset): """Make sure an exception gets raised if the version number is too low""" with pytest.raises(DataVersionError): dataset(base_path=low_version.data_path.parent) # Make sure the data were not re-downloaded self.check_dataset(low_version, redownloaded=False)
def test_version_greater(self, high_version, dataset): """Make sure a warning is issued if the version number is too high""" with pytest.warns(UserWarning): dataset(base_path=high_version.data_path.parent) # Make sure the data were not re-downloaded self.check_dataset(high_version, redownloaded=False)