File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616cachedir = ""
1717privatedir = ""
1818
19+
1920if sys .version_info [0 ] < 3 :
2021 import ConfigParser as configparser
2122 from StringIO import StringIO
Original file line number Diff line number Diff 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
119124def _check_flow_exists (name , version ):
120125 """Retrieves the flow id of the flow uniquely identified by name+version.
Original file line number Diff line number Diff line change 1+ import hashlib
2+ import sys
3+ import time
14import unittest
5+
26from sklearn .dummy import DummyClassifier
37
48from openml .testing import TestBase
59import openml
610
11+ if sys .version_info [0 ] >= 3 :
12+ from unittest import mock
13+ else :
14+ import mock
15+
716
817class 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 )
You can’t perform that action at this time.
0 commit comments