Skip to content

Commit fdd10ac

Browse files
committed
Changed so that files are not relative to cwd, fixed test
1 parent fa702cf commit fdd10ac

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

simvue/executor.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,10 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
208208
)
209209

210210
if script:
211-
if cwd:
212-
self._runner.save_file(
213-
file_path=os.path.join(cwd, script), category="code"
214-
)
215-
else:
216-
self._runner.save_file(file_path=script, category="code")
211+
self._runner.save_file(file_path=script, category="code")
217212

218213
if input_file:
219-
if cwd:
220-
self._runner.save_file(
221-
file_path=os.path.join(cwd, input_file), category="input"
222-
)
223-
else:
224-
self._runner.save_file(file_path=input_file, category="input")
214+
self._runner.save_file(file_path=input_file, category="input")
225215

226216
command: typing.List[str] = []
227217

simvue/run.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ def add_process(
653653
identifier: str,
654654
*cmd_args,
655655
executable: typing.Optional[typing.Union[str, pathlib.Path]] = None,
656-
script: typing.Optional[typing.Union[str, pathlib.Path]] = None,
657-
input_file: typing.Optional[typing.Union[str, pathlib.Path]] = None,
656+
script: typing.Optional[pydantic.FilePath] = None,
657+
input_file: typing.Optional[pydantic.FilePath] = None,
658658
completion_callback: typing.Optional[
659659
typing.Callable[[int, str, str], None]
660660
] = None,
@@ -704,10 +704,10 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
704704
positional argument, by default None
705705
*positional_arguments : Any, ..., optional
706706
all other positional arguments are taken to be part of the command to execute
707-
script : str | None, optional
707+
script : pydantic.FilePath | None, optional
708708
the script to run, note this only work if the script is not an option, if this is the case
709709
you should provide it as such and perform the upload manually, by default None
710-
input_file : str | None, optional
710+
input_file : pydantic.FilePath | None, optional
711711
the input file to run, note this only work if the input file is not an option, if this is the case
712712
you should provide it as such and perform the upload manually, by default None
713713
completion_callback : typing.Callable | None, optional
@@ -717,7 +717,8 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
717717
env : typing.Dict[str, str], optional
718718
environment variables for process
719719
cwd: typing.Optional[pathlib.Path], optional
720-
working directory to execute the process within
720+
working directory to execute the process within. Note that executable, input and script file paths should
721+
be absolute or relative to the directory where this method is called, not relative to the new working directory.
721722
**kwargs : Any, ..., optional
722723
all other keyword arguments are interpreted as options to the command
723724
"""

tests/functional/test_run_process_cwd.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from simvue import Run
66
import os
77
import filecmp
8-
8+
import time
99
class TestRunProcess(unittest.TestCase):
1010
def test_processes_cwd(self):
1111
"""Check that cwd argument works correctly in add_process.
@@ -18,10 +18,12 @@ def test_processes_cwd(self):
1818
with tempfile.NamedTemporaryFile(dir=temp_dir, suffix=".py") as temp_file:
1919
with open(temp_file.name, "w") as out_f:
2020
out_f.writelines([
21-
"import time\n",
22-
"time.sleep(10)\n"
21+
"import os\n",
22+
"f = open('new_file.txt', 'w')\n",
23+
"f.write('Test Line')\n",
24+
"f.close()"
2325
])
24-
file_name = os.path.basename(temp_file.name)
26+
import pdb; pdb.set_trace()
2527

2628
with Run() as run:
2729
run.init(
@@ -32,22 +34,23 @@ def test_processes_cwd(self):
3234
run.add_process(
3335
identifier="sleep_10_process",
3436
executable="python",
35-
script=file_name,
37+
script=temp_file.name,
3638
cwd=temp_dir
3739
)
40+
time.sleep(1)
41+
run.save_file(os.path.join(temp_dir, "new_file.txt"), 'output')
3842

3943
client = simvue.Client()
4044

41-
# Check that run existed for more than 10s, meaning the process ran correctly
42-
data = client.get_run(run_id)
43-
runtime = data['runtime']
44-
runtime_seconds = float(runtime.split(":")[-1])
45-
self.assertGreater(runtime_seconds, 10.0)
46-
4745
# Check that the script was uploaded to the run correctly
4846
os.makedirs(os.path.join(temp_dir, "downloaded"))
49-
client.get_artifact_as_file(run_id, file_name, path=os.path.join(temp_dir, "downloaded"))
50-
assert filecmp.cmp(os.path.join(temp_dir, "downloaded", file_name), temp_file.name)
47+
client.get_artifact_as_file(run_id, os.path.basename(temp_file.name), path=os.path.join(temp_dir, "downloaded"))
48+
assert filecmp.cmp(os.path.join(temp_dir, "downloaded", os.path.basename(temp_file.name)), temp_file.name)
49+
50+
client.get_artifact_as_file(run_id, "new_file.txt", path=os.path.join(temp_dir, "downloaded"))
51+
new_file = open(os.path.join(temp_dir, "downloaded", "new_file.txt"), "r")
52+
assert new_file.read() == "Test Line"
53+
new_file.close()
5154

5255
if __name__ == '__main__':
5356
unittest.main()

0 commit comments

Comments
 (0)