From 11880aac716d0341aacc08fe9b81ba19ff7601ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Tue, 22 Sep 2015 22:56:45 +0200 Subject: [PATCH 1/8] Adding REST methods for scripts, executions and libraries --- HISTORY.rst | 5 + bigml/api.py | 17 ++- bigml/executionhandler.py | 120 +++++++++++++++++ bigml/libraryhandler.py | 131 +++++++++++++++++++ bigml/resourcehandler.py | 137 ++++++++++++++++++++ bigml/scripthandler.py | 132 +++++++++++++++++++ bigml/tests/compare_predictions_steps.py | 18 +++ bigml/tests/create_anomaly_steps.py | 17 +++ bigml/tests/create_cluster_steps.py | 4 +- bigml/tests/create_correlation_steps.py | 17 +++ bigml/tests/create_dataset_steps.py | 17 +++ bigml/tests/create_ensemble_steps.py | 2 +- bigml/tests/create_execution_steps.py | 82 ++++++++++++ bigml/tests/create_library_steps.py | 82 ++++++++++++ bigml/tests/create_multimodel_steps.py | 19 ++- bigml/tests/create_project_steps.py | 2 +- bigml/tests/create_sample_steps.py | 19 ++- bigml/tests/create_script_steps.py | 82 ++++++++++++ bigml/tests/create_statistical_tst_steps.py | 17 +++ bigml/tests/delete_project_steps.py | 2 +- bigml/tests/read_anomaly_steps.py | 18 ++- bigml/tests/read_batch_prediction_steps.py | 17 +++ bigml/tests/read_cluster_steps.py | 17 +++ bigml/tests/read_dataset_steps.py | 17 +++ bigml/tests/read_ensemble_steps.py | 18 ++- bigml/tests/read_evaluation_steps.py | 18 ++- bigml/tests/read_execution_steps.py | 26 ++++ bigml/tests/read_library_steps.py | 26 ++++ bigml/tests/read_model_steps.py | 18 +++ bigml/tests/read_prediction_steps.py | 17 +++ bigml/tests/read_project_steps.py | 2 +- bigml/tests/read_script_steps.py | 26 ++++ bigml/tests/read_source_steps.py | 2 +- bigml/tests/test_27_script.py | 61 +++++++++ bigml/tests/test_28_execution.py | 66 ++++++++++ bigml/tests/test_29_library.py | 61 +++++++++ bigml/tests/world.py | 4 + 37 files changed, 1320 insertions(+), 16 deletions(-) create mode 100644 bigml/executionhandler.py create mode 100644 bigml/libraryhandler.py create mode 100644 bigml/scripthandler.py create mode 100644 bigml/tests/create_execution_steps.py create mode 100644 bigml/tests/create_library_steps.py create mode 100644 bigml/tests/create_script_steps.py create mode 100644 bigml/tests/read_execution_steps.py create mode 100644 bigml/tests/read_library_steps.py create mode 100644 bigml/tests/read_script_steps.py create mode 100644 bigml/tests/test_27_script.py create mode 100644 bigml/tests/test_28_execution.py create mode 100644 bigml/tests/test_29_library.py diff --git a/HISTORY.rst b/HISTORY.rst index 68465be0..3f47659d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ------- +4.6.0 (2016-04-10) +~~~~~~~~~~~~~~~~~~ + +- Adding REST methods to manage new types of whizzml resources: scripts, + executions and libraries. 4.5.2 (2016-03-24) ~~~~~~~~~~~~~~~~~~ diff --git a/bigml/api.py b/bigml/api.py index aae450b7..16d4b4d8 100644 --- a/bigml/api.py +++ b/bigml/api.py @@ -59,6 +59,9 @@ from bigml.logistichandler import LogisticRegressionHandler from bigml.associationhandler import AssociationHandler from bigml.associationsethandler import AssociationSetHandler +from bigml.scripthandler import ScriptHandler +from bigml.executionhandler import ExecutionHandler +from bigml.libraryhandler import LibraryHandler # Repeating constants and functions for backwards compatibility @@ -83,8 +86,9 @@ SAMPLE_PATH, SAMPLE_RE, CORRELATION_PATH, CORRELATION_RE, STATISTICAL_TEST_PATH, STATISTICAL_TEST_RE, LOGISTIC_REGRESSION_PATH, LOGISTIC_REGRESSION_RE, ASSOCIATION_PATH, - ASSOCIATION_RE, ASSOCIATION_SET_PATH, ASSOCIATION_SET_RE) - + ASSOCIATION_RE, ASSOCIATION_SET_PATH, ASSOCIATION_SET_RE + SCRIPT_PATH, SCRIPT_RE, + EXECUTION_PATH, EXECUTION_RE, LIBRARY_PATH, LIBRARY_RE) from bigml.resourcehandler import ( get_resource, get_resource_type, check_resource_type, get_source_id, @@ -94,7 +98,8 @@ get_batch_anomaly_score_id, get_resource_id, resource_is_ready, get_status, check_resource, http_ok, get_project_id, get_sample_id, get_correlation_id, get_statistical_test_id, get_logistic_regression_id, - get_association_id, get_association_set_id) + get_association_id, get_association_set_id, get_script_id, + get_execution_id, get_library_id)) # Map status codes to labels @@ -120,7 +125,8 @@ def count(listing): return listing['meta']['query_total'] -class BigML(AssociationSetHandler, AssociationHandler, +class BigML(LibraryHandler, ExecutionHandler, ScriptHandler, + AssociationSetHandler, AssociationHandler, LogisticRegressionHandler, StatisticalTestHandler, CorrelationHandler, SampleHandler, ProjectHandler, @@ -190,6 +196,9 @@ def __init__(self, username=None, api_key=None, dev_mode=False, LogisticRegressionHandler.__init__(self) AssociationHandler.__init__(self) AssociationSetHandler.__init__(self) + ScriptHandler.__init__(self) + ExecutionHandler.__init__(self) + LibraryHandler.__init__(self) self.getters = {} for resource_type in RESOURCE_RE: diff --git a/bigml/executionhandler.py b/bigml/executionhandler.py new file mode 100644 index 00000000..c0a0f564 --- /dev/null +++ b/bigml/executionhandler.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Base class for whizzml script executions' REST calls + + https://bigml.com/developers/executions + +""" + +try: + import simplejson as json +except ImportError: + import json + + +from bigml.resourcehandler import ResourceHandler +from bigml.resourcehandler import (check_resource_type, + get_execution_id, get_resource_type, + get_script_id, check_resource) +from bigml.resourcehandler import (EXECUTION_PATH, SCRIPT_PATH, + TINY_RESOURCE) + + +class ExecutionHandler(ResourceHandler): + """This class is used by the BigML class as + a mixin that provides the executions' REST calls. It should not + be instantiated independently. + + """ + def __init__(self): + """Initializes the ExecutionHandler. This class is intended to be + used as a mixin on ResourceHandler, that inherits its + attributes and basic method from BigMLConnection, and must not be + instantiated independently. + + """ + self.execution_url = self.url + EXECUTION_PATH + + def create_execution(self, script, args=None, wait_time=3, retries=10): + """Creates an execution from a `script`. + + """ + script_id = None + resource_type = get_resource_type(script) + if resource_type == SCRIPT_PATH: + script_id = get_script_id(script) + check_resource(script_id, + query_string=TINY_RESOURCE, + wait_time=wait_time, retries=retries, + raise_on_error=True, api=self) + else: + raise Exception("A script id is needed to create a" + " script execution. %s found." % resource_type) + + create_args = {} + if args is not None: + create_args.update(args) + create_args.update({ + "script": script_id}) + + body = json.dumps(create_args) + return self._create(self.execution_url, body) + + def get_execution(self, execution, query_string=''): + """Retrieves an execution. + + The execution parameter should be a string containing the + execution id or the dict returned by create_execution. + As execution is an evolving object that is processed + until it reaches the FINISHED or FAULTY state, the function will + return a dict that encloses the execution contents and state info + available at the time it is called. + """ + check_resource_type(execution, EXECUTION_PATH, + message="An execution id is needed.") + execution_id = get_execution_id(execution) + if execution_id: + return self._get("%s%s" % (self.url, execution_id), + query_string=query_string) + + def list_executions(self, query_string=''): + """Lists all your executions. + + """ + return self._list(self.execution_url, query_string) + + def update_execution(self, execution, changes): + """Updates an execution. + + """ + check_resource_type(execution, EXECUTION_PATH, + message="An execution id is needed.") + execution_id = get_execution_id(execution) + if execution_id: + body = json.dumps(changes) + return self._update("%s%s" % (self.url, execution_id), body) + + def delete_execution(self, execution): + """Deletes an execution. + + """ + check_resource_type(execution, EXECUTION_PATH, + message="An execution id is needed.") + execution_id = get_execution_id(execution) + if execution_id: + return self._delete("%s%s" % (self.url, execution_id)) diff --git a/bigml/libraryhandler.py b/bigml/libraryhandler.py new file mode 100644 index 00000000..e7147cd0 --- /dev/null +++ b/bigml/libraryhandler.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Base class for whizzml libraries' REST calls + + https://bigml.com/developers/libraries + +""" + +try: + import simplejson as json +except ImportError: + import json + + +from bigml.resourcehandler import ResourceHandler +from bigml.resourcehandler import (check_resource_type, + get_library_id, get_resource_type, + check_resource) +from bigml.resourcehandler import (LIBRARY_PATH, TINY_RESOURCE) + + +class LibraryHandler(ResourceHandler): + """This class is used by the BigML class as + a mixin that provides the whizzml libraries' REST calls. It should not + be instantiated independently. + + """ + def __init__(self): + """Initializes the LibraryHandler. This class is intended to be + used as a mixin on ResourceHandler, that inherits its + attributes and basic method from BigMLConnection, and must not be + instantiated independently. + + """ + self.library_url = self.url + LIBRARY_PATH + + def create_library(self, source_code=None, args=None, + wait_time=3, retries=10): + """Creates a whizzml library from its source code. The `source_code` + parameter can be a: + {library ID}: the ID for an existing whizzml library + {string} : the string containing the source code for the library + + """ + create_args = {} + if args is not None: + create_args.update(args) + + if source_code is None: + raise Exception('A valid code string' + ' or a library id must be provided.') + resource_type = get_resource_type(source_code) + if resource_type == LIBRARY_PATH: + library_id = get_library_id(source_code) + if library_id: + check_resource(library_id, + query_string=TINY_RESOURCE, + wait_time=wait_time, retries=retries, + raise_on_error=True, api=self) + create_args.update({ + "origin": library_id}) + elif isinstance(source_code, basestring): + create_args.update({ + "source_code": source_code}) + else: + raise Exception("A library id or a valid source code" + " is needed to create a" + " library. %s found." % resource_type) + + + body = json.dumps(create_args) + return self._create(self.library_url, body) + + def get_library(self, library, query_string=''): + """Retrieves a library. + + The library parameter should be a string containing the + library id or the dict returned by create_script. + As library is an evolving object that is processed + until it reaches the FINISHED or FAULTY state, the function will + return a dict that encloses the library content and state info + available at the time it is called. + """ + check_resource_type(library, LIBRARY_PATH, + message="A library id is needed.") + library_id = get_library_id(library) + if library_id: + return self._get("%s%s" % (self.url, library_id), + query_string=query_string) + + def list_libraries(self, query_string=''): + """Lists all your libraries. + + """ + return self._list(self.library_url, query_string) + + def update_library(self, library, changes): + """Updates a library. + + """ + check_resource_type(library, LIBRARY_PATH, + message="A library id is needed.") + library_id = get_library_id(library) + if library_id: + body = json.dumps(changes) + return self._update("%s%s" % (self.url, library_id), body) + + def delete_library(self, library): + """Deletes a library. + + """ + check_resource_type(library, LIBRARY_PATH, + message="A library id is needed.") + library_id = get_library_id(library) + if library_id: + return self._delete("%s%s" % (self.url, library_id)) diff --git a/bigml/resourcehandler.py b/bigml/resourcehandler.py index e72dd3f0..2474b40a 100644 --- a/bigml/resourcehandler.py +++ b/bigml/resourcehandler.py @@ -28,11 +28,127 @@ from bigml.bigmlconnection import BigMLConnection +# Basic resources +SOURCE_PATH = 'source' +DATASET_PATH = 'dataset' +MODEL_PATH = 'model' +PREDICTION_PATH = 'prediction' +EVALUATION_PATH = 'evaluation' +ENSEMBLE_PATH = 'ensemble' +BATCH_PREDICTION_PATH = 'batchprediction' +CLUSTER_PATH = 'cluster' +CENTROID_PATH = 'centroid' +BATCH_CENTROID_PATH = 'batchcentroid' +ANOMALY_PATH = 'anomaly' +ANOMALY_SCORE_PATH = 'anomalyscore' +BATCH_ANOMALY_SCORE_PATH = 'batchanomalyscore' +PROJECT_PATH = 'project' +SAMPLE_PATH = 'sample' +CORRELATION_PATH = 'correlation' +STATISTICAL_TEST_PATH = 'statisticaltest' +SCRIPT_PATH = 'script' +EXECUTION_PATH = 'execution' +LIBRARY_PATH = 'library' + +# Resource Ids patterns +ID_PATTERN = '[a-f0-9]{24}' +SHARED_PATTERN = '[a-zA-Z0-9]{24,30}' +SOURCE_RE = re.compile(r'^%s/%s$' % (SOURCE_PATH, ID_PATTERN)) +# public resources: model and dataset +# shared resources: all except sources +DATASET_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( + DATASET_PATH, ID_PATTERN, DATASET_PATH, SHARED_PATTERN)) +MODEL_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( + MODEL_PATH, ID_PATTERN, MODEL_PATH, SHARED_PATTERN)) +# +PREDICTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + PREDICTION_PATH, ID_PATTERN, PREDICTION_PATH, SHARED_PATTERN)) +EVALUATION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + EVALUATION_PATH, ID_PATTERN, EVALUATION_PATH, SHARED_PATTERN)) +ENSEMBLE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + ENSEMBLE_PATH, ID_PATTERN, ENSEMBLE_PATH, SHARED_PATTERN)) +BATCH_PREDICTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + BATCH_PREDICTION_PATH, ID_PATTERN, BATCH_PREDICTION_PATH, SHARED_PATTERN)) +CLUSTER_RE = re.compile(r'^%s/%s$|^shared/%s/%s$' % ( + CLUSTER_PATH, ID_PATTERN, CLUSTER_PATH, SHARED_PATTERN)) +CENTROID_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + CENTROID_PATH, ID_PATTERN, CENTROID_PATH, SHARED_PATTERN)) +BATCH_CENTROID_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + BATCH_CENTROID_PATH, ID_PATTERN, BATCH_CENTROID_PATH, SHARED_PATTERN)) +ANOMALY_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( + ANOMALY_PATH, ID_PATTERN, ANOMALY_PATH, SHARED_PATTERN)) +ANOMALY_SCORE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + ANOMALY_SCORE_PATH, ID_PATTERN, ANOMALY_SCORE_PATH, SHARED_PATTERN)) +BATCH_ANOMALY_SCORE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + BATCH_ANOMALY_SCORE_PATH, ID_PATTERN, + BATCH_ANOMALY_SCORE_PATH, SHARED_PATTERN)) +PROJECT_RE = re.compile(r'^%s/%s$' % (PROJECT_PATH, ID_PATTERN)) +SAMPLE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + SAMPLE_PATH, ID_PATTERN, SAMPLE_PATH, SHARED_PATTERN)) +CORRELATION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( + CORRELATION_PATH, ID_PATTERN, CORRELATION_PATH, SHARED_PATTERN)) +STATISTICAL_TEST_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (STATISTICAL_TEST_PATH, ID_PATTERN, STATISTICAL_TEST_PATH, SHARED_PATTERN)) +SCRIPT_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (SCRIPT_PATH, ID_PATTERN, SCRIPT_PATH, SHARED_PATTERN)) +EXECUTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (EXECUTION_PATH, ID_PATTERN, EXECUTION_PATH, SHARED_PATTERN)) +LIBRARY_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (LIBRARY_PATH, ID_PATTERN, LIBRARY_PATH, SHARED_PATTERN)) + +RESOURCE_RE = { + 'source': SOURCE_RE, + 'dataset': DATASET_RE, + 'model': MODEL_RE, + 'prediction': PREDICTION_RE, + 'evaluation': EVALUATION_RE, + 'ensemble': ENSEMBLE_RE, + 'batchprediction': BATCH_PREDICTION_RE, + 'cluster': CLUSTER_RE, + 'centroid': CENTROID_RE, + 'batchcentroid': BATCH_CENTROID_RE, + 'anomaly': ANOMALY_RE, + 'anomalyscore': ANOMALY_SCORE_RE, + 'batchanomalyscore': BATCH_ANOMALY_SCORE_RE, + 'project': PROJECT_RE, + 'sample': SAMPLE_RE, + 'correlation': CORRELATION_RE, + 'statisticaltest': STATISTICAL_TEST_RE, + 'script': SCRIPT_RE, + 'execution': EXECUTION_RE, + 'library': LIBRARY_RE} + + +RENAMED_RESOURCES = { + 'batchprediction': 'batch_prediction', + 'batchcentroid': 'batch_centroid', + 'anomalyscore': 'anomaly_score', + 'batchanomalyscore': 'batch_anomaly_score', + 'statisticaltest': 'statistical_test' +} + NO_QS = [c.EVALUATION_RE, c.PREDICTION_RE, c.BATCH_PREDICTION_RE, c.CENTROID_RE, c.BATCH_CENTROID_RE, c.ANOMALY_SCORE_RE, c.BATCH_ANOMALY_SCORE_RE, c.PROJECT_RE, c.ASSOCIATION_SET_RE] +# Resource status codes +WAITING = 0 +QUEUED = 1 +STARTED = 2 +IN_PROGRESS = 3 +SUMMARIZED = 4 +FINISHED = 5 +UPLOADING = 6 +FAULTY = -1 +UNKNOWN = -2 +RUNNABLE = -3 + + +# Minimum query string to get model fields +TINY_RESOURCE = "full=false" + + def get_resource_type(resource): """Returns the associated resource type for a resource @@ -244,6 +360,27 @@ def get_association_set_id(association_set): return get_resource(c.ASSOCIATION_SET_PATH, association_set) +def get_script_id(script): + """Returns a script/id. + + """ + return get_resource(SCRIPT_RE, script) + + +def get_execution_id(execution): + """Returns a execution/id. + + """ + return get_resource(EXECUTION_RE, execution) + + +def get_library_id(library): + """Returns a library/id. + + """ + return get_resource(LIBRARY_RE, library) + + def get_resource_id(resource): """Returns the resource id if it falls in one of the registered types diff --git a/bigml/scripthandler.py b/bigml/scripthandler.py new file mode 100644 index 00000000..fab1252a --- /dev/null +++ b/bigml/scripthandler.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Base class for whizzml script' REST calls + + https://bigml.com/developers/scripts + +""" + +try: + import simplejson as json +except ImportError: + import json + + +from bigml.resourcehandler import ResourceHandler +from bigml.resourcehandler import (check_resource_type, + get_script_id, get_resource_type, + get_dataset_id, check_resource) +from bigml.resourcehandler import (SCRIPT_PATH, DATASET_PATH, + TINY_RESOURCE) + + +class ScriptHandler(ResourceHandler): + """This class is used by the BigML class as + a mixin that provides the whizzml script' REST calls. It should not + be instantiated independently. + + """ + def __init__(self): + """Initializes the ScriptHandler. This class is intended to be + used as a mixin on ResourceHandler, that inherits its + attributes and basic method from BigMLConnection, and must not be + instantiated independently. + + """ + self.script_url = self.url + SCRIPT_PATH + + def create_script(self, source_code=None, args=None, + wait_time=3, retries=10): + """Creates a whizzml script from its source code. The `source_code` + parameter can be a: + {script ID}: the ID for an existing whizzml script + {string} : the string containing the source code for the script + + """ + create_args = {} + if args is not None: + create_args.update(args) + + if source_code is None: + raise Exception('A valid code string' + ' or a script id must be provided.') + resource_type = get_resource_type(source_code) + if resource_type == SCRIPT_PATH: + script_id = get_script_id(source_code) + if script_id: + check_resource(script_id, + query_string=TINY_RESOURCE, + wait_time=wait_time, retries=retries, + raise_on_error=True, api=self) + create_args.update({ + "origin": script_id}) + elif isinstance(source_code, basestring): + create_args.update({ + "source_code": source_code}) + else: + raise Exception("A script id or a valid source code" + " is needed to create a" + " script. %s found." % resource_type) + + + body = json.dumps(create_args) + return self._create(self.script_url, body) + + def get_script(self, script, query_string=''): + """Retrieves a script. + + The script parameter should be a string containing the + script id or the dict returned by create_script. + As script is an evolving object that is processed + until it reaches the FINISHED or FAULTY state, the function will + return a dict that encloses the script content and state info + available at the time it is called. + """ + check_resource_type(script, SCRIPT_PATH, + message="A script id is needed.") + script_id = get_script_id(script) + if script_id: + return self._get("%s%s" % (self.url, script_id), + query_string=query_string) + + def list_scripts(self, query_string=''): + """Lists all your scripts. + + """ + return self._list(self.script_url, query_string) + + def update_script(self, script, changes): + """Updates a script. + + """ + check_resource_type(script, SCRIPT_PATH, + message="A script id is needed.") + script_id = get_script_id(script) + if script_id: + body = json.dumps(changes) + return self._update("%s%s" % (self.url, script_id), body) + + def delete_script(self, script): + """Deletes a script. + + """ + check_resource_type(script, SCRIPT_PATH, + message="A script id is needed.") + script_id = get_script_id(script) + if script_id: + return self._delete("%s%s" % (self.url, script_id)) diff --git a/bigml/tests/compare_predictions_steps.py b/bigml/tests/compare_predictions_steps.py index f4df9389..3d47f474 100644 --- a/bigml/tests/compare_predictions_steps.py +++ b/bigml/tests/compare_predictions_steps.py @@ -1,3 +1,21 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + import json import os from world import world, res_filename diff --git a/bigml/tests/create_anomaly_steps.py b/bigml/tests/create_anomaly_steps.py index 78416275..456253cb 100644 --- a/bigml/tests/create_anomaly_steps.py +++ b/bigml/tests/create_anomaly_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2014-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import time import json import os diff --git a/bigml/tests/create_cluster_steps.py b/bigml/tests/create_cluster_steps.py index b0873d84..5a3e53b2 100644 --- a/bigml/tests/create_cluster_steps.py +++ b/bigml/tests/create_cluster_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2012 BigML +# Copyright 2012-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -105,7 +105,7 @@ def cluster_from_shared_url(step): #@step(r'I check the cluster status using the model\'s shared key') def cluster_from_shared_key(step): - + username = os.environ.get("BIGML_USERNAME") world.cluster = world.api.get_cluster(world.cluster['resource'], shared_username=username, shared_api_key=world.sharing_key) diff --git a/bigml/tests/create_correlation_steps.py b/bigml/tests/create_correlation_steps.py index db35bcca..777ea507 100644 --- a/bigml/tests/create_correlation_steps.py +++ b/bigml/tests/create_correlation_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import time import json import os diff --git a/bigml/tests/create_dataset_steps.py b/bigml/tests/create_dataset_steps.py index f2260ba3..35766931 100644 --- a/bigml/tests/create_dataset_steps.py +++ b/bigml/tests/create_dataset_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import time import json from datetime import datetime, timedelta diff --git a/bigml/tests/create_ensemble_steps.py b/bigml/tests/create_ensemble_steps.py index 0ded93ba..0a13df73 100644 --- a/bigml/tests/create_ensemble_steps.py +++ b/bigml/tests/create_ensemble_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2012 BigML +# Copyright 2012-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/bigml/tests/create_execution_steps.py b/bigml/tests/create_execution_steps.py new file mode 100644 index 00000000..122aa29d --- /dev/null +++ b/bigml/tests/create_execution_steps.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import time +import json +import os +from datetime import datetime, timedelta +from world import world + +from bigml.api import HTTP_CREATED +from bigml.api import HTTP_ACCEPTED +from bigml.api import FINISHED +from bigml.api import FAULTY +from bigml.api import get_status + +from read_execution_steps import i_get_the_execution + + +#@step(r'the script id is correct and the value of "(.*)" is "(.*)"') +def the_execution_and_attributes(step, param, param_value): + res_param_value = world.execution[param] + if res_param_value == param_value: + assert True + else: + assert False, ("The execution %s is %s " + "and the expected %s is %s" % + (param, param_value, param, param_value)) + + +#@step(r'I create a whizzml execution from an existing script"$') +def i_create_an_execution(step): + resource = world.api.create_execution(world.script) + world.status = resource['code'] + assert world.status == HTTP_CREATED + world.location = resource['location'] + world.execution = resource['object'] + world.executions.append(resource['resource']) + + +#@step(r'I update the execution with "(.*)", "(.*)"$') +def i_update_an_execution(step, param, param_value): + resource = world.api.update_execution(world.execution['resource'], + {param: param_value}) + world.status = resource['code'] + assert world.status == HTTP_ACCEPTED + world.location = resource['location'] + world.execution = resource['object'] + + +#@step(r'I wait until the execution status code is either (\d) or (-\d) less than (\d+)') +def wait_until_execution_status_code_is(step, code1, code2, secs): + start = datetime.utcnow() + execution_id = world.execution['resource'] + i_get_the_execution(step, execution_id) + status = get_status(world.execution) + while (status['code'] != int(code1) and + status['code'] != int(code2)): + time.sleep(3) + assert datetime.utcnow() - start < timedelta(seconds=int(secs)) + i_get_the_execution(step, execution_id) + status = get_status(world.execution) + print "***", status + assert status['code'] == int(code1) + + +#@step(r'I wait until the script is ready less than (\d+)') +def the_execution_is_finished(step, secs): + wait_until_execution_status_code_is(step, FINISHED, FAULTY, secs) diff --git a/bigml/tests/create_library_steps.py b/bigml/tests/create_library_steps.py new file mode 100644 index 00000000..36d0f752 --- /dev/null +++ b/bigml/tests/create_library_steps.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import time +import json +import os +from datetime import datetime, timedelta +from world import world + +from bigml.api import HTTP_CREATED +from bigml.api import HTTP_ACCEPTED +from bigml.api import FINISHED +from bigml.api import FAULTY +from bigml.api import get_status + +from read_library_steps import i_get_the_library + + +#@step(r'the library code is "(.*)" and the value of "(.*)" is "(.*)"') +def the_library_code_and_attributes(step, source_code, param, param_value): + res_param_value = world.library[param] + if res_param_value == param_value: + assert True + else: + assert False, ("The library %s is %s " + "and the expected %s is %s" % + (param, param_value, param, param_value)) + + +#@step(r'I create a whizzml library from a excerpt of code "(.*)"$') +def i_create_a_library(step, source_code): + resource = world.api.create_library(source_code) + world.status = resource['code'] + assert world.status == HTTP_CREATED + world.location = resource['location'] + world.library = resource['object'] + world.libraries.append(resource['resource']) + + +#@step(r'I update the library with "(.*)", "(.*)"$') +def i_update_a_library(step, param, param_value): + resource = world.api.update_library(world.library['resource'], + {param: param_value}) + world.status = resource['code'] + assert world.status == HTTP_ACCEPTED + world.location = resource['location'] + world.library = resource['object'] + + +#@step(r'I wait until the library status code is either (\d) or (-\d) less than (\d+)') +def wait_until_library_status_code_is(step, code1, code2, secs): + start = datetime.utcnow() + library_id = world.library['resource'] + i_get_the_library(step, library_id) + status = get_status(world.library) + while (status['code'] != int(code1) and + status['code'] != int(code2)): + time.sleep(3) + assert datetime.utcnow() - start < timedelta(seconds=int(secs)) + i_get_the_library(step, library_id) + status = get_status(world.library) + print "***", status + assert status['code'] == int(code1) + + +#@step(r'I wait until the library is ready less than (\d+)') +def the_library_is_finished(step, secs): + wait_until_library_status_code_is(step, FINISHED, FAULTY, secs) diff --git a/bigml/tests/create_multimodel_steps.py b/bigml/tests/create_multimodel_steps.py index c2d3902c..01c8a6cc 100644 --- a/bigml/tests/create_multimodel_steps.py +++ b/bigml/tests/create_multimodel_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2014-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + from world import world #@step(r'I store the dataset id in a list') @@ -13,4 +30,4 @@ def i_check_model_datasets_and_datasets_ids(step): assert False, ("The model contains only %s " "and the dataset ids are %s" % (",".join(model['datasets']), - ",".join(world.dataset_ids))) + ",".join(world.dataset_ids))) diff --git a/bigml/tests/create_project_steps.py b/bigml/tests/create_project_steps.py index 2fdf75bc..c017b182 100644 --- a/bigml/tests/create_project_steps.py +++ b/bigml/tests/create_project_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2014 BigML +# Copyright 2014-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/bigml/tests/create_sample_steps.py b/bigml/tests/create_sample_steps.py index cb72341b..8971ac5a 100644 --- a/bigml/tests/create_sample_steps.py +++ b/bigml/tests/create_sample_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import time import json import os @@ -58,7 +75,7 @@ def wait_until_sample_status_code_is(step, code1, code2, secs): i_get_the_sample(step, sample_id) status = get_status(world.sample) assert status['code'] == int(code1) - + #@step(r'I wait until the sample is ready less than (\d+)') def the_sample_is_finished_in_less_than(step, secs): diff --git a/bigml/tests/create_script_steps.py b/bigml/tests/create_script_steps.py new file mode 100644 index 00000000..bf45a3ed --- /dev/null +++ b/bigml/tests/create_script_steps.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import time +import json +import os +from datetime import datetime, timedelta +from world import world + +from bigml.api import HTTP_CREATED +from bigml.api import HTTP_ACCEPTED +from bigml.api import FINISHED +from bigml.api import FAULTY +from bigml.api import get_status + +from read_script_steps import i_get_the_script + + +#@step(r'the script code is "(.*)" and the value of "(.*)" is "(.*)"') +def the_script_code_and_attributes(step, source_code, param, param_value): + res_param_value = world.script[param] + if res_param_value == param_value: + assert True + else: + assert False, ("The script %s is %s " + "and the expected %s is %s" % + (param, param_value, param, param_value)) + + +#@step(r'I create a whizzml script from a excerpt of code "(.*)"$') +def i_create_a_script(step, source_code): + resource = world.api.create_script(source_code) + world.status = resource['code'] + assert world.status == HTTP_CREATED + world.location = resource['location'] + world.script = resource['object'] + world.scripts.append(resource['resource']) + + +#@step(r'I update the script with "(.*)", "(.*)"$') +def i_update_a_script(step, param, param_value): + resource = world.api.update_script(world.script['resource'], + {param: param_value}) + world.status = resource['code'] + assert world.status == HTTP_ACCEPTED + world.location = resource['location'] + world.script = resource['object'] + + +#@step(r'I wait until the script status code is either (\d) or (-\d) less than (\d+)') +def wait_until_script_status_code_is(step, code1, code2, secs): + start = datetime.utcnow() + script_id = world.script['resource'] + i_get_the_script(step, script_id) + status = get_status(world.script) + while (status['code'] != int(code1) and + status['code'] != int(code2)): + time.sleep(3) + assert datetime.utcnow() - start < timedelta(seconds=int(secs)) + i_get_the_script(step, script_id) + status = get_status(world.script) + print "***", status + assert status['code'] == int(code1) + + +#@step(r'I wait until the script is ready less than (\d+)') +def the_script_is_finished(step, secs): + wait_until_script_status_code_is(step, FINISHED, FAULTY, secs) diff --git a/bigml/tests/create_statistical_tst_steps.py b/bigml/tests/create_statistical_tst_steps.py index f956dfb8..1ba8fc0c 100644 --- a/bigml/tests/create_statistical_tst_steps.py +++ b/bigml/tests/create_statistical_tst_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import time import json import os diff --git a/bigml/tests/delete_project_steps.py b/bigml/tests/delete_project_steps.py index 386607c7..a9660785 100644 --- a/bigml/tests/delete_project_steps.py +++ b/bigml/tests/delete_project_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2014 BigML +# Copyright 2014-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/bigml/tests/read_anomaly_steps.py b/bigml/tests/read_anomaly_steps.py index 1ba72faf..4c065ebd 100644 --- a/bigml/tests/read_anomaly_steps.py +++ b/bigml/tests/read_anomaly_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2014-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world @@ -9,4 +26,3 @@ def i_get_the_anomaly(step, anomaly): world.status = resource['code'] assert world.status == HTTP_OK world.anomaly = resource['object'] - diff --git a/bigml/tests/read_batch_prediction_steps.py b/bigml/tests/read_batch_prediction_steps.py index fd70646c..857e9dbe 100644 --- a/bigml/tests/read_batch_prediction_steps.py +++ b/bigml/tests/read_batch_prediction_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world diff --git a/bigml/tests/read_cluster_steps.py b/bigml/tests/read_cluster_steps.py index 3b1f28fe..1af50065 100644 --- a/bigml/tests/read_cluster_steps.py +++ b/bigml/tests/read_cluster_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world diff --git a/bigml/tests/read_dataset_steps.py b/bigml/tests/read_dataset_steps.py index 8d263d01..eebfcd89 100644 --- a/bigml/tests/read_dataset_steps.py +++ b/bigml/tests/read_dataset_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import json from world import world diff --git a/bigml/tests/read_ensemble_steps.py b/bigml/tests/read_ensemble_steps.py index f8ffc334..382183ae 100644 --- a/bigml/tests/read_ensemble_steps.py +++ b/bigml/tests/read_ensemble_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world @@ -9,4 +26,3 @@ def i_get_the_ensemble(step, ensemble): world.status = resource['code'] assert world.status == HTTP_OK world.ensemble = resource['object'] - diff --git a/bigml/tests/read_evaluation_steps.py b/bigml/tests/read_evaluation_steps.py index 2721b8d8..36abb890 100644 --- a/bigml/tests/read_evaluation_steps.py +++ b/bigml/tests/read_evaluation_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world @@ -9,4 +26,3 @@ def i_get_the_evaluation(step, evaluation): world.status = resource['code'] assert world.status == HTTP_OK world.evaluation = resource['object'] - diff --git a/bigml/tests/read_execution_steps.py b/bigml/tests/read_execution_steps.py new file mode 100644 index 00000000..971f05a8 --- /dev/null +++ b/bigml/tests/read_execution_steps.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from world import world +from bigml.api import HTTP_OK + +#@step(r'I get the execution "(.*)"') +def i_get_the_execution(step, resource): + resource = world.api.get_execution(resource) + world.status = resource['code'] + assert world.status == HTTP_OK + world.execution = resource['object'] diff --git a/bigml/tests/read_library_steps.py b/bigml/tests/read_library_steps.py new file mode 100644 index 00000000..24cf9be9 --- /dev/null +++ b/bigml/tests/read_library_steps.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from world import world +from bigml.api import HTTP_OK + +#@step(r'I get the library "(.*)"') +def i_get_the_library(step, resource): + resource = world.api.get_library(resource) + world.status = resource['code'] + assert world.status == HTTP_OK + world.library = resource['object'] diff --git a/bigml/tests/read_model_steps.py b/bigml/tests/read_model_steps.py index 56bd3c7a..e3a9f2a2 100644 --- a/bigml/tests/read_model_steps.py +++ b/bigml/tests/read_model_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world @@ -10,6 +27,7 @@ def i_get_the_model(step, model): assert world.status == HTTP_OK world.model = resource['object'] + #@step(r'I get the logistic regression model "(.*)"') def i_get_the_logistic_model(step, model): resource = world.api.get_logistic_regression(model) diff --git a/bigml/tests/read_prediction_steps.py b/bigml/tests/read_prediction_steps.py index 0e3dc653..d662b5bf 100644 --- a/bigml/tests/read_prediction_steps.py +++ b/bigml/tests/read_prediction_steps.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2012-2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from world import world from bigml.api import HTTP_OK diff --git a/bigml/tests/read_project_steps.py b/bigml/tests/read_project_steps.py index 80e08f80..39089e2a 100644 --- a/bigml/tests/read_project_steps.py +++ b/bigml/tests/read_project_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2014 BigML +# Copyright 2014-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/bigml/tests/read_script_steps.py b/bigml/tests/read_script_steps.py new file mode 100644 index 00000000..d9cf22f7 --- /dev/null +++ b/bigml/tests/read_script_steps.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from world import world +from bigml.api import HTTP_OK + +#@step(r'I get the script "(.*)"') +def i_get_the_script(step, resource): + resource = world.api.get_script(resource) + world.status = resource['code'] + assert world.status == HTTP_OK + world.script = resource['object'] diff --git a/bigml/tests/read_source_steps.py b/bigml/tests/read_source_steps.py index 702bc9de..4c2c1514 100644 --- a/bigml/tests/read_source_steps.py +++ b/bigml/tests/read_source_steps.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- #!/usr/bin/env python # -# Copyright 2012 BigML +# Copyright 2012-2015 BigML # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/bigml/tests/test_27_script.py b/bigml/tests/test_27_script.py new file mode 100644 index 00000000..47ab0a62 --- /dev/null +++ b/bigml/tests/test_27_script.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +""" Creating and updating scripts + +""" +from world import world, setup_module, teardown_module +import create_script_steps as script_create + +class TestScript(object): + + def setup(self): + """ + Debug information + """ + print "\n-------------------\nTests in: %s\n" % __name__ + + def teardown(self): + """ + Debug information + """ + print "\nEnd of tests in: %s\n-------------------\n" % __name__ + + def test_scenario1(self): + """ + Scenario: Successfully creating a whizzml script: + Given I create a whizzml script from a excerpt of code "" + And I wait until the script is ready less than secs + And I update the script with "", "" + And I wait until the script is ready less than secs + Then the script code is "" and the value of "" is "" + + Examples: + | source_code | time_1 | time_2 | param | param_value + | (+ 1 1) | 10 | 10 | name | my script + """ + print self.test_scenario1.__doc__ + examples = [ + ['(+ 1 1)', '10', '10', 'name', 'my script']] + for example in examples: + print "\nTesting with:\n", example + script_create.i_create_a_script(self, example[0]) + script_create.the_script_is_finished(self, example[1]) + script_create.i_update_a_script(self, example[3], example[4]) + script_create.the_script_is_finished(self, example[2]) + script_create.the_script_code_and_attributes(self, example[0], example[3], example[4]) diff --git a/bigml/tests/test_28_execution.py b/bigml/tests/test_28_execution.py new file mode 100644 index 00000000..7cc8eb6f --- /dev/null +++ b/bigml/tests/test_28_execution.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +""" Creating and updating scripts + +""" +from world import world, setup_module, teardown_module +import create_script_steps as script_create +import create_execution_steps as execution_create + +class TestExecution(object): + + def setup(self): + """ + Debug information + """ + print "\n-------------------\nTests in: %s\n" % __name__ + + def teardown(self): + """ + Debug information + """ + print "\nEnd of tests in: %s\n-------------------\n" % __name__ + + def test_scenario1(self): + """ + Scenario: Successfully creating a whizzml script execution: + Given I create a whizzml script from a excerpt of code "" + And I wait until the script is ready less than secs + And I create a whizzml script execution from an existing script + And I wait until the execution is ready less than secs + And I update the execution with "", "" + And I wait until the execution is ready less than secs + Then the script id is correct and the value of "" is "" + + Examples: + | source_code | time_1 | time_2 | time_3 | param | param_value + | (+ 1 1) | 10 | 10 | 10 | name | my execution + """ + print self.test_scenario1.__doc__ + examples = [ + ['(+ 1 1)', '10', '10', '10', 'name', 'my execution']] + for example in examples: + print "\nTesting with:\n", example + script_create.i_create_a_script(self, example[0]) + script_create.the_script_is_finished(self, example[1]) + execution_create.i_create_an_execution(self) + execution_create.the_execution_is_finished(self, example[2]) + execution_create.i_update_an_execution(self, example[4], example[5]) + execution_create.the_execution_is_finished(self, example[3]) + execution_create.the_execution_and_attributes(self, example[4], example[5]) diff --git a/bigml/tests/test_29_library.py b/bigml/tests/test_29_library.py new file mode 100644 index 00000000..885e63f2 --- /dev/null +++ b/bigml/tests/test_29_library.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +# +# Copyright 2015 BigML +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +""" Creating and updating scripts + +""" +from world import world, setup_module, teardown_module +import create_library_steps as library_create + +class TestLibrary(object): + + def setup(self): + """ + Debug information + """ + print "\n-------------------\nTests in: %s\n" % __name__ + + def teardown(self): + """ + Debug information + """ + print "\nEnd of tests in: %s\n-------------------\n" % __name__ + + def test_scenario1(self): + """ + Scenario: Successfully creating a whizzml library: + Given I create a whizzml library from a excerpt of code "" + And I wait until the library is ready less than secs + And I update the library with "", "" + And I wait until the library is ready less than secs + Then the library code is "" and the value of "" is "" + + Examples: + | source_code | time_1 | time_2 | param | param_value + | (define (mu x) (+ x 1)) | 10 | 10 | name | my library + """ + print self.test_scenario1.__doc__ + examples = [ + ['(define (mu x) (+ x 1))', '10', '10', 'name', 'my library']] + for example in examples: + print "\nTesting with:\n", example + library_create.i_create_a_library(self, example[0]) + library_create.the_library_is_finished(self, example[1]) + library_create.i_update_a_library(self, example[3], example[4]) + library_create.the_library_is_finished(self, example[2]) + library_create.the_library_code_and_attributes(self, example[0], example[3], example[4]) diff --git a/bigml/tests/world.py b/bigml/tests/world.py index eff48f6f..fc55427c 100644 --- a/bigml/tests/world.py +++ b/bigml/tests/world.py @@ -49,6 +49,9 @@ 'statisticaltest', 'logisticregression', 'association' + 'script', + 'execution', + 'library' ] IRREGULAR_PLURALS = { 'anomaly': 'anomalies', @@ -58,6 +61,7 @@ 'batchanomalyscore': 'batch_anomaly_scores', 'statisticaltest': 'statistical_tests', 'logisticregression': 'logistic_regressions' + 'library': 'libraries' } TRANSLATED_RESOURCES = { 'batchprediction': 'batch_prediction', From 2e82ba19ad84fc3ecb3c4ce02efa562c47de43e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Wed, 23 Sep 2015 21:40:10 +0200 Subject: [PATCH 2/8] Allowing the api.create_execution method to use lists of scripts as argument --- bigml/executionhandler.py | 44 ++++++++++++++++++--------- bigml/tests/create_execution_steps.py | 28 +++++++++++++++-- bigml/tests/create_library_steps.py | 1 - bigml/tests/create_script_steps.py | 1 - bigml/tests/test_28_execution.py | 32 +++++++++++++++++++ 5 files changed, 87 insertions(+), 19 deletions(-) diff --git a/bigml/executionhandler.py b/bigml/executionhandler.py index c0a0f564..03ce7797 100644 --- a/bigml/executionhandler.py +++ b/bigml/executionhandler.py @@ -50,27 +50,41 @@ def __init__(self): """ self.execution_url = self.url + EXECUTION_PATH - def create_execution(self, script, args=None, wait_time=3, retries=10): - """Creates an execution from a `script`. + def create_execution(self, origin_resource, args=None, + wait_time=3, retries=10): + """Creates an execution from a `script` or a list of `scripts`. """ - script_id = None - resource_type = get_resource_type(script) - if resource_type == SCRIPT_PATH: - script_id = get_script_id(script) - check_resource(script_id, - query_string=TINY_RESOURCE, - wait_time=wait_time, retries=retries, - raise_on_error=True, api=self) - else: - raise Exception("A script id is needed to create a" - " script execution. %s found." % resource_type) create_args = {} if args is not None: create_args.update(args) - create_args.update({ - "script": script_id}) + + if isinstance(origin_resource, basestring): + # single script + scripts = [origin_resource] + else: + scripts = origin_resource + + script_ids = [get_script_id(script) for script in scripts] + if all([get_resource_type(script_id) == SCRIPT_PATH for + script_id in script_ids]): + for script in scripts: + check_resource(script, + query_string=TINY_RESOURCE, + wait_time=wait_time, retries=retries, + raise_on_error=True, api=self) + else: + raise Exception("A script id or a list of them is needed to create" + " a script execution. %s found." % + get_resource_type(origin_resource)) + + if len(scripts) > 1: + create_args.update({ + "scripts": script_ids}) + else: + create_args.update({ + "script": script_ids[0]}) body = json.dumps(create_args) return self._create(self.execution_url, body) diff --git a/bigml/tests/create_execution_steps.py b/bigml/tests/create_execution_steps.py index 122aa29d..163f7aa9 100644 --- a/bigml/tests/create_execution_steps.py +++ b/bigml/tests/create_execution_steps.py @@ -32,6 +32,7 @@ #@step(r'the script id is correct and the value of "(.*)" is "(.*)"') def the_execution_and_attributes(step, param, param_value): + assert world.script['resource'] == world.execution['script'] res_param_value = world.execution[param] if res_param_value == param_value: assert True @@ -41,9 +42,33 @@ def the_execution_and_attributes(step, param, param_value): (param, param_value, param, param_value)) +#@step(r'the script ids are correct and the value of "(.*)" is "(.*)"') +def the_execution_ids_and_attributes(step, number_of_scripts, + param, param_value): + scripts = world.scripts[-number_of_scripts:] + assert scripts == world.execution['scripts'] + res_param_value = world.execution[param] + if res_param_value == param_value: + assert True + else: + assert False, ("The execution %s is %s " + "and the expected %s is %s" % + (param, param_value, param, param_value)) + #@step(r'I create a whizzml execution from an existing script"$') def i_create_an_execution(step): - resource = world.api.create_execution(world.script) + resource = world.api.create_execution(world.script['resource']) + world.status = resource['code'] + assert world.status == HTTP_CREATED + world.location = resource['location'] + world.execution = resource['object'] + world.executions.append(resource['resource']) + + +#@step(r'I create a whizzml execution from the last two scripts$') +def i_create_an_execution_from_list(step, number_of_scripts=2): + scripts = world.scripts[-number_of_scripts:] + resource = world.api.create_execution(scripts) world.status = resource['code'] assert world.status == HTTP_CREATED world.location = resource['location'] @@ -73,7 +98,6 @@ def wait_until_execution_status_code_is(step, code1, code2, secs): assert datetime.utcnow() - start < timedelta(seconds=int(secs)) i_get_the_execution(step, execution_id) status = get_status(world.execution) - print "***", status assert status['code'] == int(code1) diff --git a/bigml/tests/create_library_steps.py b/bigml/tests/create_library_steps.py index 36d0f752..9fa8f080 100644 --- a/bigml/tests/create_library_steps.py +++ b/bigml/tests/create_library_steps.py @@ -73,7 +73,6 @@ def wait_until_library_status_code_is(step, code1, code2, secs): assert datetime.utcnow() - start < timedelta(seconds=int(secs)) i_get_the_library(step, library_id) status = get_status(world.library) - print "***", status assert status['code'] == int(code1) diff --git a/bigml/tests/create_script_steps.py b/bigml/tests/create_script_steps.py index bf45a3ed..554ca439 100644 --- a/bigml/tests/create_script_steps.py +++ b/bigml/tests/create_script_steps.py @@ -73,7 +73,6 @@ def wait_until_script_status_code_is(step, code1, code2, secs): assert datetime.utcnow() - start < timedelta(seconds=int(secs)) i_get_the_script(step, script_id) status = get_status(world.script) - print "***", status assert status['code'] == int(code1) diff --git a/bigml/tests/test_28_execution.py b/bigml/tests/test_28_execution.py index 7cc8eb6f..938ee6a9 100644 --- a/bigml/tests/test_28_execution.py +++ b/bigml/tests/test_28_execution.py @@ -64,3 +64,35 @@ def test_scenario1(self): execution_create.i_update_an_execution(self, example[4], example[5]) execution_create.the_execution_is_finished(self, example[3]) execution_create.the_execution_and_attributes(self, example[4], example[5]) + + def test_scenario2(self): + """ + Scenario: Successfully creating a whizzml script execution from a list of scripts: + Given I create a whizzml script from a excerpt of code "" + And I wait until the script is ready less than secs + And I create a whizzml script from a excerpt of code "" + And I wait until the script is ready less than secs + And I create a whizzml script execution from the last two scripts + And I wait until the execution is ready less than secs + And I update the execution with "", "" + And I wait until the execution is ready less than secs + Then the script ids are correct and the value of "" is "" + + Examples: + | source_code | time_1 | time_2 | time_3 | param | param_value + | (+ 1 1) | 10 | 10 | 10 | name | my execution + """ + print self.test_scenario2.__doc__ + examples = [ + ['(+ 1 1)', '10', '10', '10', 'name', 'my execution']] + for example in examples: + print "\nTesting with:\n", example + script_create.i_create_a_script(self, example[0]) + script_create.the_script_is_finished(self, example[1]) + script_create.i_create_a_script(self, example[0]) + script_create.the_script_is_finished(self, example[1]) + execution_create.i_create_an_execution_from_list(self, 2) + execution_create.the_execution_is_finished(self, example[2]) + execution_create.i_update_an_execution(self, example[4], example[5]) + execution_create.the_execution_is_finished(self, example[3]) + execution_create.the_execution_ids_and_attributes(self, 2, example[4], example[5]) From 295e2f3cab1f74b1b648a6c570d65df2ebc57d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Sat, 12 Mar 2016 02:30:18 +0100 Subject: [PATCH 3/8] Updating the code to adapt to changes in backend --- HISTORY.rst | 1 + bigml/__init__.py | 2 +- bigml/api.py | 4 +- bigml/constants.py | 14 ++- bigml/executionhandler.py | 4 +- bigml/fields.py | 24 +++- bigml/libraryhandler.py | 2 +- bigml/logistic.py | 4 +- bigml/resourcehandler.py | 104 +----------------- bigml/scripthandler.py | 4 +- bigml/tests/inspect_model_steps.py | 6 + .../{test_27_script.py => test_29_script.py} | 0 ...t_28_execution.py => test_30_execution.py} | 8 +- ...{test_29_library.py => test_31_library.py} | 0 bigml/tests/world.py | 5 +- 15 files changed, 64 insertions(+), 118 deletions(-) rename bigml/tests/{test_27_script.py => test_29_script.py} (100%) rename bigml/tests/{test_28_execution.py => test_30_execution.py} (94%) rename bigml/tests/{test_29_library.py => test_31_library.py} (100%) diff --git a/HISTORY.rst b/HISTORY.rst index 3f47659d..d8d64d69 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,7 @@ History ------- + 4.6.0 (2016-04-10) ~~~~~~~~~~~~~~~~~~ diff --git a/bigml/__init__.py b/bigml/__init__.py index d04f92aa..52fde385 100644 --- a/bigml/__init__.py +++ b/bigml/__init__.py @@ -1 +1 @@ -__version__ = '4.5.2' +__version__ = '4.6.0' diff --git a/bigml/api.py b/bigml/api.py index 16d4b4d8..ba6ca80a 100644 --- a/bigml/api.py +++ b/bigml/api.py @@ -86,7 +86,7 @@ SAMPLE_PATH, SAMPLE_RE, CORRELATION_PATH, CORRELATION_RE, STATISTICAL_TEST_PATH, STATISTICAL_TEST_RE, LOGISTIC_REGRESSION_PATH, LOGISTIC_REGRESSION_RE, ASSOCIATION_PATH, - ASSOCIATION_RE, ASSOCIATION_SET_PATH, ASSOCIATION_SET_RE + ASSOCIATION_RE, ASSOCIATION_SET_PATH, ASSOCIATION_SET_RE, SCRIPT_PATH, SCRIPT_RE, EXECUTION_PATH, EXECUTION_RE, LIBRARY_PATH, LIBRARY_RE) @@ -99,7 +99,7 @@ get_status, check_resource, http_ok, get_project_id, get_sample_id, get_correlation_id, get_statistical_test_id, get_logistic_regression_id, get_association_id, get_association_set_id, get_script_id, - get_execution_id, get_library_id)) + get_execution_id, get_library_id) # Map status codes to labels diff --git a/bigml/constants.py b/bigml/constants.py index 2e658236..42752263 100644 --- a/bigml/constants.py +++ b/bigml/constants.py @@ -42,6 +42,9 @@ LOGISTIC_REGRESSION_PATH = 'logisticregression' ASSOCIATION_PATH = 'association' ASSOCIATION_SET_PATH = 'associationset' +SCRIPT_PATH = 'script' +EXECUTION_PATH = 'execution' +LIBRARY_PATH = 'library' # Resource Ids patterns @@ -81,6 +84,12 @@ (ASSOCIATION_PATH, ID_PATTERN, ASSOCIATION_PATH, SHARED_PATTERN)) ASSOCIATION_SET_RE = re.compile(r'^%s/%s$' % \ (ASSOCIATION_SET_PATH, ID_PATTERN)) +SCRIPT_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (SCRIPT_PATH, ID_PATTERN, SCRIPT_PATH, SHARED_PATTERN)) +EXECUTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (EXECUTION_PATH, ID_PATTERN, EXECUTION_PATH, SHARED_PATTERN)) +LIBRARY_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ + (LIBRARY_PATH, ID_PATTERN, LIBRARY_PATH, SHARED_PATTERN)) RESOURCE_RE = { SOURCE_PATH: SOURCE_RE, @@ -102,7 +111,10 @@ STATISTICAL_TEST_PATH: STATISTICAL_TEST_RE, LOGISTIC_REGRESSION_PATH: LOGISTIC_REGRESSION_RE, ASSOCIATION_PATH: ASSOCIATION_RE, - ASSOCIATION_SET_PATH: ASSOCIATION_SET_RE} + ASSOCIATION_SET_PATH: ASSOCIATION_SET_RE, + SCRIPT_PATH: SCRIPT_RE, + EXECUTION_PATH: EXECUTION_RE, + LIBRARY_PATH: LIBRARY_RE} RENAMED_RESOURCES = { diff --git a/bigml/executionhandler.py b/bigml/executionhandler.py index 03ce7797..2477fb98 100644 --- a/bigml/executionhandler.py +++ b/bigml/executionhandler.py @@ -31,8 +31,8 @@ from bigml.resourcehandler import (check_resource_type, get_execution_id, get_resource_type, get_script_id, check_resource) -from bigml.resourcehandler import (EXECUTION_PATH, SCRIPT_PATH, - TINY_RESOURCE) +from bigml.constants import (EXECUTION_PATH, SCRIPT_PATH, + TINY_RESOURCE) class ExecutionHandler(ResourceHandler): diff --git a/bigml/fields.py b/bigml/fields.py index 4d0063d9..07e8207d 100644 --- a/bigml/fields.py +++ b/bigml/fields.py @@ -44,6 +44,7 @@ import sys import json + from bigml.util import invert_dictionary, python_map_type, find_locale from bigml.util import DEFAULT_LOCALE from bigml.api import get_resource_type @@ -70,8 +71,12 @@ UPDATABLE_HEADERS = {"field name": "name", "field label": "label", "field description": "description", +<<<<<<< HEAD "field type": "optype", "preferred": "preferred"} +======= + "field type": "optype"} +>>>>>>> Updating the code to adapt to changes in backend ITEM_SINGULAR = {u"categories": u"category"} @@ -131,16 +136,34 @@ def get_fields_structure(resource, errors=False): result = result + (field_errors,) return result else: +<<<<<<< HEAD return (None, None, None, None, None) if errors else \ (None, None, None, None) +======= + + return None, None, None, None, None if errors else \ + None, None, None, None + + +def text_encode(text): + """Encoding text to be written in a utf-8 file + + """ + if isinstance(text, basestring): + return text.encode("utf-8") + return text +>>>>>>> Updating the code to adapt to changes in backend def attribute_summary(attribute_value, item_type, limit=None): """Summarizes the information in fields attributes where content is written as an array of arrays like tag_cloud, items, etc. """ +<<<<<<< HEAD if attribute_value is None: return None +======= +>>>>>>> Updating the code to adapt to changes in backend items = [u"%s (%s)" % (item, instances) for item, instances in attribute_value] items_length = len(items) @@ -588,7 +611,6 @@ def new_fields_structure(self, csv_attributes_file=None, self.field_id(int(field_attributes[0])) new_fields_structure[field_id] = \ dict(zip(headers, field_attributes[1: 6])) - except ValueError: raise ValueError("The first column should contain either the" " column or ID of the fields. Failed to find" diff --git a/bigml/libraryhandler.py b/bigml/libraryhandler.py index e7147cd0..6a820e43 100644 --- a/bigml/libraryhandler.py +++ b/bigml/libraryhandler.py @@ -31,7 +31,7 @@ from bigml.resourcehandler import (check_resource_type, get_library_id, get_resource_type, check_resource) -from bigml.resourcehandler import (LIBRARY_PATH, TINY_RESOURCE) +from bigml.constants import LIBRARY_PATH, TINY_RESOURCE class LibraryHandler(ResourceHandler): diff --git a/bigml/logistic.py b/bigml/logistic.py index e7a5d19d..0278731a 100644 --- a/bigml/logistic.py +++ b/bigml/logistic.py @@ -134,7 +134,9 @@ def __init__(self, logistic_regression, api=None): try: self.dataset_field_types = logistic_regression.get( "dataset_field_types", {}) - objective_field = logistic_regression['objective_fields'] + objective_field = logistic_regression['objective_fields'] if \ + logistic_regression['objective_fields'] else \ + logistic_regression['objective_field'] except KeyError: raise ValueError("Failed to find the logistic regression expected " "JSON structure. Check your arguments.") diff --git a/bigml/resourcehandler.py b/bigml/resourcehandler.py index 2474b40a..1cde5be7 100644 --- a/bigml/resourcehandler.py +++ b/bigml/resourcehandler.py @@ -28,104 +28,6 @@ from bigml.bigmlconnection import BigMLConnection -# Basic resources -SOURCE_PATH = 'source' -DATASET_PATH = 'dataset' -MODEL_PATH = 'model' -PREDICTION_PATH = 'prediction' -EVALUATION_PATH = 'evaluation' -ENSEMBLE_PATH = 'ensemble' -BATCH_PREDICTION_PATH = 'batchprediction' -CLUSTER_PATH = 'cluster' -CENTROID_PATH = 'centroid' -BATCH_CENTROID_PATH = 'batchcentroid' -ANOMALY_PATH = 'anomaly' -ANOMALY_SCORE_PATH = 'anomalyscore' -BATCH_ANOMALY_SCORE_PATH = 'batchanomalyscore' -PROJECT_PATH = 'project' -SAMPLE_PATH = 'sample' -CORRELATION_PATH = 'correlation' -STATISTICAL_TEST_PATH = 'statisticaltest' -SCRIPT_PATH = 'script' -EXECUTION_PATH = 'execution' -LIBRARY_PATH = 'library' - -# Resource Ids patterns -ID_PATTERN = '[a-f0-9]{24}' -SHARED_PATTERN = '[a-zA-Z0-9]{24,30}' -SOURCE_RE = re.compile(r'^%s/%s$' % (SOURCE_PATH, ID_PATTERN)) -# public resources: model and dataset -# shared resources: all except sources -DATASET_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( - DATASET_PATH, ID_PATTERN, DATASET_PATH, SHARED_PATTERN)) -MODEL_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( - MODEL_PATH, ID_PATTERN, MODEL_PATH, SHARED_PATTERN)) -# -PREDICTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - PREDICTION_PATH, ID_PATTERN, PREDICTION_PATH, SHARED_PATTERN)) -EVALUATION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - EVALUATION_PATH, ID_PATTERN, EVALUATION_PATH, SHARED_PATTERN)) -ENSEMBLE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - ENSEMBLE_PATH, ID_PATTERN, ENSEMBLE_PATH, SHARED_PATTERN)) -BATCH_PREDICTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - BATCH_PREDICTION_PATH, ID_PATTERN, BATCH_PREDICTION_PATH, SHARED_PATTERN)) -CLUSTER_RE = re.compile(r'^%s/%s$|^shared/%s/%s$' % ( - CLUSTER_PATH, ID_PATTERN, CLUSTER_PATH, SHARED_PATTERN)) -CENTROID_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - CENTROID_PATH, ID_PATTERN, CENTROID_PATH, SHARED_PATTERN)) -BATCH_CENTROID_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - BATCH_CENTROID_PATH, ID_PATTERN, BATCH_CENTROID_PATH, SHARED_PATTERN)) -ANOMALY_RE = re.compile(r'^(public/)?%s/%s$|^shared/%s/%s$' % ( - ANOMALY_PATH, ID_PATTERN, ANOMALY_PATH, SHARED_PATTERN)) -ANOMALY_SCORE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - ANOMALY_SCORE_PATH, ID_PATTERN, ANOMALY_SCORE_PATH, SHARED_PATTERN)) -BATCH_ANOMALY_SCORE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - BATCH_ANOMALY_SCORE_PATH, ID_PATTERN, - BATCH_ANOMALY_SCORE_PATH, SHARED_PATTERN)) -PROJECT_RE = re.compile(r'^%s/%s$' % (PROJECT_PATH, ID_PATTERN)) -SAMPLE_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - SAMPLE_PATH, ID_PATTERN, SAMPLE_PATH, SHARED_PATTERN)) -CORRELATION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % ( - CORRELATION_PATH, ID_PATTERN, CORRELATION_PATH, SHARED_PATTERN)) -STATISTICAL_TEST_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ - (STATISTICAL_TEST_PATH, ID_PATTERN, STATISTICAL_TEST_PATH, SHARED_PATTERN)) -SCRIPT_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ - (SCRIPT_PATH, ID_PATTERN, SCRIPT_PATH, SHARED_PATTERN)) -EXECUTION_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ - (EXECUTION_PATH, ID_PATTERN, EXECUTION_PATH, SHARED_PATTERN)) -LIBRARY_RE = re.compile(r'^%s/%s|^shared/%s/%s$' % \ - (LIBRARY_PATH, ID_PATTERN, LIBRARY_PATH, SHARED_PATTERN)) - -RESOURCE_RE = { - 'source': SOURCE_RE, - 'dataset': DATASET_RE, - 'model': MODEL_RE, - 'prediction': PREDICTION_RE, - 'evaluation': EVALUATION_RE, - 'ensemble': ENSEMBLE_RE, - 'batchprediction': BATCH_PREDICTION_RE, - 'cluster': CLUSTER_RE, - 'centroid': CENTROID_RE, - 'batchcentroid': BATCH_CENTROID_RE, - 'anomaly': ANOMALY_RE, - 'anomalyscore': ANOMALY_SCORE_RE, - 'batchanomalyscore': BATCH_ANOMALY_SCORE_RE, - 'project': PROJECT_RE, - 'sample': SAMPLE_RE, - 'correlation': CORRELATION_RE, - 'statisticaltest': STATISTICAL_TEST_RE, - 'script': SCRIPT_RE, - 'execution': EXECUTION_RE, - 'library': LIBRARY_RE} - - -RENAMED_RESOURCES = { - 'batchprediction': 'batch_prediction', - 'batchcentroid': 'batch_centroid', - 'anomalyscore': 'anomaly_score', - 'batchanomalyscore': 'batch_anomaly_score', - 'statisticaltest': 'statistical_test' -} NO_QS = [c.EVALUATION_RE, c.PREDICTION_RE, c.BATCH_PREDICTION_RE, c.CENTROID_RE, c.BATCH_CENTROID_RE, c.ANOMALY_SCORE_RE, @@ -364,21 +266,21 @@ def get_script_id(script): """Returns a script/id. """ - return get_resource(SCRIPT_RE, script) + return get_resource(c.SCRIPT_PATH, script) def get_execution_id(execution): """Returns a execution/id. """ - return get_resource(EXECUTION_RE, execution) + return get_resource(c.EXECUTION_PATH, execution) def get_library_id(library): """Returns a library/id. """ - return get_resource(LIBRARY_RE, library) + return get_resource(c.LIBRARY_PATH, library) def get_resource_id(resource): diff --git a/bigml/scripthandler.py b/bigml/scripthandler.py index fab1252a..815c7fdc 100644 --- a/bigml/scripthandler.py +++ b/bigml/scripthandler.py @@ -31,8 +31,8 @@ from bigml.resourcehandler import (check_resource_type, get_script_id, get_resource_type, get_dataset_id, check_resource) -from bigml.resourcehandler import (SCRIPT_PATH, DATASET_PATH, - TINY_RESOURCE) +from bigml.constants import (SCRIPT_PATH, DATASET_PATH, + TINY_RESOURCE) class ScriptHandler(ResourceHandler): diff --git a/bigml/tests/inspect_model_steps.py b/bigml/tests/inspect_model_steps.py index 6c604066..e1fa06b8 100644 --- a/bigml/tests/inspect_model_steps.py +++ b/bigml/tests/inspect_model_steps.py @@ -65,6 +65,12 @@ def i_check_the_model_summary_with(step, file): output = io.BytesIO() world.local_model.summarize(out=output) world.output = output.getvalue() + if not os.path.exists('./tmp'): + os.mkdir('./tmp') + with open('./tmp/summary.txt', "w") as rules_file: + rules_file.write(world.output) + + i_check_if_the_output_is_like_expected_file(step, file) diff --git a/bigml/tests/test_27_script.py b/bigml/tests/test_29_script.py similarity index 100% rename from bigml/tests/test_27_script.py rename to bigml/tests/test_29_script.py diff --git a/bigml/tests/test_28_execution.py b/bigml/tests/test_30_execution.py similarity index 94% rename from bigml/tests/test_28_execution.py rename to bigml/tests/test_30_execution.py index 938ee6a9..4c9bb312 100644 --- a/bigml/tests/test_28_execution.py +++ b/bigml/tests/test_30_execution.py @@ -50,11 +50,11 @@ def test_scenario1(self): Examples: | source_code | time_1 | time_2 | time_3 | param | param_value - | (+ 1 1) | 10 | 10 | 10 | name | my execution + | (+ 1 1) | 10 | 10 | 50 | name | my execution """ print self.test_scenario1.__doc__ examples = [ - ['(+ 1 1)', '10', '10', '10', 'name', 'my execution']] + ['(+ 1 1)', '10', '10', '50', 'name', 'my execution']] for example in examples: print "\nTesting with:\n", example script_create.i_create_a_script(self, example[0]) @@ -80,11 +80,11 @@ def test_scenario2(self): Examples: | source_code | time_1 | time_2 | time_3 | param | param_value - | (+ 1 1) | 10 | 10 | 10 | name | my execution + | (+ 1 1) | 10 | 10 | 50 | name | my execution """ print self.test_scenario2.__doc__ examples = [ - ['(+ 1 1)', '10', '10', '10', 'name', 'my execution']] + ['(+ 1 1)', '10', '10', '50', 'name', 'my execution']] for example in examples: print "\nTesting with:\n", example script_create.i_create_a_script(self, example[0]) diff --git a/bigml/tests/test_29_library.py b/bigml/tests/test_31_library.py similarity index 100% rename from bigml/tests/test_29_library.py rename to bigml/tests/test_31_library.py diff --git a/bigml/tests/world.py b/bigml/tests/world.py index fc55427c..242e5ed0 100644 --- a/bigml/tests/world.py +++ b/bigml/tests/world.py @@ -48,7 +48,7 @@ 'correlation', 'statisticaltest', 'logisticregression', - 'association' + 'association', 'script', 'execution', 'library' @@ -60,9 +60,10 @@ 'anomalyscore': 'anomaly_scores', 'batchanomalyscore': 'batch_anomaly_scores', 'statisticaltest': 'statistical_tests', - 'logisticregression': 'logistic_regressions' + 'logisticregression': 'logistic_regressions', 'library': 'libraries' } + TRANSLATED_RESOURCES = { 'batchprediction': 'batch_prediction', 'batchcentroid': 'batch_centroid', From 830d944b7cd0176b8817d9bbebf82a625212e430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Fri, 25 Mar 2016 19:44:24 +0100 Subject: [PATCH 4/8] Removing rebase conflcts --- bigml/fields.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/bigml/fields.py b/bigml/fields.py index 07e8207d..f1ef507b 100644 --- a/bigml/fields.py +++ b/bigml/fields.py @@ -71,12 +71,8 @@ UPDATABLE_HEADERS = {"field name": "name", "field label": "label", "field description": "description", -<<<<<<< HEAD "field type": "optype", "preferred": "preferred"} -======= - "field type": "optype"} ->>>>>>> Updating the code to adapt to changes in backend ITEM_SINGULAR = {u"categories": u"category"} @@ -136,34 +132,16 @@ def get_fields_structure(resource, errors=False): result = result + (field_errors,) return result else: -<<<<<<< HEAD return (None, None, None, None, None) if errors else \ (None, None, None, None) -======= - - return None, None, None, None, None if errors else \ - None, None, None, None - - -def text_encode(text): - """Encoding text to be written in a utf-8 file - - """ - if isinstance(text, basestring): - return text.encode("utf-8") - return text ->>>>>>> Updating the code to adapt to changes in backend def attribute_summary(attribute_value, item_type, limit=None): """Summarizes the information in fields attributes where content is written as an array of arrays like tag_cloud, items, etc. """ -<<<<<<< HEAD if attribute_value is None: return None -======= ->>>>>>> Updating the code to adapt to changes in backend items = [u"%s (%s)" % (item, instances) for item, instances in attribute_value] items_length = len(items) From d0a99897b5cab37f7c4332207a6c5accdc7cfac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Mon, 28 Mar 2016 18:55:51 +0200 Subject: [PATCH 5/8] Adding create calls accept path to a file in library and script --- bigml/libraryhandler.py | 9 ++++++++- bigml/scripthandler.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bigml/libraryhandler.py b/bigml/libraryhandler.py index 6a820e43..a4526dd6 100644 --- a/bigml/libraryhandler.py +++ b/bigml/libraryhandler.py @@ -25,7 +25,7 @@ import simplejson as json except ImportError: import json - +import os from bigml.resourcehandler import ResourceHandler from bigml.resourcehandler import (check_resource_type, @@ -75,6 +75,13 @@ def create_library(self, source_code=None, args=None, create_args.update({ "origin": library_id}) elif isinstance(source_code, basestring): + try: + if os.path.exists(source_code): + with open(source_code) as code_file: + source_code = code_file.read() + except IOError: + raise IOError("Could not open the source code file %s." % + source_code) create_args.update({ "source_code": source_code}) else: diff --git a/bigml/scripthandler.py b/bigml/scripthandler.py index 815c7fdc..64c20b6a 100644 --- a/bigml/scripthandler.py +++ b/bigml/scripthandler.py @@ -21,6 +21,7 @@ """ +import os try: import simplejson as json except ImportError: @@ -33,6 +34,7 @@ get_dataset_id, check_resource) from bigml.constants import (SCRIPT_PATH, DATASET_PATH, TINY_RESOURCE) +from bigml.util import is_url class ScriptHandler(ResourceHandler): @@ -76,6 +78,13 @@ def create_script(self, source_code=None, args=None, create_args.update({ "origin": script_id}) elif isinstance(source_code, basestring): + try: + if os.path.exists(source_code): + with open(source_code) as code_file: + source_code = code_file.read() + except IOError: + raise IOError("Could not open the source code file %s." % + source_code) create_args.update({ "source_code": source_code}) else: From 5e72ad3e0c2d770429f735d95e3f4e360e20a38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Fri, 8 Apr 2016 00:28:07 +0200 Subject: [PATCH 6/8] Improving comments for script and library handler --- bigml/libraryhandler.py | 1 + bigml/scripthandler.py | 1 + 2 files changed, 2 insertions(+) diff --git a/bigml/libraryhandler.py b/bigml/libraryhandler.py index a4526dd6..b1089d28 100644 --- a/bigml/libraryhandler.py +++ b/bigml/libraryhandler.py @@ -54,6 +54,7 @@ def create_library(self, source_code=None, args=None, """Creates a whizzml library from its source code. The `source_code` parameter can be a: {library ID}: the ID for an existing whizzml library + {path}: the path to a file containing the source code {string} : the string containing the source code for the library """ diff --git a/bigml/scripthandler.py b/bigml/scripthandler.py index 64c20b6a..40348edc 100644 --- a/bigml/scripthandler.py +++ b/bigml/scripthandler.py @@ -57,6 +57,7 @@ def create_script(self, source_code=None, args=None, """Creates a whizzml script from its source code. The `source_code` parameter can be a: {script ID}: the ID for an existing whizzml script + {path}: the path to a file containing the source code {string} : the string containing the source code for the script """ From 42aa12284450559d2790f58a02b703ac79732e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Thu, 28 Apr 2016 19:57:32 +0200 Subject: [PATCH 7/8] Adding comment for new argument option in scripts --- bigml/logistic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigml/logistic.py b/bigml/logistic.py index 0278731a..cc19fded 100644 --- a/bigml/logistic.py +++ b/bigml/logistic.py @@ -221,7 +221,7 @@ def predict(self, input_data, by_name=True): probabilities = {} total = 0 - for category in self.categories[self.objective_id]: + for category in self.coefficients.keys(): coefficients = self.coefficients[category] probabilities[category] = self.category_probability( input_data, unique_terms, coefficients) From 9423b4c4968b81ee14cef1ab6cd62d23dfa8bd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Merc=C3=A8=20Mart=C3=ADn=20Prats?= Date: Fri, 29 Apr 2016 03:38:58 +0200 Subject: [PATCH 8/8] Changing tests after backend changes in clustering --- bigml/tests/create_execution_steps.py | 7 ++++--- bigml/tests/test_05_compare_predictions.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bigml/tests/create_execution_steps.py b/bigml/tests/create_execution_steps.py index 163f7aa9..504551b2 100644 --- a/bigml/tests/create_execution_steps.py +++ b/bigml/tests/create_execution_steps.py @@ -20,6 +20,7 @@ import os from datetime import datetime, timedelta from world import world +from nose.tools import assert_equal from bigml.api import HTTP_CREATED from bigml.api import HTTP_ACCEPTED @@ -59,7 +60,7 @@ def the_execution_ids_and_attributes(step, number_of_scripts, def i_create_an_execution(step): resource = world.api.create_execution(world.script['resource']) world.status = resource['code'] - assert world.status == HTTP_CREATED + assert_equal(world.status, HTTP_CREATED) world.location = resource['location'] world.execution = resource['object'] world.executions.append(resource['resource']) @@ -70,7 +71,7 @@ def i_create_an_execution_from_list(step, number_of_scripts=2): scripts = world.scripts[-number_of_scripts:] resource = world.api.create_execution(scripts) world.status = resource['code'] - assert world.status == HTTP_CREATED + assert_equal(world.status, HTTP_CREATED) world.location = resource['location'] world.execution = resource['object'] world.executions.append(resource['resource']) @@ -81,7 +82,7 @@ def i_update_an_execution(step, param, param_value): resource = world.api.update_execution(world.execution['resource'], {param: param_value}) world.status = resource['code'] - assert world.status == HTTP_ACCEPTED + assert_equal(world.status, HTTP_ACCEPTED) world.location = resource['location'] world.execution = resource['object'] diff --git a/bigml/tests/test_05_compare_predictions.py b/bigml/tests/test_05_compare_predictions.py index 712ff72f..8fedcba1 100644 --- a/bigml/tests/test_05_compare_predictions.py +++ b/bigml/tests/test_05_compare_predictions.py @@ -257,11 +257,11 @@ def test_scenario5(self): Examples: | data | time_1 | time_2 | time_3 | options | data_input | centroid | distance | - | ../data/iris.csv | 20 | 20 | 30 | {"summary_fields": ["sepal width"]} |{"petal length": 1, "petal width": 1, "sepal length": 1, "species": "Iris-setosa"} | Cluster 3 | 0.7155571246307187 | + | ../data/iris.csv | 20 | 20 | 30 | {"summary_fields": ["sepal width"]} |{"petal length": 1, "petal width": 1, "sepal length": 1, "species": "Iris-setosa"} | Cluster 3 | 1.1176214402303308 | """ print self.test_scenario5.__doc__ examples = [ - ['data/iris.csv', '20', '20', '30', '{"summary_fields": ["sepal width"]}', '{"petal length": 1, "petal width": 1, "sepal length": 1, "species": "Iris-setosa"}', 'Cluster 3', '0.7155571246307187']] + ['data/iris.csv', '20', '20', '30', '{"summary_fields": ["sepal width"]}', '{"petal length": 1, "petal width": 1, "sepal length": 1, "species": "Iris-setosa"}', 'Cluster 3', '1.1176214402303308']] for example in examples: print "\nTesting with:\n", example source_create.i_upload_a_file(self, example[0])