def test_ManagedMcrun_run_simulation_basic_path(self, mock_sub): """ Check a basic system call is correct, with different path format """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas", "") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", executable_path=executable_path, executable="mcrun",) os.chdir(current_work_dir) mcrun_obj.run_simulation() expected_folder_path = os.path.join(THIS_DIR, "test_folder") executable = os.path.join(executable_path, "mcrun") # a double space because of a missing option expected_call = (executable + " -c -n 1000000 " + "-d " + expected_folder_path + " test.instr") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True, cwd=mcrun_obj.run_path)
def test_ManagedMcrun_run_simulation_compile(self, mock_sub): """ Check a run with parameters is correct """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", mcrun_path="path", mpi=7, ncount=48.4, force_compile=False, custom_flags="-fo", parameters={ "A": 2, "BC": "car", "th": "\"toy\"" }) mcrun_obj.run_simulation() current_directory = os.getcwd() expected_folder_path = os.path.join(current_directory, "test_folder") # a double space because of a missing option expected_call = ("path/mcrun -n 48 --mpi=7 " + "-d " + expected_folder_path + " -fo test.instr " + "A=2 BC=car th=\"toy\"") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True)
def test_ManagedMcrun_run_simulation_no_standard(self, mock_sub): """ Check a non standard system call is correct """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", mcrun_path="path", mpi=7, ncount=48.4, custom_flags="-fo") mcrun_obj.run_simulation() current_directory = os.getcwd() expected_folder_path = os.path.join(current_directory, "test_folder") # a double space because of a missing option expected_call = ("path/mcrun -c -n 48 --mpi=7 " + "-d " + expected_folder_path + " -fo test.instr") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True)
def test_ManagedMcrun_run_simulation_compile(self, mock_sub): """ Check run with force_compile set to False works """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", executable_path=executable_path, executable="mcrun", mpi=7, ncount=48.4, force_compile=False, custom_flags="-fo", parameters={ "A": 2, "BC": "car", "th": "\"toy\"" }) os.chdir(current_work_dir) mcrun_obj.run_simulation() expected_folder_path = os.path.join(THIS_DIR, "test_folder") executable = os.path.join(executable_path, "mcrun") # a double space because of a missing option expected_call = (executable + " -n 48 --mpi=7 " + "-d " + expected_folder_path + " -fo test.instr " + "A=2 BC=car th=\"toy\"") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True, cwd=mcrun_obj.run_path)
def test_ManagedMcrun_run_simulation_no_standard(self, mock_sub): """ Check a non standard system call is correct Here multiple options are used and ncount is a float that should be rounded by the class. """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", executable_path=executable_path, executable="mcrun", mpi=7, ncount=48.4, custom_flags="-fo") os.chdir(current_work_dir) mcrun_obj.run_simulation() expected_folder_path = os.path.join(THIS_DIR, "test_folder") # a double space because of a missing option executable = os.path.join(executable_path, "mcrun") expected_call = (executable + " -c -n 48 --mpi=7 " + "-d " + expected_folder_path + " -fo test.instr") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True, cwd=mcrun_obj.run_path)
def test_ManagedMcrun_run_simulation_basic_path(self, mock_sub): """ Check a basic system call is correct, with different path format """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_folder", mcrun_path="path/") mcrun_obj.run_simulation() current_directory = os.getcwd() expected_folder_path = os.path.join(current_directory, "test_folder") # a double space because of a missing option expected_call = ("path/mcrun -c -n 1000000 " + "-d " + expected_folder_path + " test.instr") mock_sub.assert_called_once_with(expected_call, shell=True, stderr=-1, stdout=-1, universal_newlines=True)