Skip to content

Commit a001782

Browse files
authored
Merge pull request #158 from openml/fix/add_sentinels
Fix/add sentinels
2 parents 4d0ea94 + f3950e1 commit a001782

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

openml/config.py

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

19+
1920
if sys.version_info[0] < 3:
2021
import ConfigParser as configparser
2122
from StringIO import StringIO

openml/flows/flow.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ def _generate_flow_xml(self):
5050
Flow represented as XML string.
5151
"""
5252
model = self.model
53+
5354
flow_dict = OrderedDict()
5455
flow_dict['oml:flow'] = OrderedDict()
5556
flow_dict['oml:flow']['@xmlns:oml'] = 'http://openml.org/openml'
56-
flow_dict['oml:flow']['oml:name'] = self.name
57+
flow_dict['oml:flow']['oml:name'] = self._get_name()
5758
flow_dict['oml:flow']['oml:external_version'] = self.external_version
5859
flow_dict['oml:flow']['oml:description'] = self.description
5960

@@ -103,7 +104,7 @@ def _ensure_flow_exists(self):
103104
"""
104105
import sklearn
105106
flow_version = 'sklearn_' + sklearn.__version__
106-
_, _, flow_id = _check_flow_exists(self.name, flow_version)
107+
_, _, flow_id = _check_flow_exists(self._get_name(), flow_version)
107108
# TODO add numpy and scipy version!
108109

109110
if int(flow_id) == -1:
@@ -115,6 +116,10 @@ def _ensure_flow_exists(self):
115116

116117
return int(flow_id)
117118

119+
def _get_name(self):
120+
"""Helper function. Can be mocked for testing."""
121+
return self.name
122+
118123

119124
def _check_flow_exists(name, version):
120125
"""Retrieves the flow id of the flow uniquely identified by name+version.

tests/flows/test_flow.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import hashlib
2+
import sys
3+
import time
14
import unittest
5+
26
from sklearn.dummy import DummyClassifier
37

48
from openml.testing import TestBase
59
import openml
610

11+
if sys.version_info[0] >= 3:
12+
from unittest import mock
13+
else:
14+
import mock
15+
716

817
class TestFlow(TestBase):
918
@unittest.skip('The method which is tested by this function doesnt exist')
@@ -17,8 +26,17 @@ def check_flow(flow):
1726
for flow in flows:
1827
check_flow(flow)
1928

20-
@unittest.skip('Not tested until test sentinels are added back.')
21-
def test_upload_flow(self):
29+
@mock.patch.object(openml.OpenMLFlow, '_get_name', autospec=True)
30+
def test_upload_flow(self, name_mock):
2231
flow = openml.OpenMLFlow(model=DummyClassifier(), description="test description")
32+
33+
# Create a unique prefix for the flow. Necessary because the flow is
34+
# identified by its name and external version online. Having a unique
35+
# name allows us to publish the same flow in each test run
36+
md5 = hashlib.md5()
37+
md5.update(str(time.time()).encode('utf-8'))
38+
sentinel = md5.hexdigest()[:10]
39+
name_mock.return_value = '%s%s' % (sentinel, flow.name)
40+
2341
flow.publish()
2442
self.assertIsInstance(flow.flow_id, int)

0 commit comments

Comments
 (0)