Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions tests/test_tasks/test_task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from random import randint

from openml.exceptions import OpenMLServerException
from openml.testing import TestBase
from openml.datasets import (
get_dataset,
Expand Down Expand Up @@ -42,16 +43,37 @@ def test_download_task(self):

def test_upload_task(self):

dataset_id = self._get_compatible_rand_dataset()
# TODO consider implementing on the diff task types.
task = create_task(
task_type_id=self.task_type_id,
dataset_id=dataset_id,
target_name=self._get_random_feature(dataset_id),
estimation_procedure_id=self.estimation_procedure
)
# We don't know if the task in question already exists, so we try a few times. Checking
# beforehand would not be an option because a concurrent unit test could potentially
# create the same task and make this unit test fail (i.e. getting a dataset and creating
# a task for it is not atomic).
for i in range(100):
try:
dataset_id = self._get_compatible_rand_dataset()
# TODO consider implementing on the diff task types.
task = create_task(
task_type_id=self.task_type_id,
dataset_id=dataset_id,
target_name=self._get_random_feature(dataset_id),
estimation_procedure_id=self.estimation_procedure
)

task_id = task.publish()
# 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(
'Could not create a valid task for task type ID {}'.format(self.task_type_id)
)

task_id = task.publish()
_delete_entity('task', task_id)

def _get_compatible_rand_dataset(self) -> int:
Expand Down