def _compute_path_value(self, user_param_value, storage_dir): if not data.is_uri(user_param_value): if not os.path.exists(user_param_value): raise ExecutionException("Got value %s for parameter %s, but no such file or " "directory was found." % (user_param_value, self.name)) return os.path.abspath(user_param_value) basename = os.path.basename(user_param_value) dest_path = os.path.join(storage_dir, basename) if dest_path != user_param_value: data.download_uri(uri=user_param_value, output_path=dest_path) return os.path.abspath(dest_path)
def test_download_uri(): # Verify downloading from DBFS & S3 urls calls the corresponding helper functions prefix_to_mock = {"dbfs:/": "mlflow.data._fetch_dbfs", "s3://": "mlflow.data._fetch_s3", "gs://": "mlflow.data._fetch_gs"} for prefix, fn_name in prefix_to_mock.items(): with mock.patch(fn_name) as mocked_fn, temp_directory() as dst_dir: download_uri(uri=os.path.join(prefix, "some/path"), output_path=os.path.join(dst_dir, "tmp-file")) assert mocked_fn.call_count == 1 # Verify exceptions are thrown when downloading from unsupported/invalid URIs invalid_prefixes = ["file://", "/tmp"] for prefix in invalid_prefixes: with temp_directory() as dst_dir, pytest.raises(DownloadException): download_uri(uri=os.path.join(prefix, "some/path"), output_path=os.path.join(dst_dir, "tmp-file"))