1+ from time import time
2+
13from sklearn .ensemble import RandomForestClassifier , AdaBoostClassifier
24from sklearn .linear_model import LogisticRegression
35from sklearn .model_selection import RandomizedSearchCV , StratifiedKFold
46
57from openml .testing import TestBase
68from openml .flows .sklearn_converter import sklearn_to_flow
79from openml import OpenMLRun
10+ import openml
811
912
1013class TestRun (TestBase ):
11- # Splitting not helpful, these test's don't rely on the server and take less
12- # than 1 seconds
14+ # Splitting not helpful, these test's don't rely on the server and take
15+ # less than 1 seconds
1316
1417 def test_parse_parameters_flow_not_on_server (self ):
1518
1619 model = LogisticRegression ()
1720 flow = sklearn_to_flow (model )
18- self .assertRaisesRegexp (ValueError ,
19- 'Flow sklearn.linear_model.logistic.LogisticRegression '
20- 'has no flow_id!' ,
21- OpenMLRun ._parse_parameters , flow )
21+ self .assertRaisesRegexp (
22+ ValueError , 'Flow sklearn.linear_model.logistic.LogisticRegression'
23+ ' has no flow_id!' , OpenMLRun ._parse_parameters , flow )
2224
2325 model = AdaBoostClassifier (base_estimator = LogisticRegression ())
2426 flow = sklearn_to_flow (model )
2527 flow .flow_id = 1
26- self .assertRaisesRegexp (ValueError ,
27- 'Flow sklearn.linear_model.logistic.LogisticRegression '
28- 'has no flow_id!' ,
29- OpenMLRun ._parse_parameters , flow )
28+ self .assertRaisesRegexp (
29+ ValueError , 'Flow sklearn.linear_model.logistic.LogisticRegression'
30+ ' has no flow_id!' , OpenMLRun ._parse_parameters , flow )
3031
3132 def test_parse_parameters (self ):
3233
3334 model = RandomizedSearchCV (
3435 estimator = RandomForestClassifier (n_estimators = 5 ),
35- param_distributions = {"max_depth" : [ 3 , None ],
36- "max_features " : [1 , 2 , 3 , 4 ],
37- "min_samples_split " : [2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ],
38- "min_samples_leaf " : [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ],
39- "bootstrap" : [ True , False ],
40- "criterion" : ["gini" , "entropy" ]},
36+ param_distributions = {
37+ "max_depth " : [3 , None ],
38+ "max_features " : [1 , 2 , 3 , 4 ],
39+ "min_samples_split " : [2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ],
40+ "min_samples_leaf" : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ],
41+ "bootstrap" : [ True , False ], "criterion" : ["gini" , "entropy" ]},
4142 cv = StratifiedKFold (n_splits = 2 , random_state = 1 ),
4243 n_iter = 5 )
4344 flow = sklearn_to_flow (model )
@@ -49,3 +50,16 @@ def test_parse_parameters(self):
4950 if parameter ['oml:name' ] == 'n_estimators' :
5051 self .assertEqual (parameter ['oml:value' ], '5' )
5152 self .assertEqual (parameter ['oml:component' ], 2 )
53+
54+ def test_tagging (self ):
55+ run = openml .runs .get_run (1 )
56+ tag = "testing_tag_{}_{}" .format (self .id (), time ())
57+ run_list = openml .runs .list_runs (tag = tag )
58+ self .assertEqual (len (run_list ), 0 )
59+ run .push_tag (tag )
60+ run_list = openml .runs .list_runs (tag = tag )
61+ self .assertEqual (len (run_list ), 1 )
62+ self .assertIn (1 , run_list )
63+ run .remove_tag (tag )
64+ run_list = openml .runs .list_runs (tag = tag )
65+ self .assertEqual (len (run_list ), 0 )
0 commit comments