2323import 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+
2637class 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