| 
2 | 2 | from bids.variables import (SparseRunVariable, SimpleVariable,  | 
3 | 3 |                             DenseRunVariable, load_variables)  | 
4 | 4 | from bids.variables.entities import Node, RunNode, NodeIndex  | 
 | 5 | +from bids.variables.io import parse_transforms  | 
5 | 6 | from unittest.mock import patch  | 
6 | 7 | import pytest  | 
7 | 8 | from os.path import join  | 
 | 9 | +from pathlib import Path  | 
 | 10 | +import tempfile  | 
 | 11 | +import json  | 
8 | 12 | from bids.tests import get_test_data_path  | 
9 | 13 | from bids.config import set_option, get_option  | 
10 | 14 | 
 
  | 
 | 15 | +EXAMPLE_TRANSFORM = {  | 
 | 16 | +    "Transformations":[{"Name":"example_trans","Inputs":["col_a","col_b"]}]  | 
 | 17 | +}  | 
 | 18 | +TRANSFORMS_JSON = join(tempfile.tempdir,"tranformations.json")  | 
 | 19 | +Path(TRANSFORMS_JSON).write_text(json.dumps(EXAMPLE_TRANSFORM))  | 
11 | 20 | 
 
  | 
12 | 21 | @pytest.fixture  | 
13 | 22 | def layout1():  | 
@@ -103,3 +112,29 @@ def test_load_synthetic_dataset(synthetic):  | 
103 | 112 |     subs = index.get_nodes('subject')  | 
104 | 113 |     assert len(subs) == 5  | 
105 | 114 |     assert set(subs[0].variables.keys()) == {'systolic_blood_pressure'}  | 
 | 115 | + | 
 | 116 | +@pytest.mark.parametrize(  | 
 | 117 | +    "test_case,transform_input,expected_names",  | 
 | 118 | +    [  | 
 | 119 | +        ("raw transform json",  | 
 | 120 | +         EXAMPLE_TRANSFORM,  | 
 | 121 | +         ["example_trans"]  | 
 | 122 | +        ),  | 
 | 123 | +        ("transform json file",  | 
 | 124 | +         TRANSFORMS_JSON,  | 
 | 125 | +         ["example_trans"]  | 
 | 126 | +        ),  | 
 | 127 | +        ("raw model json",  | 
 | 128 | +         {"Nodes": [EXAMPLE_TRANSFORM]},  | 
 | 129 | +         ["example_trans"]  | 
 | 130 | +        ),  | 
 | 131 | +         ("model json file",  | 
 | 132 | +         str(Path(get_test_data_path()) / "ds005/models/ds-005_type-mfx_model.json"),  | 
 | 133 | +         ["Scale"]  | 
 | 134 | +        ),  | 
 | 135 | +    ]  | 
 | 136 | +)  | 
 | 137 | +def test_parse_transforms(test_case,transform_input,expected_names):  | 
 | 138 | +    result = parse_transforms(transform_input)  | 
 | 139 | +    transformation_names =  [x['name'] for x in result]  | 
 | 140 | +    assert expected_names == transformation_names  | 
0 commit comments