def test_5_cleanup(self): print("\n\33[33m{}\33[0m".format("5. Cleanup after myself ...")) # delete my_model from the store, if it exists from cube.io_utils.model_store import ModelMetadata, ModelStore model_store_object = ModelStore() local_models = model_store_object.list_local_models() print("\tFound local models:" + str(local_models)) self.assertTrue(len(local_models) > 0) for model, version in local_models: if model == "my_model": # delete local model print("\tDeleting 'my_model-1.0'...") model_store_object.delete_model("my_model", "1.0") local_models_new = model_store_object.list_local_models() print("\tFound local models:" + str(local_models_new)) self.assertTrue(len(local_models) > len(local_models_new)) break # delete my_model.zip, if it exists if os.path.exists( os.path.join(self.local_model_repo, "my_model-1.0.zip")): os.remove(os.path.join(self.local_model_repo, "my_model-1.0.zip")) self.assertFalse( os.path.exists( os.path.join(self.local_model_repo, "my_model-1.0.zip")))
def test_4_2_import_model_in_store(self): print("\n\33[33m{}\33[0m".format( "4.2. Import locally created model in store (with prior cleanup)..." )) # first check local models from cube.io_utils.model_store import ModelMetadata, ModelStore model_store_object = ModelStore() local_models = model_store_object.list_local_models() print("\tFound local models:" + str(local_models)) self.assertTrue(len(local_models) > 0) # search for my_model for model, version in local_models: if model == "my_model": # delete local model print("\tDeleting 'my_model-1.0'...") model_store_object.delete_model("my_model", "1.0") local_models_new = model_store_object.list_local_models() print("\tFound local models:" + str(local_models_new)) self.assertTrue(len(local_models) > len(local_models_new)) # import new model command = "python3 " + os.path.join( self.scripts_path, "import_model.py") + " " + os.path.join( self.local_model_repo, "my_model-1.0.zip") print("\n\t\t\33[32m{}\n{}\33[0m".format("Import command:", command)) '''popen = subprocess.Popen(command.split(" ") , stdout=subprocess.PIPE, universal_newlines=True) output = [] for stdout_line in iter(popen.stdout.readline, ""): print(stdout_line[:-1]) if stdout_line.strip()!= "": output.append(stdout_line[:-1]) popen.stdout.close() return_code = popen.wait() ''' os.system(command) test = os.path.exists( os.path.join(self.local_model_repo, "my_model-1.0.zip")) self.assertTrue(test) # check it is in store local_models = model_store_object.list_local_models() test = False for model, version in local_models: if model == "my_model": test = True self.assertTrue(test)