Skip to content

Commit b349581

Browse files
committed
remove old caching tests
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
1 parent d6146aa commit b349581

3 files changed

Lines changed: 41 additions & 157 deletions

File tree

tests/test_api/test_run.py

Lines changed: 41 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,42 @@
55

66
import openml
77
from openml._api.resources import FallbackProxy, RunV1API, RunV2API
8+
from openml.enums import APIVersion
89
from openml.exceptions import OpenMLNotSupportedError
910
from openml.runs.run import OpenMLRun
1011
from openml.testing import TestAPIBase
1112

1213

14+
@pytest.mark.uses_test_server()
1315
class TestRunsV1(TestAPIBase):
1416
"""Test RunsV1 resource implementation."""
1517

1618
def setUp(self):
1719
super().setUp()
18-
self.resource = RunV1API(self.http_client)
20+
http_client = self.http_clients[APIVersion.V1]
21+
self.resource = RunV1API(http_client)
1922

20-
@pytest.mark.uses_test_server()
2123
def test_get(self):
2224
"""Test getting a run from the V1 API."""
2325
run = self.resource.get(run_id=1)
2426

25-
assert isinstance(run, OpenMLRun)
26-
assert run.run_id == 1
27-
assert isinstance(run.task_id, int)
27+
self.assertIsInstance(run, OpenMLRun)
28+
self.assertEqual(run.run_id, 1)
29+
self.assertIsInstance(run.task_id, int)
2830

29-
@pytest.mark.uses_test_server()
3031
def test_list(self):
3132
"""Test listing runs from the V1 API."""
32-
runs_df = self.resource.list(limit=5, offset=0)
33-
34-
assert len(runs_df) > 0
35-
assert len(runs_df) <= 5
36-
assert "run_id" in runs_df.columns
37-
assert "task_id" in runs_df.columns
38-
assert "setup_id" in runs_df.columns
39-
assert "flow_id" in runs_df.columns
40-
41-
@pytest.mark.uses_test_server()
42-
def test_publish(self):
43-
"""Test publishing a small run using V1 API."""
44-
from sklearn.neighbors import KNeighborsClassifier
33+
limit = 5
34+
runs_df = self.resource.list(limit=limit, offset=0)
4535

46-
task = openml.tasks.get_task(19)
47-
clf = KNeighborsClassifier(n_neighbors=3)
48-
run = openml.runs.run_model_on_task(clf, task)
36+
self.assertEqual(len(runs_df), limit)
37+
self.assertIn("run_id", runs_df.columns)
38+
self.assertIn("task_id", runs_df.columns)
39+
self.assertIn("setup_id", runs_df.columns)
40+
self.assertIn("flow_id", runs_df.columns)
4941

50-
file_elements = run._get_file_elements()
51-
if "description" not in file_elements:
52-
file_elements["description"] = run._to_xml()
53-
54-
run_id = self.resource.publish(path="run", files=file_elements)
55-
assert isinstance(run_id, int)
56-
assert run_id > 0
57-
58-
@pytest.mark.uses_test_server()
59-
def test_delete_run(self):
60-
"""Test deleting a run using V1 API."""
42+
def test_delete_and_publish_run(self):
43+
"""Test publishing then deleting a run using V1 API."""
6144
# First, create and publish a run to delete
6245
from sklearn.neighbors import KNeighborsClassifier
6346

@@ -70,84 +53,47 @@ def test_delete_run(self):
7053
file_elements["description"] = run._to_xml()
7154

7255
run_id = self.resource.publish(path="run", files=file_elements)
73-
assert isinstance(run_id, int)
74-
assert run_id > 0
56+
self.assertIsInstance(run_id, int)
57+
self.assertGreater(run_id, 0)
7558

76-
# Now delete the run
7759
self.resource.delete(run_id)
7860

79-
# Verify deletion by attempting to fetch the run
8061
with pytest.raises(Exception):
8162
self.resource.get(run_id=run_id)
8263

8364

84-
class TestRunsV2(TestAPIBase):
65+
@pytest.mark.uses_test_server()
66+
class TestRunsV2(TestRunsV1):
8567
"""Test RunsV2 resource implementation."""
8668

