Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ TemplateFlow 2.0 file names: the client reads the v2 skeleton and resolves old n
in earlier releases.
* MAINT: A compatibility matrix (``tests/compat``, workflow *Compatibility*) runs the
released clients and this one against an Archive before and after a renames table,
in S3 and DataLad homes. It replays a proposed table before it is merged.
in S3 and DataLad homes. It replays a proposed table before it is merged, text files
included.
* MAINT: The documentation builds on CircleCI again: Python 3.13, the ``doc`` extra
instead of a conda environment, and pandoc for the notebooks.

Expand Down
8 changes: 5 additions & 3 deletions tests/compat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ breaks no released client that reads it through S3.
```text
test_compat.py (pytest, the branch installed)
├── archive.py the fixture Archive: names from the bundled v2 skeleton, made-up
│ content, annexed files as MD5E symlinks; skeletons built by the
│ real build-skeletons.py (templateflow/templateflow), before and
│ after the table
│ content for annexed files (MD5E symlinks), the bundled content of
│ text files; skeletons built by the real build-skeletons.py
│ (templateflow/templateflow), before and after the table
├── datalad_archive.py a one-template git-annex Archive for DataLad homes
├── server.py local S3 (404 answers as S3 sends them) and skeleton URLs
└── client processes one uv environment per client (25.0.4, 25.1.2, branch)
Expand Down Expand Up @@ -82,3 +82,5 @@ does not exercise (no removed files, say) are skipped.
The sample table renames `tpl-MNI152Lin` files as the 2.0 rules do: `res-01` to
`res-1` (entities kept), entity order with `res` (kept), `PET` to `pet` and
`desc-head` to `label-head` (entities changed), one removed file (`n/a`) and one purged.
It also removes a text file, the CerebA lookup table of `tpl-MNI152NLin2009cSym` (`n/a`),
as that template's migration does. Results compare the whole file (its sha256).
20 changes: 15 additions & 5 deletions tests/compat/datalad_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from functools import partial
from pathlib import Path

from archive import GIT_ENV, KEYWORDS, content
from archive import GIT_ENV, KEYWORDS

TEXT = ('template_description.json', 'LICENSE', 'CHANGES')

Expand All @@ -41,13 +41,23 @@ def run(cwd: Path, *args: str, bin_dir: Path) -> str:


class DataladArchive:
def __init__(self, work: Path, rows: list[tuple[str, str]], text: dict[str, bytes], bin_dir):
def __init__(
self,
work: Path,
rows: list[tuple[str, str]],
text: dict[str, bytes],
files: dict[str, bytes],
bin_dir,
):
"""The rows of the :func:`busiest` template; ``text`` the Archive's text files;
``bin_dir`` the folder with ``git-annex``."""
``files`` the bytes of the rows' old paths, as S3 serves them before the table (made
up for annexed files, real for text files); ``bin_dir`` the folder with
``git-annex``."""
self.run = partial(run, bin_dir=bin_dir)
self.template = template = busiest(rows)
self.root = work / 'origin' / 'templateflow'
self.rows = [(o, n) for o, n in rows if o.startswith(f'{template}/')]
self.contents = {old: files[old] for old, _ in self.rows}
self.repo = self.root / template
self.repo.mkdir(parents=True)
self.run(self.root, 'git', 'init', '-q', '-b', 'master')
Expand All @@ -59,8 +69,8 @@ def __init__(self, work: Path, rows: list[tuple[str, str]], text: dict[str, byte
for name in TEXT:
if f'{self.template}/{name}' in text:
(self.repo / name).write_bytes(text[f'{self.template}/{name}'])
for old, _ in self.rows:
(self.root / old).write_bytes(content(old))
for old, data in self.contents.items():
(self.root / old).write_bytes(data)
self.run(self.repo, 'git', 'annex', 'add', '-q', '.')
self.run(
self.repo,
Expand Down
5 changes: 5 additions & 0 deletions tests/compat/runtime/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Only uses the API that every client in the matrix has (25.0 and later).
"""

import hashlib
import json
import sys
import warnings
Expand Down Expand Up @@ -62,6 +63,10 @@ def op_get(path):
Path(p).read_bytes()[:200].decode(errors='replace') if Path(p).is_file() else None
for p in paths
],
'sha256': [
hashlib.sha256(Path(p).read_bytes()).hexdigest() if Path(p).is_file() else None
for p in paths
],
'warnings': [
f'{w.category.__name__}: {w.message}'
for w in caught
Expand Down
1 change: 1 addition & 0 deletions tests/compat/sample-renames.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ tpl-MNI152Lin/tpl-MNI152Lin_desc-SPM12_res-02_T1w.nii.gz tpl-MNI152Lin/tpl-MNI15
tpl-MNI152Lin/tpl-MNI152Lin_desc-SPM12_res-02_PET.nii.gz tpl-MNI152Lin/tpl-MNI152Lin_res-2_desc-SPM12_pet.nii.gz
tpl-MNI152Lin/tpl-MNI152Lin_res-01_desc-head_mask.nii.gz tpl-MNI152Lin/tpl-MNI152Lin_res-1_label-head_mask.nii.gz
tpl-MNI152Lin/tpl-MNI152Lin_desc-SPM12_res-02_SPECT.nii.gz n/a
tpl-MNI152NLin2009cSym/tpl-MNI152NLin2009cSym_atlas-CerebA_dseg.tsv n/a
tpl-MNI152Lin/tpl-MNI152Lin_desc-SPM12_res-02_epi.nii.gz purge
14 changes: 8 additions & 6 deletions tests/compat/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

import hashlib
import json
import os
import shutil
Expand Down Expand Up @@ -194,7 +195,7 @@ def assert_found(result: dict, path: str, expected: bytes):
assert result['error'] is None, result
assert result['single'], result
assert result['paths'] == [path], result
assert result['contents'][0] == expected.decode(), result
assert result['sha256'][0] == hashlib.sha256(expected).hexdigest(), result


# Pinned clients: no update, the bundled skeleton ######################################
Expand Down Expand Up @@ -334,8 +335,9 @@ def datalad_archive(tmp_path, fixture, environments) -> DataladArchive:
for path, data in fixture.files['before'].items()
if path.count('/') == 1 and path.split('/', 1)[1] in TEXT
}
files = {old: fixture.content('before', old) for old, _ in fixture.rows}
bin_dir = environments('branch', datalad=True).parent
return DataladArchive(tmp_path / 'datalad', fixture.rows, text, bin_dir)
return DataladArchive(tmp_path / 'datalad', fixture.rows, text, files, bin_dir)


def datalad_rows(archive_):
Expand All @@ -348,7 +350,7 @@ def install_and_update(client, datalad_archive) -> None:
renamed_, removed_ = datalad_rows(datalad_archive)
found = client.get(*(old for old, _ in renamed_ + removed_))
for old, _ in renamed_ + removed_:
assert_found(found[old], old, archive.content(old))
assert_found(found[old], old, datalad_archive.contents[old])
datalad_archive.apply()
client.update()

Expand All @@ -361,10 +363,10 @@ def test_branch_datalad(fixture, server, client_for, datalad_archive):
renamed_, removed_ = datalad_rows(datalad_archive)
found = client.get(*(old for old, _ in renamed_ + removed_))
for old, new in renamed_:
assert_found(found[old], new, archive.content(old))
assert_found(found[old], new, datalad_archive.contents[old])
assert bool(found[old]['warnings']) is entities_change(old, new), found[old]
for old, _ in removed_:
assert_found(found[old], old, archive.content(old))
assert_found(found[old], old, datalad_archive.contents[old])
assert any('removed from the Archive' in w for w in found[old]['warnings'])


Expand All @@ -378,7 +380,7 @@ def test_released_datalad(fixture, server, client_for, datalad_archive, name):
need(rows, 'renames that keep the entities')
found = client.get(*(old for old, _ in rows))
for old, new in rows:
assert_found(found[old], new, archive.content(old))
assert_found(found[old], new, datalad_archive.contents[old])


@pytest.mark.xfail(
Expand Down
Loading