Skip to content

Commit 4a7db0e

Browse files
authored
Subclass all test classes from openml test helper (#609)
* Subclass all test classes from openml test helper * FIX inheritance issues * TST add sentinel to dataset upload * TEST redirect a few tests to the live server again * MAINT fix pep8 * Trying simple solution
1 parent 7c0a77d commit 4a7db0e

File tree

7 files changed

+33
-16
lines changed

7 files changed

+33
-16
lines changed

openml/runs/functions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def run_flow_on_task(flow, task, avoid_duplicate_runs=True, flow_tags=None,
127127
raise ValueError('flow.flow_id is not None, but the flow does not'
128128
'exist on the server according to flow_exists')
129129
_publish_flow_if_necessary(flow)
130+
# if the flow was published successfully
131+
# and has an id
132+
if flow.flow_id is not None:
133+
flow_id = flow.flow_id
134+
130135

131136
data_content, trace, fold_evaluations, sample_evaluations = res
132137
if not isinstance(flow.flow_id, int):

openml/testing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ def tearDown(self):
7777
raise
7878
openml.config.server = self.production_server
7979

80-
def _add_sentinel_to_flow_name(self, flow, sentinel=None):
80+
def _get_sentinel(self, sentinel=None):
8181
if sentinel is None:
8282
# Create a unique prefix for the flow. Necessary because the flow is
8383
# identified by its name and external version online. Having a unique
8484
# name allows us to publish the same flow in each test run
8585
md5 = hashlib.md5()
8686
md5.update(str(time.time()).encode('utf-8'))
87+
md5.update(str(os.getpid()).encode('utf-8'))
8788
sentinel = md5.hexdigest()[:10]
8889
sentinel = 'TEST%s' % sentinel
90+
return sentinel
8991

92+
def _add_sentinel_to_flow_name(self, flow, sentinel=None):
93+
sentinel = self._get_sentinel(sentinel=sentinel)
9094
flows_to_visit = list()
9195
flows_to_visit.append(flow)
9296
while len(flows_to_visit) > 0:

tests/test_datasets/test_dataset_functions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test__retrieve_class_labels(self):
367367
def test_upload_dataset_with_url(self):
368368

369369
dataset = OpenMLDataset(
370-
"UploadTestWithURL",
370+
"%s-UploadTestWithURL" % self._get_sentinel(),
371371
"test",
372372
data_format="arff",
373373
version=1,
@@ -378,7 +378,8 @@ def test_upload_dataset_with_url(self):
378378

379379
def test_data_status(self):
380380
dataset = OpenMLDataset(
381-
"UploadTestWithURL", "test", "ARFF",
381+
"%s-UploadTestWithURL" % self._get_sentinel(),
382+
"test", "ARFF",
382383
version=1,
383384
url="https://www.openml.org/data/download/61/dataset_61_iris.arff")
384385
dataset.publish()
@@ -476,7 +477,7 @@ def test_create_dataset_numpy(self):
476477
for i in range(data.shape[1])]
477478

478479
dataset = create_dataset(
479-
name='NumPy_testing_dataset',
480+
name='%s-NumPy_testing_dataset' % self._get_sentinel(),
480481
description='Synthetic dataset created from a NumPy array',
481482
creator='OpenML tester',
482483
contributor=None,
@@ -536,7 +537,7 @@ def test_create_dataset_list(self):
536537
]
537538

538539
dataset = create_dataset(
539-
name="ModifiedWeather",
540+
name="%s-ModifiedWeather" % self._get_sentinel(),
540541
description=(
541542
'Testing dataset upload when the data is a list of lists'
542543
),
@@ -583,7 +584,7 @@ def test_create_dataset_sparse(self):
583584
]
584585

585586
xor_dataset = create_dataset(
586-
name="XOR",
587+
name="%s-XOR" % self._get_sentinel(),
587588
description='Dataset representing the XOR operation',
588589
creator=None,
589590
contributor=None,
@@ -620,7 +621,7 @@ def test_create_dataset_sparse(self):
620621
]
621622

622623
xor_dataset = create_dataset(
623-
name="XOR",
624+
name="%s-XOR" % self._get_sentinel(),
624625
description='Dataset representing the XOR operation',
625626
creator=None,
626627
contributor=None,
@@ -732,7 +733,7 @@ def test_create_dataset_pandas(self):
732733
df['windy'] = df['windy'].astype('bool')
733734
df['play'] = df['play'].astype('category')
734735
# meta-information
735-
name = 'Pandas_testing_dataset'
736+
name = '%s-pandas_testing_dataset' % self._get_sentinel()
736737
description = 'Synthetic dataset created from a Pandas DataFrame'
737738
creator = 'OpenML tester'
738739
collection_date = '01-01-2018'
@@ -842,7 +843,7 @@ def test_create_dataset_pandas(self):
842843

843844
def test_create_dataset_row_id_attribute_error(self):
844845
# meta-information
845-
name = 'Pandas_testing_dataset'
846+
name = '%s-pandas_testing_dataset' % self._get_sentinel()
846847
description = 'Synthetic dataset created from a Pandas DataFrame'
847848
creator = 'OpenML tester'
848849
collection_date = '01-01-2018'
@@ -884,7 +885,7 @@ def test_create_dataset_row_id_attribute_error(self):
884885

885886
def test_create_dataset_row_id_attribute_inference(self):
886887
# meta-information
887-
name = 'Pandas_testing_dataset'
888+
name = '%s-pandas_testing_dataset' % self._get_sentinel()
888889
description = 'Synthetic dataset created from a Pandas DataFrame'
889890
creator = 'OpenML tester'
890891
collection_date = '01-01-2018'

tests/test_flows/test_flow_functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import six
66

77
import openml
8+
from openml.testing import TestBase
89

910

10-
class TestFlowFunctions(unittest.TestCase):
11+
class TestFlowFunctions(TestBase):
1112
_multiprocess_can_split_ = True
1213

1314
def _check_flow(self, flow):
@@ -23,6 +24,7 @@ def _check_flow(self, flow):
2324
flow['external_version'] is None)
2425

2526
def test_list_flows(self):
27+
openml.config.server = self.production_server
2628
# We can only perform a smoke test here because we test on dynamic
2729
# data from the internet...
2830
flows = openml.flows.list_flows()
@@ -32,19 +34,22 @@ def test_list_flows(self):
3234
self._check_flow(flows[fid])
3335

3436
def test_list_flows_empty(self):
37+
openml.config.server = self.production_server
3538
flows = openml.flows.list_flows(tag='NoOneEverUsesThisTag123')
3639
if len(flows) > 0:
3740
raise ValueError('UnitTest Outdated, got somehow results (please adapt)')
3841

3942
self.assertIsInstance(flows, dict)
4043

4144
def test_list_flows_by_tag(self):
45+
openml.config.server = self.production_server
4246
flows = openml.flows.list_flows(tag='weka')
4347
self.assertGreaterEqual(len(flows), 5)
4448
for did in flows:
4549
self._check_flow(flows[did])
4650

4751
def test_list_flows_paginate(self):
52+
openml.config.server = self.production_server
4853
size = 10
4954
max = 100
5055
for i in range(0, max, size):

tests/test_flows/test_sklearn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from sklearn.impute import SimpleImputer as Imputer
3434

3535
import openml
36+
from openml.testing import TestBase
3637
from openml.flows import OpenMLFlow, sklearn_to_flow, flow_to_sklearn
3738
from openml.flows.functions import assert_flows_equal
3839
from openml.flows.sklearn_converter import _format_external_version, \
@@ -56,11 +57,12 @@ def fit(self, X, y):
5657
pass
5758

5859

59-
class TestSklearn(unittest.TestCase):
60+
class TestSklearn(TestBase):
6061
# Splitting not helpful, these test's don't rely on the server and take less
6162
# than 1 seconds
6263

6364
def setUp(self):
65+
super(TestSklearn, self).setUp()
6466
iris = sklearn.datasets.load_iris()
6567
self.X = iris.data
6668
self.y = iris.target

tests/test_runs/test_trace.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import unittest
2-
31
from openml.runs import OpenMLRunTrace, OpenMLTraceIteration
2+
from openml.testing import TestBase
43

54

6-
class TestTrace(unittest.TestCase):
5+
class TestTrace(TestBase):
76
def test_get_selected_iteration(self):
87
trace_iterations = {}
98
for i in range(5):

tests/test_tasks/test_split.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import numpy as np
66

77
from openml import OpenMLSplit
8+
from openml.testing import TestBase
89

910

10-
class OpenMLSplitTest(unittest.TestCase):
11+
class OpenMLSplitTest(TestBase):
1112
# Splitting not helpful, these test's don't rely on the server and take less
1213
# than 5 seconds + rebuilding the test would potentially be costly
1314

0 commit comments

Comments
 (0)