-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1312 from pyiron/job_step
add wrap_executable() function to project
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
from pyiron_base._tests import TestWithProject | ||
|
||
|
||
def write_input(input_dict, working_directory="."): | ||
with open(os.path.join(working_directory, "input_file"), "w") as f: | ||
f.write(str(input_dict["energy"])) | ||
|
||
|
||
def collect_output(working_directory="."): | ||
with open(os.path.join(working_directory, "output_file"), "r") as f: | ||
return {"energy": float(f.readline())} | ||
|
||
|
||
class TestWrapExecutable(TestWithProject): | ||
def test_python_version(self): | ||
python_version_step = self.project.wrap_executable( | ||
job_name="pythonjobstep", | ||
executable_str="python --version", | ||
write_input_funct=None, | ||
collect_output_funct=None, | ||
input_dict=None, | ||
conda_environment_path=None, | ||
conda_environment_name=None, | ||
input_file_lst=None, | ||
execute_job=True, | ||
) | ||
self.assertTrue(python_version_step.status.finished) | ||
self.assertEqual( | ||
python_version_step.files.error_out, | ||
os.path.join(python_version_step.working_directory, "error.out") | ||
) | ||
|
||
def test_cat(self): | ||
job = self.project.wrap_executable( | ||
job_name="Cat_Job_energy_1_0", | ||
write_input_funct=write_input, | ||
collect_output_funct=collect_output, | ||
input_dict={"energy": 1.0}, | ||
executable_str="cat input_file > output_file", | ||
execute_job=False, | ||
) | ||
job.input.energy = 2.0 | ||
job.run() | ||
self.assertEqual(job.output.energy, 2.0) |