Skip to content

Commit 3a90409

Browse files
committed
FIX adapt _check_flow_exists and test
1 parent 34243ac commit 3a90409

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

openml/_api_calls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _read_url_files(url, file_dictionary=None, file_elements=None):
7575
# 'gzip,deflate'
7676
response = requests.post(url, data=data, files=file_elements)
7777
if response.status_code != 200:
78-
raise OpenMLServerError(response.text)
78+
raise OpenMLServerError(('Status code: %d\n' % response.status_code) + response.text)
7979
if 'Content-Encoding' not in response.headers or \
8080
response.headers['Content-Encoding'] != 'gzip':
8181
warnings.warn('Received uncompressed content from OpenML for %s.' % url)
@@ -91,7 +91,7 @@ def _read_url(url):
9191
# 'gzip,deflate'
9292
response = requests.post(url, data=data)
9393
if response.status_code != 200:
94-
raise OpenMLServerError(response.text)
94+
raise OpenMLServerError(('Status code: %d\n' % response.status_code) + response.text)
9595
if 'Content-Encoding' not in response.headers or \
9696
response.headers['Content-Encoding'] != 'gzip':
9797
warnings.warn('Received uncompressed content from OpenML for %s.' % url)

openml/flows/flow.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,8 @@ def _ensure_flow_exists(self):
381381
# TODO add numpy and scipy version!
382382

383383
if int(flow_id) == -1:
384-
return_code, response_xml = self.publish()
385-
386-
response_dict = xmltodict.parse(response_xml)
387-
flow_id = response_dict['oml:upload_flow']['oml:id']
388-
return int(flow_id)
384+
flow = self.publish()
385+
return int(flow.flow_id)
389386

390387
return int(flow_id)
391388

@@ -416,6 +413,7 @@ def _check_flow_exists(name, version):
416413

417414
return_code, xml_response = _perform_api_call(
418415
"flow/exists/%s/%s" % (name, version))
416+
print(return_code)
419417
# TODO check with latest version of code if this raises an exception
420418
if return_code != 200:
421419
# fixme raise appropriate error

tests/flows/test_flow.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
import openml
2424

2525

26+
def get_sentinel():
27+
# Create a unique prefix for the flow. Necessary because the flow is
28+
# identified by its name and external version online. Having a unique
29+
# name allows us to publish the same flow in each test run
30+
md5 = hashlib.md5()
31+
md5.update(str(time.time()).encode('utf-8'))
32+
sentinel = md5.hexdigest()[:10]
33+
sentinel = 'TEST%s' % sentinel
34+
return sentinel
35+
36+
2637
class TestFlow(TestBase):
2738

2839
@unittest.skip('The method which is tested by this function doesnt exist')
@@ -102,12 +113,7 @@ def test_to_xml_from_xml(self):
102113
self.assertIsNot(new_flow, flow)
103114

104115
def test_publish_flow(self):
105-
# Create a unique prefix for the flow. Necessary because the flow is
106-
# identified by its name and external version online. Having a unique
107-
# name allows us to publish the same flow in each test run
108-
md5 = hashlib.md5()
109-
md5.update(str(time.time()).encode('utf-8'))
110-
sentinel = md5.hexdigest()[:10]
116+
sentinel = get_sentinel()
111117

112118
flow = openml.OpenMLFlow(name='Test',
113119
description="test description",
@@ -118,25 +124,35 @@ def test_publish_flow(self):
118124
external_version=str(sklearn.__version__),
119125
tags=[],
120126
language='English',
121-
dependencies=''
122-
)
127+
dependencies='')
123128
flow.name = 'TEST%s%s' % (sentinel, flow.name)
124129

125130
flow.publish()
126131
self.assertIsInstance(flow.flow_id, int)
127132

133+
def test_ensure_flow_exists(self):
134+
sentinel = get_sentinel()
135+
136+
flow = openml.OpenMLFlow(name='Test',
137+
description="test description",
138+
model=sklearn.dummy.DummyClassifier(),
139+
components=collections.OrderedDict(),
140+
parameters=collections.OrderedDict(),
141+
parameters_meta_info=collections.OrderedDict(),
142+
external_version=str(sklearn.__version__),
143+
tags=[],
144+
language='English',
145+
dependencies='')
146+
flow.name = 'TEST%s%s' % (sentinel, flow.name)
147+
flow_id = flow._ensure_flow_exists()
148+
self.assertIsInstance(flow_id, int)
149+
self.assertEqual(flow._ensure_flow_exists(), flow_id)
150+
128151
def test_sklearn_to_upload_to_flow(self):
129152
iris = sklearn.datasets.load_iris()
130153
X = iris.data
131154
y = iris.target
132-
133-
# Create a unique prefix for the flow. Necessary because the flow is
134-
# identified by its name and external version online. Having a unique
135-
# name allows us to publish the same flow in each test run
136-
md5 = hashlib.md5()
137-
md5.update(str(time.time()).encode('utf-8'))
138-
sentinel = md5.hexdigest()[:10]
139-
sentinel = 'TEST%s' % sentinel
155+
sentinel = get_sentinel()
140156

141157
# Test a more complicated flow
142158
ohe = sklearn.preprocessing.OneHotEncoder(categorical_features=[1])

0 commit comments

Comments
 (0)