1414 OpenMLNotAuthorizedError ,
1515 OpenMLServerException ,
1616)
17- from openml .tasks import TaskType
17+ from openml .tasks import TaskType , task
1818from openml .testing import TestBase , create_request_response
1919
2020
@@ -29,7 +29,7 @@ def tearDown(self):
2929
3030 @pytest .mark .test_server ()
3131 def test__get_estimation_procedure_list (self ):
32- estimation_procedures = openml .tasks . functions ._get_estimation_procedure_list ()
32+ estimation_procedures = openml ._api . resources . task ._get_estimation_procedure_list ()
3333 assert isinstance (estimation_procedures , list )
3434 assert isinstance (estimation_procedures [0 ], dict )
3535 assert estimation_procedures [0 ]["task_type_id" ] == TaskType .SUPERVISED_CLASSIFICATION
@@ -116,6 +116,13 @@ def test_list_tasks_per_type_paginate(self):
116116 assert j == task ["ttid" ]
117117 self ._check_task (task )
118118
119+ @pytest .mark .test_server ()
120+ def test__get_task (self ):
121+ openml .config .set_root_cache_directory (self .static_cache_dir )
122+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
123+ openml .tasks .get_task (1882 )
124+ mock_request .assert_not_called ()
125+
119126 @unittest .skip (
120127 "Please await outcome of discussion: https://github.com/openml/OpenML/issues/776" ,
121128 )
@@ -126,13 +133,18 @@ def test__get_task_live(self):
126133 # https://github.com/openml/openml-python/issues/378
127134 openml .tasks .get_task (34536 )
128135
129- @pytest .mark .skipif (
130- os .getenv ("OPENML_USE_LOCAL_SERVICES" ) == "true" ,
131- reason = "Pending resolution of #1657" ,
132- )
136+ @pytest .mark .test_server ()
137+ def test_get_task (self ):
138+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
139+ openml .tasks .get_task (1 )
140+ mock_request .assert_not_called ()
141+
133142 @pytest .mark .test_server ()
134143 def test_get_task_lazy (self ):
135- task = openml .tasks .get_task (2 , download_data = False ) # anneal; crossvalidation
144+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
145+ task = openml .tasks .get_task (2 , download_data = False ) # anneal; crossvalidation
146+ mock_request .assert_not_called ()
147+
136148 assert isinstance (task , OpenMLTask )
137149 assert os .path .exists (
138150 os .path .join (openml .config .get_cache_directory (), "tasks" , "2" , "task.xml" )
@@ -151,7 +163,10 @@ def test_get_task_lazy(self):
151163 )
152164 )
153165
154- task .download_split ()
166+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
167+ task .download_split ()
168+ mock_request .assert_not_called ()
169+
155170 assert os .path .exists (
156171 os .path .join (
157172 openml .config .get_cache_directory (), "tasks" , "2" , "datasplits.arff"
@@ -177,6 +192,15 @@ def assert_and_raise(*args, **kwargs):
177192 # Now the file should no longer exist
178193 assert not os .path .exists (os .path .join (os .getcwd (), "tasks" , "1" , "tasks.xml" ))
179194
195+ @pytest .mark .test_server ()
196+ def test_get_task_with_cache (self ):
197+ openml .config .set_root_cache_directory (self .static_cache_dir )
198+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
199+ task = openml .tasks .get_task (1 )
200+ mock_request .assert_not_called ()
201+
202+ assert isinstance (task , OpenMLTask )
203+
180204 @pytest .mark .production_server ()
181205 def test_get_task_different_types (self ):
182206 self .use_production_server ()
@@ -189,8 +213,10 @@ def test_get_task_different_types(self):
189213
190214 @pytest .mark .test_server ()
191215 def test_download_split (self ):
192- task = openml .tasks .get_task (1 ) # anneal; crossvalidation
193- split = task .download_split ()
216+ with unittest .mock .patch ("requests.sessions.Session.request" ) as mock_request :
217+ task = openml .tasks .get_task (1 ) # anneal; crossvalidation
218+ split = task .download_split ()
219+ mock_request .assert_not_called ()
194220 assert type (split ) == OpenMLSplit
195221 assert os .path .exists (
196222 os .path .join (
0 commit comments