Skip to content

Commit 1f984ec

Browse files
committed
MAINT remove tests from production code
1 parent 310d1d1 commit 1f984ec

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

openml/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
cachedir = ""
1717
privatedir = ""
1818

19-
_testmode = False
2019

2120
if sys.version_info[0] < 3:
2221
import ConfigParser as configparser

openml/flows/flow.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,10 @@ def _generate_flow_xml(self):
5252
"""
5353
model = self.model
5454

55-
if config._testmode:
56-
flow_name = '%s%s' % (config.testsentinel, self.name)
57-
else:
58-
flow_name = self.name
59-
6055
flow_dict = OrderedDict()
6156
flow_dict['oml:flow'] = OrderedDict()
6257
flow_dict['oml:flow']['@xmlns:oml'] = 'http://openml.org/openml'
63-
flow_dict['oml:flow']['oml:name'] = flow_name
58+
flow_dict['oml:flow']['oml:name'] = self._get_name()
6459
flow_dict['oml:flow']['oml:external_version'] = self.external_version
6560
flow_dict['oml:flow']['oml:description'] = self.description
6661

@@ -106,7 +101,7 @@ def _ensure_flow_exists(self):
106101
"""
107102
import sklearn
108103
flow_version = 'sklearn_' + sklearn.__version__
109-
_, _, flow_id = _check_flow_exists(self.name, flow_version)
104+
_, _, flow_id = _check_flow_exists(self._get_name(), flow_version)
110105
# TODO add numpy and scipy version!
111106

112107
if int(flow_id) == -1:
@@ -118,6 +113,10 @@ def _ensure_flow_exists(self):
118113

119114
return int(flow_id)
120115

116+
def _get_name(self):
117+
"""Helper function. Can be mocked for testing."""
118+
return self.name
119+
121120

122121
def _check_flow_exists(name, version):
123122
"""Retrieves the flow id of the flow uniquely identified by name+version.
@@ -143,12 +142,6 @@ def _check_flow_exists(name, version):
143142
if not (type(version) is str and len(version) > 0):
144143
raise ValueError('Argument \'version\' should be a non-empty string')
145144

146-
if config._testmode:
147-
# It could already be in the name, for example when checking if a
148-
# downloaded flow exists on the server
149-
if config.testsentinel not in name:
150-
name = '%s%s' % (config.testsentinel, name)
151-
152145
return_code, xml_response = _perform_api_call(
153146
"flow/exists/%s/%s" % (name, version))
154147
# TODO check with latest version of code if this raises an exception

openml/testing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ def tearDown(self):
6666
os.chdir(self.cwd)
6767
shutil.rmtree(self.workdir)
6868

69-
openml.config._testmode = False
70-
7169
__all__ = ['TestBase']

tests/flows/test_flow.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import sys
12
import unittest
3+
24
from sklearn.dummy import DummyClassifier
35

46
from openml.testing import TestBase
57
import openml
68

9+
if sys.version_info[0] >= 3:
10+
from unittest import mock
11+
else:
12+
import mock
13+
714

815
class TestFlow(TestBase):
916
@unittest.skip('The method which is tested by this function doesnt exist')
@@ -17,9 +24,9 @@ def check_flow(flow):
1724
for flow in flows:
1825
check_flow(flow)
1926

20-
# @unittest.skip('Not tested until test sentinels are added back.')
21-
def test_upload_flow(self):
27+
@mock.patch.object(openml.OpenMLFlow, '_get_name', autospec=True)
28+
def test_upload_flow(self, name_mock):
2229
flow = openml.OpenMLFlow(model=DummyClassifier(), description="test description")
30+
name_mock.return_value = '%s%s' % (self.sentinel, flow.name)
2331
return_code, return_value = flow.publish()
24-
# self.assertTrue("This is a read-only account" in return_value)
2532
self.assertEqual(return_code, 200)

0 commit comments

Comments
 (0)