From 2a81f7a7e1db01c065b93d9fd157b6af03ceb5a4 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Tue, 31 Oct 2023 14:10:35 +0100 Subject: [PATCH] Bypass changing paths if new path is the same as old one --- model_server/api.py | 2 ++ model_server/util.py | 4 ++++ tests/test_api.py | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/model_server/api.py b/model_server/api.py index 6e7fb5c3..5752fa4b 100644 --- a/model_server/api.py +++ b/model_server/api.py @@ -30,6 +30,8 @@ def list_session_paths(): def change_path(key, path): try: + if session.get_paths()[key] == path: + return session.get_paths() session.set_data_directory(key, path) except InvalidPathError as e: raise HTTPException( diff --git a/model_server/util.py b/model_server/util.py index 8bc071ab..1cc33753 100644 --- a/model_server/util.py +++ b/model_server/util.py @@ -1,10 +1,12 @@ from pathlib import Path import re from time import localtime, strftime +from typing import List import pandas as pd from model_server.accessors import InMemoryDataAccessor, write_accessor_data_to_file +from model_server.models import Model def autonumber_new_directory(where: str, prefix: str) -> str: """ @@ -75,6 +77,7 @@ def loop_workflow( files: list, output_folder_path: str, workflow_func: callable, + models: List[Model], params: dict, export_batch_csvs: bool = True, write_intermediate_products: bool = True, @@ -95,6 +98,7 @@ def loop_workflow( export_kwargs = { 'input_file_path': ff, 'output_folder_path': output_folder_path, + 'models': models, **params, } diff --git a/tests/test_api.py b/tests/test_api.py index f1431ab5..5a307376 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -155,4 +155,20 @@ class TestApiFromAutomatedClient(TestServerBaseClass): resp_check = requests.get( self.uri + 'paths' ) - self.assertEqual(resp_inpath.json()['inbound_images'], resp_check.json()['inbound_images']) \ No newline at end of file + self.assertEqual(resp_inpath.json()['outbound_images'], resp_check.json()['outbound_images']) + + def test_no_change_inbound_path(self): + resp_inpath = requests.get( + self.uri + 'paths' + ) + resp_change = requests.put( + self.uri + f'paths/watch_output', + params={ + 'path': resp_inpath.json()['outbound_images'] + } + ) + self.assertEqual(resp_change.status_code, 200) + resp_check = requests.get( + self.uri + 'paths' + ) + self.assertEqual(resp_inpath.json()['outbound_images'], resp_check.json()['outbound_images']) \ No newline at end of file -- GitLab