8769
def setUp(self):
8870
super().setUp()
89-
self.v2_http_client = self._get_http_client(
90-
server="http://127.0.0.1:8001/",
91-
base_url="",
92-
api_key=self.api_key,
93-
timeout=self.timeout,
94-
retries=self.retries,
95-
retry_policy=self.retry_policy,
96-
cache=self.cache,
97-
)
98-
self.resource = RunV2API(self.v2_http_client)
99-
100-
@pytest.mark.uses_test_server()
101-
def test_get_not_supported(self):
102-
"""Test that V2 get is not implemented."""
71+
http_client = self.http_clients[APIVersion.V2]
72+
self.resource = RunV2API(http_client)
73+
74+
def test_get(self):
75+
with pytest.raises(OpenMLNotSupportedError):
76+
super().test_get()
77+
78+
def test_list(self):
10379
with pytest.raises(OpenMLNotSupportedError):
104-
_ = self.resource.get(run_id=1)
80+
super().test_list()
10581

106-
@pytest.mark.uses_test_server()
107-
def test_list_not_supported(self):
108-
"""Test that V2 list is not implemented."""
82+
def test_delete_and_publish_run(self):
10983
with pytest.raises(OpenMLNotSupportedError):
110-
_ = self.resource.list(limit=5, offset=0)
84+
super().test_delete_and_publish_run()
11185

11286

113-
class TestRunsCombined(TestAPIBase):
114-
"""Test fallback behavior between V2 and V1 for Runs."""
87+
@pytest.mark.uses_test_server()
88+
class TestRunsFallback(TestRunsV1):
89+
"""Test combined functionality and fallback between V1 and V2."""
11590

11691
def setUp(self):
11792
super().setUp()
118-
self.v1_client = self._get_http_client(
119-
server=self.server,
120-
base_url=self.base_url,
121-
api_key=self.api_key,
122-
timeout=self.timeout,
123-
retries=self.retries,
124-
retry_policy=self.retry_policy,
125-
cache=self.cache,
126-
)
127-
self.v2_client = self._get_http_client(
128-
server="http://127.0.0.1:8001/",
129-
base_url="",
130-
api_key=self.api_key,
131-
timeout=self.timeout,
132-
retries=self.retries,
133-
retry_policy=self.retry_policy,
134-
cache=self.cache,
135-
)
136-
137-
self.resource_v1 = RunV1API(self.v1_client)
138-
self.resource_v2 = RunV2API(self.v2_client)
139-
self.resource_fallback = FallbackProxy(self.resource_v2, self.resource_v1)
140-
141-
@pytest.mark.uses_test_server()
142-
def test_get_fallback(self):
143-
"""Test fallback for get() when V2 is not implemented."""
144-
run = self.resource_fallback.get(run_id=1)
145-
assert isinstance(run, OpenMLRun)
146-
assert run.run_id == 1
147-
148-
@pytest.mark.uses_test_server()
149-
def test_list_fallback(self):
150-
"""Test fallback for list() when V2 is not implemented."""
151-
runs_df = self.resource_fallback.list(limit=5, offset=0)
152-
assert len(runs_df) > 0
153-
assert "run_id" in runs_df.columns
93+
http_client_v1 = self.http_clients[APIVersion.V1]
94+
resource_v1 = RunV1API(http_client_v1)
95+
96+
http_client_v2 = self.http_clients[APIVersion.V2]
97+
resource_v2 = RunV2API(http_client_v2)
98+
99+
self.resource = FallbackProxy(resource_v2, resource_v1)

tests/test_evaluations/test_evaluation_functions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def test_list_evaluation_measures(self):
239239
assert isinstance(measures, list) is True
240240
assert all(isinstance(s, str) for s in measures) is True
241241

242-
@pytest.mark.skip(reason="production server issue")
243242
@pytest.mark.production()
244243
def test_list_evaluations_setups_filter_flow(self):
245244
self.use_production_server()

