Skip to content

Commit 07b0db8

Browse files
committed
ADD add sentinel in front of flow names for unit tests
1 parent 244c585 commit 07b0db8

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

openml/config.py

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

19+
_testmode = False
20+
1921
if sys.version_info[0] < 3:
2022
import ConfigParser as configparser
2123
from StringIO import StringIO

openml/flows/flow.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sklearn
44

55
from .._api_calls import _perform_api_call
6+
from .. import config
67

78

89
class OpenMLFlow(object):
@@ -50,10 +51,16 @@ def _generate_flow_xml(self):
5051
Flow represented as XML string.
5152
"""
5253
model = self.model
54+
55+
if config._testmode:
56+
flow_name = '%s%s' % (config.testsentinel, self.name)
57+
else:
58+
flow_name = self.name
59+
5360
flow_dict = OrderedDict()
5461
flow_dict['oml:flow'] = OrderedDict()
5562
flow_dict['oml:flow']['@xmlns:oml'] = 'http://openml.org/openml'
56-
flow_dict['oml:flow']['oml:name'] = self.name
63+
flow_dict['oml:flow']['oml:name'] = flow_name
5764
flow_dict['oml:flow']['oml:external_version'] = self.external_version
5865
flow_dict['oml:flow']['oml:description'] = self.description
5966

@@ -136,6 +143,12 @@ def _check_flow_exists(name, version):
136143
if not (type(version) is str and len(version) > 0):
137144
raise ValueError('Argument \'version\' should be a non-empty string')
138145

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+
139152
return_code, xml_response = _perform_api_call(
140153
"flow/exists/%s/%s" % (name, version))
141154
# TODO check with latest version of code if this raises an exception

openml/testing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import inspect
23
import os
34
import shutil
@@ -39,6 +40,18 @@ def setUp(self):
3940
os.mkdir(self.workdir)
4041
os.chdir(self.workdir)
4142

43+
# Remove testmode once mock.wraps is available?
44+
openml.config._testmode = True
45+
apikey = openml.config.apikey
46+
pid = os.getpid()
47+
md5 = hashlib.md5()
48+
md5.update(apikey.encode('utf-8'))
49+
md5.update(str(pid).encode('utf-8'))
50+
sentinel = md5.hexdigest()
51+
# For testing the hash code mustn't be bulletproof
52+
self.sentinel = '%sTESTSENTINEL999' % sentinel[:8]
53+
openml.config.testsentinel = self.sentinel
54+
4255
self.cached = True
4356
# amueller's read/write key that he will throw away later
4457
openml.config.apikey = "610344db6388d9ba34f6db45a3cf71de"
@@ -49,4 +62,6 @@ def tearDown(self):
4962
os.chdir(self.cwd)
5063
shutil.rmtree(self.workdir)
5164

65+
openml.config._testmode = False
66+
5267
__all__ = ['TestBase']

tests/flows/test_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def check_flow(flow):
1717
for flow in flows:
1818
check_flow(flow)
1919

20-
@unittest.skip('Not tested until test sentinels are added back.')
20+
# @unittest.skip('Not tested until test sentinels are added back.')
2121
def test_upload_flow(self):
2222
flow = openml.OpenMLFlow(model=DummyClassifier(), description="test description")
2323
return_code, return_value = flow.publish()

0 commit comments

Comments
 (0)