Skip to content

Commit dc411dd

Browse files
committed
Merge remote-tracking branch 'geetu040/migration' into tasks
2 parents 1d3cf95 + ec9477f commit dc411dd

4 files changed

Lines changed: 21 additions & 28 deletions

File tree

openml/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _sync_api_config() -> None:
534534

535535
p = urlparse(server)
536536
v1_server = f"{p.scheme}://{p.netloc}/"
537-
v1_base_url = p.path.lstrip("/")
537+
v1_base_url = p.path.rstrip("/") + "/" # requirement for urllib.parse.urljoin
538538
connection_retry_policy = RetryPolicy.HUMAN if retry_policy == "human" else RetryPolicy.ROBOT
539539
cache_dir = str(_root_cache_directory)
540540

openml/testing.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,54 +281,42 @@ def _check_fold_timing_evaluations( # noqa: PLR0913
281281
assert evaluation <= max_val
282282

283283

284-
class TestAPIBase(unittest.TestCase):
285-
retries: int
286-
retry_policy: RetryPolicy
287-
ttl: int
288-
cache_dir: Path
284+
class TestAPIBase(TestBase):
289285
cache: HTTPCache
290286
http_clients: dict[APIVersion, HTTPClient]
291287
minio_client: MinIOClient
292-
current_api_version: APIVersion | None
293288

294-
def setUp(self) -> None:
295-
config = openml._backend.get_config()
296-
297-
self.retries = config.connection.retries
298-
self.retry_policy = config.connection.retry_policy
299-
self.ttl = config.cache.ttl
300-
self.current_api_version = None
289+
def setUp(self, n_levels: int = 1, tmpdir_suffix: str = "") -> None:
290+
super().setUp(n_levels=n_levels, tmpdir_suffix=tmpdir_suffix)
301291

302-
abspath_this_file = Path(inspect.getfile(self.__class__)).absolute()
303-
self.cache_dir = abspath_this_file.parent.parent / "files"
304-
if not self.cache_dir.is_dir():
305-
raise ValueError(
306-
f"Cannot find test cache dir, expected it to be {self.cache_dir}!",
307-
)
292+
retries = self.connection_n_retries
293+
retry_policy = RetryPolicy.HUMAN if self.retry_policy == "human" else RetryPolicy.ROBOT
294+
ttl = openml._backend.get_config_value("cache.ttl")
295+
cache_dir = self.static_cache_dir
308296

309297
self.cache = HTTPCache(
310-
path=self.cache_dir,
311-
ttl=self.ttl,
298+
path=cache_dir,
299+
ttl=ttl,
312300
)
313301
self.http_clients = {
314302
APIVersion.V1: HTTPClient(
315303
server="https://test.openml.org/",
316304
base_url="api/v1/xml/",
317305
api_key="normaluser",
318-
retries=self.retries,
319-
retry_policy=self.retry_policy,
306+
retries=retries,
307+
retry_policy=retry_policy,
320308
cache=self.cache,
321309
),
322310
APIVersion.V2: HTTPClient(
323311
server="http://localhost:8002/",
324312
base_url="",
325313
api_key="",
326-
retries=self.retries,
327-
retry_policy=self.retry_policy,
314+
retries=retries,
315+
retry_policy=retry_policy,
328316
cache=self.cache,
329317
),
330318
}
331-
self.minio_client = MinIOClient(path=self.cache_dir)
319+
self.minio_client = MinIOClient(path=cache_dir)
332320

333321

334322
def check_task_existence(

tests/test_api/test_http.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import os
77
from urllib.parse import urljoin
88
from openml.enums import APIVersion
9+
from openml._api import HTTPClient
910

1011

1112
class TestHTTPClient(TestAPIBase):
13+
http_client: HTTPClient
14+
1215
def setUp(self):
1316
super().setUp()
1417
self.http_client = self.http_clients[APIVersion.V1]

tests/test_api/test_versions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from time import time
22
import pytest
33
from openml.testing import TestAPIBase
4-
from openml._api import ResourceV1API, ResourceV2API, FallbackProxy
4+
from openml._api import ResourceV1API, ResourceV2API, FallbackProxy, ResourceAPI
55
from openml.enums import ResourceType, APIVersion
66
from openml.exceptions import OpenMLNotSupportedError
77

88

99
@pytest.mark.uses_test_server()
1010
class TestResourceAPIBase(TestAPIBase):
11+
resource: ResourceAPI | FallbackProxy
12+
1113
def _publish_and_delete(self):
1214
task_xml = """
1315
<oml:task_inputs xmlns:oml="http://openml.org/openml">

0 commit comments

Comments
 (0)