tests/test_runs/test_run_functions.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
OpenMLNotAuthorizedError,
4242
OpenMLServerException,
4343
)
44-
from openml._api.config import settings
4544
#from openml.extensions.sklearn import cat, cont
4645
from openml.runs.functions import (
4746
_run_task_get_arffcontent,
@@ -1664,63 +1663,6 @@ def test_run_on_dataset_with_missing_labels_array(self):
16641663
# repeat, fold, row_id, 6 confidences, prediction and correct label
16651664
assert len(row) == 12
16661665

1667-
@pytest.mark.uses_test_server()
1668-
def test_get_cached_run(self):
1669-
previous_cache_dir = settings.cache.dir
1670-
try:
1671-
settings.cache.dir = str(self.workdir / "http_cache_runs")
1672-
openml._backend.set_config_value("api_version", "v1")
1673-
openml._backend.set_config_value("fallback_api_version", "v1")
1674-
1675-
run = openml.runs.get_run(1)
1676-
assert run.run_id == 1
1677-
1678-
http_client = openml._backend.run._http
1679-
assert http_client.cache is not None
1680-
1681-
url = urljoin(
1682-
http_client.server,
1683-
urljoin(http_client.base_url, "run/1"),
1684-
)
1685-
cache_key = http_client.cache.get_key(url, {})
1686-
cache_path = http_client.cache._key_to_path(cache_key)
1687-
1688-
assert (cache_path / "meta.json").exists()
1689-
assert (cache_path / "headers.json").exists()
1690-
assert (cache_path / "body.bin").exists()
1691-
finally:
1692-
settings.cache.dir = previous_cache_dir
1693-
openml._backend.set_config_value("api_version", "v1")
1694-
openml._backend.set_config_value("fallback_api_version", "v1")
1695-
1696-
def test_get_uncached_run(self):
1697-
previous_cache_dir = settings.cache.dir
1698-
try:
1699-
settings.cache.dir = str(self.workdir / "http_cache_runs_uncached")
1700-
openml._backend.set_config_value("api_version", "v1")
1701-
openml._backend.set_config_value("fallback_api_version", "v1")
1702-
1703-
run = openml.runs.get_run(1)
1704-
assert run.run_id == 1
1705-
1706-
http_client = openml._backend.run._http
1707-
assert http_client.cache is not None
1708-
1709-
url = urljoin(
1710-
http_client.server,
1711-
urljoin(http_client.base_url, "run/1"),
1712-
)
1713-
cache_key = http_client.cache.get_key(url, {})
1714-
cache_path = http_client.cache._key_to_path(cache_key)
1715-
1716-
assert (cache_path / "meta.json").exists()
1717-
assert (cache_path / "headers.json").exists()
1718-
assert (cache_path / "body.bin").exists()
1719-
finally:
1720-
settings.cache.dir = previous_cache_dir
1721-
openml._backend.set_config_value("api_version", "v1")
1722-
openml._backend.set_config_value("fallback_api_version", "v1")
1723-
17241666
@pytest.mark.sklearn()
17251667
@pytest.mark.uses_test_server()
17261668
def test_run_flow_on_task_downloaded_flow(self):
@@ -1865,7 +1807,6 @@ def test_initialize_model_from_run_nonstrict(self):
18651807
# This tests all lines of code for OpenML but not the initialization, which we do not want to guarantee anyhow.
18661808
_ = openml.runs.initialize_model_from_run(run_id=1, strict_version=False)
18671809

1868-
@pytest.mark.skip(reason="old delete style test, to be removed")
18691810
@mock.patch.object(requests.Session, "delete")
18701811
def test_delete_run_not_owned(mock_delete, test_files_directory, test_api_key):
18711812
openml.config.start_using_configuration_for_example()
@@ -1885,7 +1826,6 @@ def test_delete_run_not_owned(mock_delete, test_files_directory, test_api_key):
18851826
assert run_url == mock_delete.call_args.args[0]
18861827
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
18871828

1888-
@pytest.mark.skip(reason="old delete style test, to be removed")
18891829
@mock.patch.object(requests.Session, "delete")
18901830
def test_delete_run_success(mock_delete, test_files_directory, test_api_key):
18911831
openml.config.start_using_configuration_for_example()
@@ -1902,7 +1842,6 @@ def test_delete_run_success(mock_delete, test_files_directory, test_api_key):
19021842
assert run_url == mock_delete.call_args.args[0]
19031843
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
19041844

1905-
@pytest.mark.skip(reason="old delete style test, to be removed")
19061845
@mock.patch.object(requests.Session, "delete")
19071846
def test_delete_unknown_run(mock_delete, test_files_directory, test_api_key):
19081847
openml.config.start_using_configuration_for_example()

0 commit comments

Comments
 (0)