Skip to content

Commit 79cf49c

Browse files
committed
new migration tests
1 parent 707e1f1 commit 79cf49c

3 files changed

Lines changed: 130 additions & 8 deletions

File tree

openml/datasets/dataset.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ def publish(self) -> OpenMLDataset:
959959
file_elements = self._get_file_elements()
960960
if "description" not in file_elements:
961961
file_elements["description"] = self._to_xml()
962-
963962
dataset_id = openml._backend.dataset.publish(path="data", files=file_elements)
964963
self.dataset_id = dataset_id
965964
return self

openml/testing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def setUp(self) -> None:
295295
self.server = "https://test.openml.org/"
296296
self.base_url = "api/v1/xml"
297297
self.api_key = "normaluser"
298+
self.admin_key = "abc"
298299
self.timeout = 10
299300
self.retries = 3
300301
self.retry_policy = RetryPolicy.HUMAN

tests/test_api/test_datasets.py

Lines changed: 129 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22
from pathlib import Path
3+
from time import time
34

5+
from openml import OpenMLDataset
46
import pytest
57
import pandas as pd
6-
from typing import TYPE_CHECKING
78
from openml._api.clients.minio import MinIOClient
89
from openml._api.resources.base.fallback import FallbackProxy
910
from openml.testing import TestAPIBase
@@ -73,6 +74,62 @@ def test_get_qualities(self):
7374
assert isinstance(output,dict)
7475
assert len(output.keys()) == 19
7576

77+
@pytest.mark.uses_test_server()
78+
def test_status_update(self):
79+
dataset = OpenMLDataset(
80+
f"TEST-{str(time())}-UploadTestWithURL",
81+
"test",
82+
"ARFF",
83+
version=1,
84+
url="https://www.openml.org/data/download/61/dataset_61_iris.arff",
85+
)
86+
file_elements= dict()
87+
file_elements["description"] = dataset._to_xml()
88+
dataset_id = self.dataset.publish(path="data", files=file_elements)
89+
self.dataset_id = dataset_id
90+
# admin key for test server (only admins can activate datasets.
91+
# all users can deactivate their own datasets)
92+
self.api_key = self.dataset._http.api_key = self.admin_key
93+
94+
status = "deactivated"
95+
self.dataset.status_update(dataset_id,status)
96+
result = self.dataset.list(limit=1,offset=0,data_id=[dataset_id], status="all")
97+
result = result.to_dict(orient="index")
98+
assert result[dataset_id]["status"] == status
99+
100+
status = "active"
101+
self.dataset.status_update(dataset_id,status)
102+
result = self.dataset.list(limit=1,offset=0,data_id=[dataset_id], status="all")
103+
result = result.to_dict(orient="index")
104+
assert result[dataset_id]["status"] == status
105+
106+
assert self.dataset.delete(dataset_id)
107+
108+
@pytest.mark.uses_test_server()
109+
def test_edit(self):pass
110+
111+
@pytest.mark.uses_test_server()
112+
def test_fork(self):pass
113+
114+
@pytest.mark.uses_test_server()
115+
def test_list_qualities(self):
116+
output = self.dataset.list_qualities()
117+
assert len(output) == 19
118+
assert isinstance(output[0],str)
119+
120+
@pytest.mark.uses_test_server()
121+
def test_feature_add_remove_ontology(self):
122+
did = 11
123+
fid = 0
124+
ontology = "https://www.openml.org/unittest/" + str(time())
125+
output = self.dataset.feature_add_ontology(did,fid,ontology)
126+
assert output
127+
128+
output = self.dataset.feature_remove_ontology(did,fid,ontology)
129+
assert output
130+
131+
@pytest.mark.uses_test_server()
132+
def test_add_remove_topic(self):pass
76133

77134

