Skip to content

Commit 02b8086

Browse files
committed
test: Verify that physio.sidecar gets loaded for events.tsv
1 parent bbf3c63 commit 02b8086

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/schema/associations.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { assertEquals, assertObjectMatch } from '@std/assert'
2+
import type { BIDSFile, FileTree } from '../types/filetree.ts'
3+
import { loadSchema } from '../setup/loadSchema.ts'
4+
import { pathsToTree } from '../files/filetree.ts'
5+
import { nullReadBytes } from '../tests/nullReadBytes.ts'
6+
import { rootFileTree } from './fixtures.test.ts'
7+
import { BIDSContext } from './context.ts'
8+
import { buildAssociations } from './associations.ts'
9+
10+
Deno.test('Test association loading', async (t) => {
11+
const schema = await loadSchema()
12+
await t.step('Load associations for events.tsv', async () => {
13+
const eventsFile = rootFileTree.get('sub-01/ses-01/func/sub-01_ses-01_task-movie_events.tsv') as BIDSFile
14+
const context = new BIDSContext(eventsFile, undefined, rootFileTree)
15+
context.dataset.schema = schema
16+
const associations = await buildAssociations(context)
17+
assertObjectMatch(associations, {
18+
physio: {
19+
sidecar: { SamplingFrequency: 100, StartTime: 0, PhysioType: "eyetrack" },
20+
}
21+
})
22+
})
23+
})

src/schema/fixtures.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ function readBytes(json: string) {
1818
export const rootFileTree = pathsToTree([
1919
'/dataset_description.json',
2020
'/T1w.json',
21+
'/task-movie_events.json',
22+
'/task-movie_physio.json',
2123
'/sub-01/ses-01_T1w.json',
2224
'/sub-01/ses-01/anat/sub-01_ses-01_T1w.nii.gz',
2325
'/sub-01/ses-01/anat/sub-01_ses-01_T1w.json',
26+
'/sub-01/ses-01/func/sub-01_ses-01_task-movie_bold.nii.gz',
27+
'/sub-01/ses-01/func/sub-01_ses-01_task-movie_bold.nii.gz',
28+
'/sub-01/ses-01/func/sub-01_ses-01_task-movie_events.tsv',
29+
'/sub-01/ses-01/func/sub-01_ses-01_task-movie_physio.tsv.gz',
2430
...[...Array(10).keys()].map((i) => `/stimuli/stimfile${i}.png`),
2531
])
2632

@@ -35,5 +41,24 @@ const anatFileTree = subjectFileTree.directories[0].directories[0] as FileTree
3541

3642
export const dataFile = anatFileTree.get('sub-01_ses-01_T1w.nii.gz') as BIDSFile
3743
const anatJSONFile = anatFileTree.get('sub-01_ses-01_T1w.json') as BIDSFile
38-
anatJSONFile.readBytes = (size: number) =>
39-
Promise.resolve(new TextEncoder().encode(anatJson) as Uint8Array<ArrayBuffer>)
44+
anatJSONFile.readBytes = readBytes(anatJson)
45+
46+
const eventsSidecar = rootFileTree.get('task-movie_events.json') as BIDSFile
47+
eventsSidecar.readBytes = readBytes(
48+
JSON.stringify({
49+
StimulusPresentation: {
50+
ScreenDistance: 1.8,
51+
ScreenOrigin: ["top", "left"],
52+
ScreenResolution: [1920, 1080],
53+
ScreenSize: [0.472, 0.265],
54+
},
55+
})
56+
)
57+
const physioSidecar = rootFileTree.get('task-movie_physio.json') as BIDSFile
58+
physioSidecar.readBytes = readBytes(
59+
JSON.stringify({
60+
SamplingFrequency: 100,
61+
StartTime: 0,
62+
PhysioType: "eyetrack",
63+
})
64+
)

0 commit comments

Comments
 (0)