1+ from pathlib import Path
12import pytest
23
4+ from datalad .local .rerun import get_run_info
5+
36from datalad_next .exceptions import IncompleteResultsError
47from datalad_next .tests .utils import (
58 SkipTest ,
@@ -23,3 +26,79 @@ def test_substitution_config_default(existing_dataset):
2326 # make sure we could actually detect breakage with the check above
2427 with pytest .raises (IncompleteResultsError ):
2528 ds .run ('{python} -c "breakage"' , result_renderer = 'disabled' )
29+
30+
31+ def test_runrecord_portable_paths (existing_dataset ):
32+ ds = existing_dataset
33+ dsrepo = ds .repo
34+ infile = ds .pathobj / 'inputs' / 'testfile.txt'
35+ outfile = ds .pathobj / 'outputs' / 'testfile.txt'
36+ infile .parent .mkdir ()
37+ outfile .parent .mkdir ()
38+ infile .touch ()
39+ ds .save ()
40+ assert not outfile .exists ()
41+ # script copies any 'inputs' to the outputs dir
42+ res = ds .run (
43+ '{python} -c "'
44+ 'from shutil import copyfile;'
45+ 'from pathlib import Path;'
46+ r"""[copyfile(f.strip('\"'), Path.cwd() / \"outputs\" / Path(f.strip('\"')).name)"""
47+ r""" for f in '{inputs}'.split()]"""
48+ '"' ,
49+ result_renderer = 'disabled' ,
50+ # we need to pass relative paths ourselves
51+ # https://github.com/datalad/datalad/issues/7516
52+ inputs = [str (infile .relative_to (ds .pathobj ))],
53+ outputs = [str (outfile .relative_to (ds .pathobj ))],
54+ )
55+ # verify basic outcome
56+ assert_result_count (res , 1 , action = 'run' , status = 'ok' )
57+ assert outfile .exists ()
58+
59+ # branch we expect the runrecord on
60+ branch = dsrepo .get_corresponding_branch () or dsrepo .get_active_branch ()
61+ cmsg = dsrepo .format_commit ('%B' , branch )
62+
63+ # the IOspecs are stored in POSIX conventions
64+ assert r'"inputs/testfile.txt"' in cmsg
65+ assert r'"outputs/testfile.txt"' in cmsg
66+
67+ # get_run_info() reports in platform conventions
68+ msg , run_info = get_run_info (ds , cmsg )
69+ assert run_info
70+ for k in ('inputs' , 'outputs' ):
71+ specs = run_info .get (k )
72+ assert len (specs ) > 0
73+ for p in specs :
74+ assert (ds .pathobj / p ).exists ()
75+
76+
77+ def test_runrecord_oldnative_paths (existing_dataset ):
78+ ds = existing_dataset
79+
80+ cmsg = (
81+ '[DATALAD RUNCMD] /home/mih/env/datalad-dev/bin/python -c ...\n \n '
82+ '=== Do not change lines below ===\n '
83+ '{\n '
84+ ' "chain": [],\n '
85+ ' "cmd": "{python} -c \\ "from shutil import copyfile;from pathlib import Path;[copyfile(f, Path.cwd() / \\ \\ \\ "outputs\\ \\ \\ " / Path(f).name) for f in \\ \\ \\ "{inputs}\\ \\ \\ ".split()]\\ "",\n '
86+ # use the ID of the test dataset to ensure proper association
87+ f' "dsid": "{ ds .id } ",\n '
88+ ' "exit": 0,\n '
89+ ' "extra_inputs": [],\n '
90+ ' "inputs": [\n '
91+ # make windows path, used to be stored in escaped form
92+ r' "inputs\\testfile.txt"' '\n '
93+ ' ],\n '
94+ ' "outputs": [\n '
95+ # make windows path, used to be stored in escaped form
96+ r' "outputs\\testfile.txt"' '\n '
97+ ' ],\n '
98+ ' "pwd": "."\n '
99+ '}\n '
100+ '^^^ Do not change lines above ^^^\n '
101+ )
102+ msg , run_info = get_run_info (ds , cmsg )
103+ assert run_info ['inputs' ][0 ] == str (Path ('inputs' , 'testfile.txt' ))
104+ assert run_info ['outputs' ][0 ] == str (Path ('outputs' , 'testfile.txt' ))
0 commit comments