44import pytest
55
66import openml
7- from openml ._api .resources import FallbackProxy , RunV1API , RunV2API
7+ from openml ._api .resources import RunV1API , RunV2API
88from openml .enums import APIVersion
99from openml .exceptions import OpenMLNotSupportedError
1010from openml .runs .run import OpenMLRun
1111from openml .testing import TestAPIBase
1212
1313
1414@pytest .mark .uses_test_server ()
15- class TestRunsV1 (TestAPIBase ):
16- """Test RunsV1 resource implementation."""
17-
18- def setUp (self ):
19- super ().setUp ()
20- http_client = self .http_clients [APIVersion .V1 ]
21- self .resource = RunV1API (http_client )
22-
23- def test_get (self ):
24- """Test getting a run from the V1 API."""
25- run = self .resource .get (run_id = 1 )
15+ class TestRunAPIBase (TestAPIBase ):
16+ resource : RunV1API | RunV2API
2617
18+ def _assert_run_shape (self , run : OpenMLRun ) -> None :
2719 self .assertIsInstance (run , OpenMLRun )
2820 self .assertEqual (run .run_id , 1 )
2921 self .assertIsInstance (run .task_id , int )
3022
31- def test_list (self ):
32- """Test listing runs from the V1 API."""
23+ def _get (self ) -> OpenMLRun :
24+ run = self .resource .get (run_id = 1 )
25+ self ._assert_run_shape (run )
26+ return run
27+
28+ def _list (self ) -> None :
3329 limit = 5
3430 runs_df = self .resource .list (limit = limit , offset = 0 )
3531
@@ -39,9 +35,7 @@ def test_list(self):
3935 self .assertIn ("setup_id" , runs_df .columns )
4036 self .assertIn ("flow_id" , runs_df .columns )
4137
42- def test_delete_and_publish_run (self ):
43- """Test publishing then deleting a run using V1 API."""
44- # First, create and publish a run to delete
38+ def _publish_and_delete (self ) -> None :
4539 from sklearn .neighbors import KNeighborsClassifier
4640
4741 task = openml .tasks .get_task (19 )
@@ -62,38 +56,85 @@ def test_delete_and_publish_run(self):
6256 self .resource .get (run_id = run_id )
6357
6458
65- @pytest .mark .uses_test_server ()
66- class TestRunsV2 (TestRunsV1 ):
67- """Test RunsV2 resource implementation."""
59+ class TestRunV1API (TestRunAPIBase ):
60+ def setUp (self ):
61+ super ().setUp ()
62+ http_client = self .http_clients [APIVersion .V1 ]
63+ self .resource = RunV1API (http_client )
64+
65+ def test_get (self ):
66+ self ._get ()
67+
68+ def test_list (self ):
69+ self ._list ()
6870
71+ def test_publish_and_delete (self ):
72+ self ._publish_and_delete ()
73+
74+
75+ class TestRunV2API (TestRunAPIBase ):
6976 def setUp (self ):
7077 super ().setUp ()
7178 http_client = self .http_clients [APIVersion .V2 ]
7279 self .resource = RunV2API (http_client )
7380
7481 def test_get (self ):
75- with pytest .raises (OpenMLNotSupportedError ):
76- super ().test_get ()
82+ with pytest .raises (
83+ OpenMLNotSupportedError ,
84+ match = "RunV2API: v2 API does not support `get` for resource `run`" ,
85+ ):
86+ self ._get ()
7787
7888 def test_list (self ):
79- with pytest .raises (OpenMLNotSupportedError ):
80- super ().test_list ()
81-
82- def test_delete_and_publish_run (self ):
83- with pytest .raises (OpenMLNotSupportedError ):
84- super ().test_delete_and_publish_run ()
89+ with pytest .raises (
90+ OpenMLNotSupportedError ,
91+ match = "RunV2API: v2 API does not support `list` for resource `run`" ,
92+ ):
93+ self ._list ()
8594
95+ def test_publish_and_delete (self ):
96+ with pytest .raises (
97+ OpenMLNotSupportedError ,
98+ match = "RunV2API: v2 API does not support `publish` for resource `run`" ,
99+ ):
100+ self ._publish_and_delete ()
86101
87- @pytest .mark .uses_test_server ()
88- class TestRunsFallback (TestRunsV1 ):
89- """Test combined functionality and fallback between V1 and V2."""
90102
103+ class TestRunCombinedAPI (TestAPIBase ):
91104 def setUp (self ):
92105 super ().setUp ()
93- http_client_v1 = self .http_clients [APIVersion .V1 ]
94- resource_v1 = RunV1API (http_client_v1 )
106+ self .resource_v1 = RunV1API (self .http_clients [APIVersion .V1 ])
107+ self .resource_v2 = RunV2API (self .http_clients [APIVersion .V2 ])
108+
109+ def test_get_contracts (self ):
110+ run_v1 = self .resource_v1 .get (run_id = 1 )
111+ self .assertIsInstance (run_v1 , OpenMLRun )
112+ self .assertEqual (run_v1 .run_id , 1 )
95113
96- http_client_v2 = self .http_clients [APIVersion .V2 ]
97- resource_v2 = RunV2API (http_client_v2 )
114+ with pytest .raises (
115+ OpenMLNotSupportedError ,
116+ match = "RunV2API: v2 API does not support `get` for resource `run`" ,
117+ ):
118+ self .resource_v2 .get (run_id = 1 )
98119
99- self .resource = FallbackProxy (resource_v2 , resource_v1 )
120+ def test_list_contracts (self ):
121+ limit = 5
122+ runs_v1 = self .resource_v1 .list (limit = limit , offset = 0 )
123+ self .assertEqual (len (runs_v1 ), limit )
124+ self .assertIn ("run_id" , runs_v1 .columns )
125+ self .assertIn ("task_id" , runs_v1 .columns )
126+ self .assertIn ("setup_id" , runs_v1 .columns )
127+ self .assertIn ("flow_id" , runs_v1 .columns )
128+
129+ with pytest .raises (
130+ OpenMLNotSupportedError ,
131+ match = "RunV2API: v2 API does not support `list` for resource `run`" ,
132+ ):
133+ self .resource_v2 .list (limit = limit , offset = 0 )
134+
135+ def test_publish_contracts (self ):
136+ with pytest .raises (
137+ OpenMLNotSupportedError ,
138+ match = "RunV2API: v2 API does not support `publish` for resource `run`" ,
139+ ):
140+ self .resource_v2 .publish (path = "run" , files = {"description" : "<run/>" })
0 commit comments