From c3002df16ea2b4a3ae524869dc26e04189765dd4 Mon Sep 17 00:00:00 2001 From: Labbeti Date: Thu, 7 Dec 2023 15:02:14 +0100 Subject: [PATCH] Fix: Try to fix CECT installation on windows for unittests. --- tests/test_compare_cet.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/test_compare_cet.py b/tests/test_compare_cet.py index 44147d1..df0eaa5 100644 --- a/tests/test_compare_cet.py +++ b/tests/test_compare_cet.py @@ -19,6 +19,7 @@ from aac_metrics.utils.paths import ( get_default_tmp_path, ) +from aac_metrics.download import _download_spice class TestCompareCaptionEvaluationTools(TestCase): @@ -37,25 +38,31 @@ def _import_cet_eval_func( Tuple[Dict[str, float], Dict[int, Dict[str, float]]], ]: cet_path = osp.join(osp.dirname(__file__), "caption-evaluation-tools") - use_shell = platform.system() == "Windows" + on_windows = platform.system() == "Windows" - stanford_fpath = osp.join( + cet_cache_path = Path( cet_path, "coco_caption", "pycocoevalcap", + ) + stanford_fpath = cet_cache_path.joinpath( "spice", "lib", "stanford-corenlp-3.6.0.jar", ) if not osp.isfile(stanford_fpath): - command = "bash get_stanford_models.sh" - subprocess.check_call( - command.split(), - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - cwd=osp.join(cet_path, "coco_caption"), - shell=use_shell, - ) + if not on_windows: + # Use CET installation + command = ["bash", "get_stanford_models.sh"] + subprocess.check_call( + command, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + cwd=osp.join(cet_path, "coco_caption"), + shell=on_windows, + ) + else: + _download_spice(str(cet_cache_path), clean_archives=True, verbose=2) # Append cet_path to allow imports of "caption" in eval_metrics.py. sys.path.append(cet_path)