Skip to content

Commit

Permalink
A test to make sure minio adaptor is properly created!
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwatts committed Jan 2, 2025
1 parent bee8aea commit 7b5eef5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion servicex/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import os
import tempfile
from pathlib import Path, PurePath
from typing import List, Optional, Dict
from typing import Callable, List, Optional, Dict

from pydantic import BaseModel, Field, AliasChoices, model_validator
# TODO: allow including this, but current import loop
# from servicex.models import TransformResult
from servicex.protocols import MinioAdapterProtocol

import yaml

Expand All @@ -41,6 +44,8 @@ class Endpoint(BaseModel):
token: Optional[str] = ""
# TODO: don't know how to use ServiceXAdapterProtocol here as pydantic can't handle it
adapter: Optional[object] = None
# TODO: TransformResult causes an import loop, so call it object for now.
minio: Optional[Callable[[object], MinioAdapterProtocol]] = None


g_registered_endpoints: List[Endpoint] = []
Expand Down
2 changes: 2 additions & 0 deletions servicex/servicex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def __init__(self, backend=None, url=None, config_path=None):

if url:
self.servicex = ServiceXAdapter(url)
self.minio_generator = MinioAdapter.for_transform
elif backend:
if backend not in self.endpoints:
raise ValueError(f"Backend {backend} not defined in .servicex file")
Expand All @@ -262,6 +263,7 @@ def __init__(self, backend=None, url=None, config_path=None):
refresh_token=self.endpoints[backend].token,
)
)
self.minio_generator = MinioAdapter.for_transform if ep.minio is None else ep.minio

self.query_cache = QueryCache(self.config)
self.code_generators = set(self.get_code_generators(backend).keys())
Expand Down
21 changes: 21 additions & 0 deletions tests/test_servicex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,24 @@ class my_adaptor:

sx = ServiceXClient(config_path="tests/example_config.yaml", backend="my-backend")
assert sx.servicex == my_backend


def test_minio_created(mock_cache):
class my_minio:
def __init__(self, x):
self.x = x
pass

def my_ctor_func(x):
return my_minio(x)

Configuration.register_endpoint(
Endpoint(
name="my-backend",
endpoint="fork-it-over",
minio=my_ctor_func,
)
)

sx = ServiceXClient(config_path="tests/example_config.yaml", backend="my-backend")
assert sx.minio_generator == my_ctor_func

0 comments on commit 7b5eef5

Please sign in to comment.