From 1faee26f656bc17053db7c68ba5cff62445b4956 Mon Sep 17 00:00:00 2001 From: Walter Simson Date: Sat, 14 Dec 2024 14:50:56 -0800 Subject: [PATCH] split arguments --- kwave/options/simulation_execution_options.py | 13 +++-- tests/test_simulation_execution_options.py | 48 ++++++++++++------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/kwave/options/simulation_execution_options.py b/kwave/options/simulation_execution_options.py index d4b4b0cb..07d1e9b2 100644 --- a/kwave/options/simulation_execution_options.py +++ b/kwave/options/simulation_execution_options.py @@ -156,13 +156,17 @@ def as_list(self, sensor: kSensor) -> list[str]: if self.device_num is not None: if self.device_num < 0: raise ValueError("Device number must be non-negative") - options_list.append(f"-g {self.device_num}") + options_list.append("-g") + options_list.append(str(self.device_num)) if self.num_threads is not None and PLATFORM != "windows": - options_list.append(f"-t {self.num_threads}") + options_list.append("-t") + options_list.append(str(self.num_threads)) if self.verbose_level > 0: - options_list.append(f"--verbose {self.verbose_level}") + options_list.append("--verbose") + options_list.append(str(self.verbose_level)) + record_options_map = { "p": "p_raw", "p_max": "p_max", "p_min": "p_min", "p_rms": "p_rms", @@ -184,7 +188,8 @@ def as_list(self, sensor: kSensor) -> list[str]: options_list.append("--p_raw") if sensor.record_start_index is not None: - options_list.append(f"-s {sensor.record_start_index}") + options_list.append("-s") + options_list.append(f"{sensor.record_start_index}") return options_list diff --git a/tests/test_simulation_execution_options.py b/tests/test_simulation_execution_options.py index 7eb8905c..8a25de9b 100644 --- a/tests/test_simulation_execution_options.py +++ b/tests/test_simulation_execution_options.py @@ -96,12 +96,16 @@ def test_get_options_string_darwin(self): options_list = options.as_list(self.mock_sensor) expected_elements = [ - f"-g {options.device_num}", - f"-t {os.cpu_count()}", - "--verbose 2", + "-g", + f"{options.device_num}", + "-t", + f"{os.cpu_count()}", + "--verbose", + "2", "--p_raw", "--u_max", - f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor + "-s", + f"{self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor ] for element in expected_elements: self.assertIn(element, options_list) @@ -116,11 +120,14 @@ def test_as_list_windows(self): options_list = options.as_list(self.mock_sensor) expected_elements = [ - f"-g {options.device_num}", - "--verbose 2", + "-g", + f"{options.device_num}", + "--verbose", + "2", "--p_raw", "--u_max", - f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor + "-s", + f"{self.mock_sensor.record_start_index}" ] for element in expected_elements: self.assertIn(element, options_list) @@ -136,12 +143,16 @@ def test_as_list_darwin(self): options_list = options.as_list(self.mock_sensor) expected_elements = [ - f"-g {options.device_num}", - f"-t {os.cpu_count()}", - "--verbose 2", + "-g", + f"{options.device_num}", + "-t", + f"{os.cpu_count()}", + "--verbose", + "2", "--p_raw", "--u_max", - f"-s {self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor + "-s", + f"{self.mock_sensor.record_start_index}" # Updated to use self.mock_sensor ] for element in expected_elements: self.assertIn(element, options_list) @@ -156,9 +167,12 @@ def test_as_list_custom_record(self): options_list = options.as_list(self.mock_sensor) expected_elements = [ - f"-g {options.device_num}", - "-t 8", - "--verbose 1", + "-g", + f"{options.device_num}", + "-t", + "8", + "--verbose", + "1", "--p_max", "--u_min", "--p_raw" # Default if no specific 'p' or 'u' options are given @@ -183,8 +197,10 @@ def test_as_list_no_record(self): options_list = options.as_list(self.mock_sensor) expected_elements = [ - f"-g {options.device_num}", - "-t 4", + "-g", + f"{options.device_num}", + "-t", + "4", "--p_raw", # Default value ] for element in expected_elements: