def test_client_download_model(gordo_project, gordo_single_target, ml_server): """ Test client's ability to download the model """ client = Client(project=gordo_project) models = client.download_model() assert isinstance(models, dict) assert isinstance(models[gordo_single_target], BaseEstimator) # Can't download model for non-existent target with pytest.raises(NotFound): client = Client(project=gordo_project) client.download_model(targets=["non-existent-target"])
def download_model(ctx: click.Context, output_dir: str, target: typing.List[str]): """ Download the actual model from the target and write to an output directory """ client = Client(*ctx.obj["args"], **ctx.obj["kwargs"]) models = client.download_model(targets=target) # Iterate over mapping of models and save into their own sub dirs of the output_dir for model_name, model in models.items(): model_out_dir = os.path.join(output_dir, model_name) os.mkdir(model_out_dir) click.secho( f"Writing model '{model_name}' to directory: '{model_out_dir}'...", nl=False ) serializer.dump(model, model_out_dir) click.secho(f"done") click.secho(f"Wrote all models to directory: {output_dir}", fg="green")