Skip to content

Commit 2f5060a

Browse files
Suppress the FileNotFound error when attempting to set the file mode (#498)
* Suppress the FileNotFound error when attempting to set the file mode * Fix test
1 parent e1e740b commit 2f5060a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

kwave/executor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import h5py
77

88
import kwave
9+
from kwave.options.simulation_execution_options import SimulationExecutionOptions
910
from kwave.utils.dotdictionary import dotdict
1011

1112

1213
class Executor:
13-
def __init__(self, execution_options, simulation_options):
14+
def __init__(self, execution_options: SimulationExecutionOptions, simulation_options):
1415
self.execution_options = execution_options
1516
self.simulation_options = simulation_options
1617

@@ -21,15 +22,15 @@ def __init__(self, execution_options, simulation_options):
2122
self._make_binary_executable()
2223

2324
def _make_binary_executable(self):
24-
try:
25-
self.execution_options.binary_path.chmod(self.execution_options.binary_path.stat().st_mode | stat.S_IEXEC)
26-
except FileNotFoundError as e:
25+
binary_path = self.execution_options.binary_path
26+
if not binary_path.exists():
2727
if kwave.PLATFORM == "darwin" and self.execution_options.is_gpu_simulation:
2828
raise ValueError(
29-
"GPU simulations are currently not supported on MacOS. Try running the simulation on CPU by setting is_gpu_simulation=False."
30-
) from e
31-
else:
32-
raise e
29+
"GPU simulations are currently not supported on MacOS. "
30+
"Try running the simulation on CPU by setting is_gpu_simulation=False."
31+
)
32+
raise FileNotFoundError(f"Binary not found at {binary_path}")
33+
binary_path.chmod(binary_path.stat().st_mode | stat.S_IEXEC)
3334

3435
def run_simulation(self, input_filename: str, output_filename: str, options: str):
3536
command = [str(self.execution_options.binary_path), "-i", input_filename, "-o", output_filename, options]

tests/test_executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def test_executor_gpu_cuda_failure_darwin(self):
193193
# Configure the mock path object
194194
mock_binary_path = MagicMock(spec=Path)
195195
mock_binary_path.chmod.side_effect = FileNotFoundError
196+
mock_binary_path.exists.return_value = False
196197

197198
# Mock the execution options to use the mocked path
198199
mock_execution_options = MagicMock()

0 commit comments

Comments
 (0)