forked from openml/openml-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_clustering_task.py
More file actions
70 lines (61 loc) · 2.35 KB
/
test_clustering_task.py
File metadata and controls
70 lines (61 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# License: BSD 3-Clause
from __future__ import annotations
import pytest
import openml
from openml.exceptions import OpenMLServerException
from openml.tasks import TaskType
from openml.testing import TestBase
from .test_task import OpenMLTaskTest
class OpenMLClusteringTaskTest(OpenMLTaskTest):
__test__ = True
def setUp(self, n_levels: int = 1):
super().setUp()
self.task_id = 146714
self.task_type = TaskType.CLUSTERING
self.estimation_procedure = 17
@pytest.mark.production_server()
def test_get_dataset(self):
# no clustering tasks on test server
self.use_production_server()
task = openml.tasks.get_task(self.task_id)
task.get_dataset()
@pytest.mark.production_server()
@pytest.mark.test_server()
def test_download_task(self):
# no clustering tasks on test server
self.use_production_server()
task = super().test_download_task()
assert task.task_id == self.task_id
assert task.task_type_id == TaskType.CLUSTERING
assert task.dataset_id == 36
@pytest.mark.test_server()
def test_upload_task(self):
compatible_datasets = self._get_compatible_rand_dataset()
for i in range(100):
try:
dataset_id = compatible_datasets[i % len(compatible_datasets)]
# Upload a clustering task without a ground truth.
task = openml.tasks.create_task(
task_type=self.task_type,
dataset_id=dataset_id,
estimation_procedure_id=self.estimation_procedure,
)
task = task.publish()
TestBase._mark_entity_for_removal("task", task.id)
TestBase.logger.info(
f"collected from {__file__.split('/')[-1]}: {task.id}",
)
# success
break
except OpenMLServerException as e:
# Error code for 'task already exists'
# Should be 533 according to the docs
# (# https://www.openml.org/api_docs#!/task/post_task)
if e.code == 614:
continue
else:
raise e
else:
raise ValueError(
f"Could not create a valid task for task type ID {self.task_type}",
)