class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.debug = False try: self.debug = bool(os.environ.get('BIGML_DEBUG', 0)) except ValueError: pass self.short_debug = False try: self.short_debug = bool(os.environ.get('BIGML_SHORT_DEBUG', 0)) except ValueError: pass self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.test_project_name = "Test: python bindings %s" % \ datetime.datetime.now() self.project_id = None self.print_connection_info() self.delta = int(os.environ.get('BIGML_DELTA', '1')) def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') self.EXTERNAL_CONN = get_env_connection_info() if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") self.api = BigML(self.USERNAME, self.API_KEY, debug=self.debug, short_debug=self.short_debug, storage=(None if not (self.debug or self.short_debug) else "./debug_storage")) print(self.api.connection_info()) print(self.external_connection_info()) def external_connection_info(self): """Printable string: The information used to connect to a external data source """ info = "External data connection config:\n%s" % \ pprint.pformat(self.EXTERNAL_CONN, indent=4) return info def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, RENAMED_RESOURCES.get(resource_type, resource_type), None) def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = set(getattr(self, plural(resource_type))) if object_list: print("Deleting %s %s" % (len(object_list), plural(resource_type))) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print("Delete failed for %s. Retrying" % obj_id) time.sleep(3 * self.delta) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print("Retries to delete the created resources are" " exhausted. Failed to delete.") def store_resources(self): """Stores the created objects """ for resource_type in RESOURCE_TYPES: object_list = set(getattr(self, plural(resource_type))) if object_list: print("Deleting %s %s" % (len(object_list), plural(resource_type))) store_method = self.api.getters[resource_type] for obj_id in object_list: counter = 0 result = store_method(obj_id) self.api.ok(result)
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.api_dev_mode = None self.debug = False try: self.debug = bool(os.environ.get('BIGML_DEBUG', 0)) except ValueError: pass self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.test_project_name = "Test: python bindings %s" % \ datetime.datetime.now() self.project_id = None self.print_connection_info() self.reset_api() def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") self.api = BigML(self.USERNAME, self.API_KEY, debug=self.debug) print self.api.connection_info() def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) def reset_api(self): """Reset the api connection values """ if self.api is not None and self.api.dev_mode: self.project_id = None if self.api is None or self.api.dev_mode: self.api = BigML(self.USERNAME, self.API_KEY, debug=self.debug) self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True, debug=self.debug) if self.api_dev_mode is None: self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True, debug=self.debug) def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print( "Retries to delete the created resources are" " exhausted. Failed to delete.")
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.debug = False self.api_debug = False self.source_lower = None self.source_upper = None self.source_reference = None self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.folders = [] self.test_project_name = "Test: BigMLer %s" % \ datetime.datetime.now() self.project_id = None self.print_connection_info() def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') try: self.debug = bool(os.environ.get('BIGMLER_DEBUG', 0)) self.api_debug = bool(os.environ.get('BIGML_DEBUG', 0)) except ValueError: pass if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") else: assert True self.api = BigML(self.USERNAME, self.API_KEY, debug=self.api_debug) print self.api.connection_info() output_dir = "./last_run" for _, subFolders, _ in os.walk("./"): for folder in subFolders: if folder.startswith("scenario"): bigmler_delete(folder, output_dir=output_dir) if os.path.exists(output_dir): shutil.rmtree(output_dir) def count_resources(self, time_tag, changed=False): """Counts the existing resources and stores it keyed by time_tag. If changed is set to True, only resources that are logged as changed are listed. """ print "Counting resources (%s)." % time_tag for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if resource_type == "time_series_set": resource_type = "time_series" if (not changed or len(getattr(self, resource_type))) > 0: resources = getattr(self.api,"list_%s" % resource_type)() if resource_type == 'source' and resources['code'] != HTTP_OK: assert False, ( "Unable to list your sources. Please check the" " BigML domain and credentials to be:\n\n%s" % self.api.connection_info()) else: if resources['code'] == HTTP_OK: assert True else: assert False, ("HTTP returned code %s for %s" % (resources['code'], resource_type)) if (not resource_type in self.counters): self.counters[resource_type] = {} self.counters[resource_type][time_tag] = resources[ 'meta']['total_count'] def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) self.source_lower = None self.source_upper = None self.source_reference = None def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print ("Retries to delete the created resources are" " exhausted. Failed to delete.") def check_init_equals_final(self): """ Checks if the counters in init and final timestap are unchanged """ for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if getattr(self, resource_type): counters = self.counters[resource_type] if counters['final'] == counters['init']: assert True else: assert False , ( "init %s: %s, final %s: %s" % (resource_type, counters['init'], resource_type, counters['final']))
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.api_dev_mode = None self.reset_api() self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.print_connection_info() self.test_project_name = "Test: python bindings %s" % \ datetime.datetime.now() self.project_id = None def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") else: assert True self.api = BigML(self.USERNAME, self.API_KEY) print self.api.connection_info() def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) def reset_api(self): """Reset the api connection values """ self.api = BigML(self.USERNAME, self.API_KEY) self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True) def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print ("Retries to delete the created resources are" " exhausted. Failed to delete.")
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.api_dev_mode = None self.reset_api() self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.print_connection_info() def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") else: assert True self.api = BigML(self.USERNAME, self.API_KEY) print self.api.connection_info() def count_resources(self, time_tag, changed=False): """Counts the existing resources and stores it keyed by time_tag. If changed is set to True, only resources that are logged as changed are listed. """ print "Counting resources (%s)." % time_tag for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if (not changed or len(getattr(self, resource_type))) > 0: resources = getattr(self.api,"list_%s" % resource_type)() if resource_type == 'source' and resources['code'] != HTTP_OK: assert False, ( "Unable to list your sources. Please check the" " BigML domain and credentials to be:\n\n%s" % self.api.connection_info()) else: if resources['code'] == HTTP_OK: assert True else: assert False, ("HTTP returned code %s" % resources['code']) if (not resource_type in self.counters): self.counters[resource_type] = {} self.counters[resource_type][time_tag] = resources[ 'meta']['total_count'] def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) def reset_api(self): """Reset the api connection values """ self.api = BigML(self.USERNAME, self.API_KEY) self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True) def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print ("Retries to delete the created resources are" " exhausted. Failed to delete.")
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.debug = False self.api_debug = False self.source_lower = None self.source_upper = None self.source_reference = None self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.folders = [] self.test_project_name = "Test: BigMLer %s" % \ datetime.datetime.now() self.project_id = None self.print_connection_info() def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') try: self.debug = bool(os.environ.get('BIGMLER_DEBUG', 0)) self.api_debug = bool(os.environ.get('BIGML_DEBUG', 0)) except ValueError: pass if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") else: assert True self.api = BigML(self.USERNAME, self.API_KEY, debug=self.api_debug) print self.api.connection_info() output_dir = "./last_run" for _, subFolders, _ in os.walk("./"): for folder in subFolders: if folder.startswith("scenario"): bigmler_delete(folder, output_dir=output_dir) if os.path.exists(output_dir): shutil.rmtree(output_dir) def count_resources(self, time_tag, changed=False): """Counts the existing resources and stores it keyed by time_tag. If changed is set to True, only resources that are logged as changed are listed. """ print "Counting resources (%s)." % time_tag for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if resource_type == "time_series_set": resource_type = "time_series" if (not changed or len(getattr(self, resource_type))) > 0: resources = getattr(self.api,"list_%s" % resource_type)() if resource_type == 'source' and resources['code'] != HTTP_OK: assert False, ( "Unable to list your sources. Please check the" " BigML domain and credentials to be:\n\n%s" % self.api.connection_info()) else: if resources['code'] == HTTP_OK: assert True else: assert False, ("HTTP returned code %s for %s" % (resources['code'], resource_type)) if (not resource_type in self.counters): self.counters[resource_type] = {} self.counters[resource_type][time_tag] = resources[ 'meta']['total_count'] def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) self.source_lower = None self.source_upper = None self.source_reference = None def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print ("Retries to delete the created resources are" " exhausted. Failed to delete.") def check_init_equals_final(self): """ Checks if the counters in init and final timestap are unchanged """ for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if getattr(self, resource_type): counters = self.counters[resource_type] if counters['final'] == counters['init']: assert True else: assert False , ( "init %s: %s, final %s: %s" % (resource_type, counters['init'], resource_type, counters['final']))
class World(object): def __init__(self): self.USERNAME = None self.API_KEY = None self.api = None self.api_dev_mode = None self.reset_api() self.clear() self.dataset_ids = [] self.fields_properties_dict = {} self.counters = {} self.print_connection_info() def print_connection_info(self): self.USERNAME = os.environ.get('BIGML_USERNAME') self.API_KEY = os.environ.get('BIGML_API_KEY') if self.USERNAME is None or self.API_KEY is None: assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY" " environment variables to authenticate the" " connection, but they seem to be unset. Please," "set them before testing.") else: assert True self.api = BigML(self.USERNAME, self.API_KEY) print self.api.connection_info() def count_resources(self, time_tag, changed=False): """Counts the existing resources and stores it keyed by time_tag. If changed is set to True, only resources that are logged as changed are listed. """ print "Counting resources (%s)." % time_tag for resource_type in RESOURCE_TYPES: resource_type = plural(resource_type) if (not changed or len(getattr(self, resource_type))) > 0: resources = getattr(self.api, "list_%s" % resource_type)() if resource_type == 'source' and resources['code'] != HTTP_OK: assert False, ( "Unable to list your sources. Please check the" " BigML domain and credentials to be:\n\n%s" % self.api.connection_info()) else: if resources['code'] == HTTP_OK: assert True else: assert False, ("HTTP returned code %s" % resources['code']) if (not resource_type in self.counters): self.counters[resource_type] = {} self.counters[resource_type][time_tag] = resources['meta'][ 'total_count'] def clear(self): """Clears the stored resources' ids """ for resource_type in RESOURCE_TYPES: setattr(self, plural(resource_type), []) setattr(self, TRANSLATED_RESOURCES.get(resource_type, resource_type), None) def reset_api(self): """Reset the api connection values """ self.api = BigML(self.USERNAME, self.API_KEY) self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True) def delete_resources(self): """Deletes the created objects """ for resource_type in RESOURCE_TYPES: object_list = getattr(self, plural(resource_type)) if object_list: print "Deleting %s %s" % (len(object_list), plural(resource_type)) delete_method = self.api.deleters[resource_type] for obj_id in object_list: counter = 0 result = delete_method(obj_id) while (result['code'] != HTTP_NO_CONTENT and counter < MAX_RETRIES): print "Delete failed for %s. Retrying" % obj_id time.sleep(3) counter += 1 result = delete_method(obj_id) if counter == MAX_RETRIES: print( "Retries to delete the created resources are" " exhausted. Failed to delete.")