Skip to content

Commit

Permalink
Add two tests that document portability issues of run-records
Browse files Browse the repository at this point in the history
- IO specifications are stored in platform-native conventions
- IO specifications are reported as-is

combined with the absence of any platform type record, this makes
run-records non-portable across unix/windows scopes.

Ping datalad/datalad#7512
  • Loading branch information
mih committed Oct 19, 2023
1 parent 78216f1 commit 175af6f
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions datalad_next/patches/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from pathlib import Path
import pytest

from datalad.local.rerun import get_run_info

from datalad_next.exceptions import IncompleteResultsError
from datalad_next.tests.utils import (
SkipTest,
Expand All @@ -23,3 +26,79 @@ def test_substitution_config_default(existing_dataset):
# make sure we could actually detect breakage with the check above
with pytest.raises(IncompleteResultsError):
ds.run('{python} -c "breakage"', result_renderer='disabled')


def test_runrecord_portable_paths(existing_dataset):
ds = existing_dataset
dsrepo = ds.repo
infile = ds.pathobj / 'inputs' / 'testfile.txt'
outfile = ds.pathobj / 'outputs' / 'testfile.txt'
infile.parent.mkdir()
outfile.parent.mkdir()
infile.touch()
ds.save()
assert not outfile.exists()
# script copies any 'inputs' to the outputs dir
res = ds.run(
'{python} -c "'
'from shutil import copyfile;'
'from pathlib import Path;'
r'[copyfile(f, Path.cwd() / \'outputs\' / Path(f).name)'
r' for f in \"{inputs}\".split()]'
'"',
result_renderer='disabled',
# we need to pass relative paths ourselves
# https://github.com/datalad/datalad/issues/7516
inputs=[str(infile.relative_to(ds.pathobj))],
outputs=[str(outfile.relative_to(ds.pathobj))],
)
# verify basic outcome
assert_result_count(res, 1, action='run', status='ok')
assert outfile.exists()

# branch we expect the runrecord on
branch = dsrepo.get_corresponding_branch() or dsrepo.get_active_branch()
cmsg = dsrepo.format_commit('%B', branch)

# the IOspecs are stored in POSIX conventions
assert r'"inputs/testfile.txt"' in cmsg
assert r'"outputs/testfile.txt"' in cmsg

# get_run_info() reports in platform conventions
msg, run_info = get_run_info(ds, cmsg)
assert run_info
for k in ('inputs', 'outputs'):
specs = run_info.get(k)
assert len(specs) > 0
for p in specs:
assert (ds.pathobj / p).exists()


def test_runrecord_oldnative_paths(existing_dataset):
ds = existing_dataset

cmsg = (
'[DATALAD RUNCMD] /home/mih/env/datalad-dev/bin/python -c ...\n\n'
'=== Do not change lines below ===\n'
'{\n'
' "chain": [],\n'
' "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'
# use the ID of the test dataset to ensure proper association
f' "dsid": "{ds.id}",\n'
' "exit": 0,\n'
' "extra_inputs": [],\n'
' "inputs": [\n'
# make windows path, used to be stored in escaped form
r' "inputs\\testfile.txt"' '\n'
' ],\n'
' "outputs": [\n'
# make windows path, used to be stored in escaped form
r' "outputs\\testfile.txt"' '\n'
' ],\n'
' "pwd": "."\n'
'}\n'
'^^^ Do not change lines above ^^^\n'
)
msg, run_info = get_run_info(ds, cmsg)
assert run_info['inputs'][0] == str(Path('inputs', 'testfile.txt'))
assert run_info['outputs'][0] == str(Path('outputs', 'testfile.txt'))

0 comments on commit 175af6f

Please sign in to comment.