|
28 | 28 | from openml._api_calls import _perform_api_call |
29 | 29 | import openml |
30 | 30 | from openml.flows.sklearn_converter import _format_external_version |
| 31 | +import openml.exceptions |
31 | 32 |
|
32 | 33 |
|
33 | 34 | class TestFlow(TestBase): |
@@ -120,6 +121,50 @@ def test_publish_flow(self): |
120 | 121 | flow.publish() |
121 | 122 | self.assertIsInstance(flow.flow_id, int) |
122 | 123 |
|
| 124 | + def test_publish_existing_flow(self): |
| 125 | + clf = sklearn.tree.DecisionTreeClassifier(max_depth=2) |
| 126 | + flow = openml.flows.sklearn_to_flow(clf) |
| 127 | + flow, _ = self._add_sentinel_to_flow_name(flow, None) |
| 128 | + flow.publish() |
| 129 | + self.assertRaisesRegexp(openml.exceptions.OpenMLServerException, |
| 130 | + 'flow already exists', flow.publish) |
| 131 | + |
| 132 | + def test_publish_flow_with_similar_components(self): |
| 133 | + clf = sklearn.ensemble.VotingClassifier( |
| 134 | + [('lr', sklearn.linear_model.LogisticRegression())]) |
| 135 | + flow = openml.flows.sklearn_to_flow(clf) |
| 136 | + flow, _ = self._add_sentinel_to_flow_name(flow, None) |
| 137 | + flow.publish() |
| 138 | + # For a flow where both components are published together, the upload |
| 139 | + # date should be equal |
| 140 | + self.assertEqual(flow.upload_date, |
| 141 | + flow.components['lr'].upload_date, |
| 142 | + (flow.name, flow.flow_id, |
| 143 | + flow.components['lr'].name, flow.components['lr'].flow_id)) |
| 144 | + |
| 145 | + clf1 = sklearn.tree.DecisionTreeClassifier(max_depth=2) |
| 146 | + flow1 = openml.flows.sklearn_to_flow(clf1) |
| 147 | + flow1, sentinel = self._add_sentinel_to_flow_name(flow1, None) |
| 148 | + flow1.publish() |
| 149 | + |
| 150 | + clf2 = sklearn.ensemble.VotingClassifier( |
| 151 | + [('dt', sklearn.tree.DecisionTreeClassifier(max_depth=2))]) |
| 152 | + flow2 = openml.flows.sklearn_to_flow(clf2) |
| 153 | + flow2, _ = self._add_sentinel_to_flow_name(flow2, sentinel) |
| 154 | + flow2.publish() |
| 155 | + # If one component was published before the other, the components in |
| 156 | + # the flow should have different upload dates |
| 157 | + self.assertNotEqual(flow2.upload_date, |
| 158 | + flow2.components['dt'].upload_date) |
| 159 | + |
| 160 | + clf3 = sklearn.ensemble.AdaBoostClassifier( |
| 161 | + sklearn.tree.DecisionTreeClassifier(max_depth=3)) |
| 162 | + flow3 = openml.flows.sklearn_to_flow(clf3) |
| 163 | + flow3, _ = self._add_sentinel_to_flow_name(flow3, sentinel) |
| 164 | + # Child flow has different parameter. Check for storing the flow |
| 165 | + # correctly on the server should thus not check the child's parameters! |
| 166 | + flow3.publish() |
| 167 | + |
123 | 168 | def test_semi_legal_flow(self): |
124 | 169 | # TODO: Test if parameters are set correctly! |
125 | 170 | # should not throw error as it contains two differentiable forms of Bagging |
|
0 commit comments