78135
class TestDatasetV2API(TestAPIBase):
@@ -84,7 +141,7 @@ def setUp(self):
84141
self.client = self._get_http_client(
85142
server="http://127.0.0.1:8001/",
86143
base_url="",
87-
api_key=self.api_key,
144+
api_key="",
88145
timeout=self.timeout,
89146
retries=self.retries,
90147
retry_policy=self.retry_policy,
@@ -138,6 +195,12 @@ def test_get_qualities(self):
138195
assert isinstance(output,dict)
139196
assert len(output.keys()) == 107
140197

198+
@pytest.mark.uses_test_server()
199+
def test_list_qualities(self):
200+
output = self.dataset.list_qualities()
201+
assert len(output) == 107
202+
assert isinstance(output[0],str)
203+
141204

142205
class TestDatasetsCombined(TestAPIBase):
143206
def setUp(self):
@@ -157,7 +220,7 @@ def setUp(self):
157220
self.v2_client = self._get_http_client(
158221
server="http://127.0.0.1:8001/",
159222
base_url="",
160-
api_key=self.api_key,
223+
api_key="",
161224
timeout=self.timeout,
162225
retries=self.retries,
163226
retry_policy=self.retry_policy,
@@ -200,10 +263,11 @@ def test_list_fallback(self):
200263

201264
@pytest.mark.uses_test_server()
202265
def test_get_features_matches(self):
203-
output_v1 = self.dataset_v1.get_features(2)
204-
output_v2 = self.dataset_v2.get_features(2)
266+
output_v1 = self.dataset_v1.get_features(3)
267+
output_v2 = self.dataset_v2.get_features(3)
205268

206269
assert output_v1.keys() == output_v2.keys()
270+
# would not be same if v1 has ontology
207271
assert output_v1 == output_v2
208272

209273
@pytest.mark.uses_test_server()
@@ -215,14 +279,72 @@ def test_get_features_fallback(self):
215279

216280
@pytest.mark.uses_test_server()
217281
def test_get_qualities_matches(self):
282+
#TODO Qualities in local python server and test server differ
218283
output_v1 = self.dataset_v1.get_qualities(2)
219284
output_v2 = self.dataset_v2.get_qualities(2)
285+
assert output_v1['AutoCorrelation'] == output_v2['AutoCorrelation']
220286

221-
#TODO Qualities in local python server and test server differ
222287

223288
@pytest.mark.uses_test_server()
224289
def test_get_qualities_fallback(self):
290+
#TODO Qualities in local python server and test server differ
225291
output_fallback = self.dataset_fallback.get_qualities(2)
226292

227293
assert isinstance(output_fallback,dict)
228-
#TODO Qualities in local python server and test server differ
294+
295+
@pytest.mark.uses_test_server()
296+
def test_list_qualities_matches(self):
297+
#TODO Qualities in local python server and test server differ
298+
output_v1 = self.dataset_v1.list_qualities()
299+
output_v2 = self.dataset_v2.list_qualities()
300+
301+
assert "AutoCorrelation" in output_v1
302+
assert "AutoCorrelation" in output_v2
303+
304+
305+
@pytest.mark.uses_test_server()
306+
def test_list_qualities_fallback(self):
307+
#TODO Qualities in local python server and test server differ
308+
output_fallback = self.dataset_fallback.list_qualities()
309+
310+
assert isinstance(output_fallback,list)
311+
312+
@pytest.mark.uses_test_server()
313+
def test_status_update_fallback(self):
314+
dataset = OpenMLDataset(
315+
f"TEST-{str(time())}-UploadTestWithURL",
316+
"test",
317+
"ARFF",
318+
version=1,
319+
url="https://www.openml.org/data/download/61/dataset_61_iris.arff",
320+
)
321+
file_elements= dict()
322+
file_elements["description"] = dataset._to_xml()
323+
dataset_id = self.dataset_fallback.publish(path="data", files=file_elements)
324+
self.dataset_id = dataset_id
325+
self.api_key = self.dataset_fallback._http.api_key = self.admin_key
326+
327+
self.dataset_fallback.status_update(dataset_id,"deactivated")
328+
self.dataset_fallback.status_update(dataset_id,"active")
329+
330+
assert self.dataset_fallback.delete(dataset_id)
331+
332+
@pytest.mark.uses_test_server()
333+
def test_edit_fallback(self):pass
334+
335+
@pytest.mark.uses_test_server()
336+
def test_fork_fallback(self):pass
337+
338+
@pytest.mark.uses_test_server()
339+
def test_feature_add_remove_ontology_fallback(self):
340+
ontology = "https://www.openml.org/unittest/" + str(time())
341+
output_fallback_add = self.dataset_fallback.feature_add_ontology(
342+
11, 0,ontology)
343+
assert output_fallback_add
344+
output_fallback_remove = self.dataset_fallback.feature_remove_ontology(
345+
11, 0,ontology)
346+
assert output_fallback_remove
347+
348+
@pytest.mark.uses_test_server()
349+
def test_add_remove_topic_fallback(self):pass
350+

0 commit comments

Comments
 (0)