Skip to content

Commit

Permalink
test(tsv): Add unit test for formatted column
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jul 29, 2024
1 parent f17e086 commit b1ce66a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion bids-validator/src/schema/applyRules.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck
import { assert, assertEquals, assertObjectMatch } from '../deps/asserts.ts'
import { loadSchema } from '../setup/loadSchema.ts'
import { applyRules, evalCheck } from './applyRules.ts'
import { applyRules, evalCheck, evalColumns } from './applyRules.ts'
import { DatasetIssues } from '../issues/datasetIssues.ts'

const ruleContextData = [
Expand Down Expand Up @@ -45,6 +45,24 @@ const schemaDefs = {
},
},
},
tabular_data: {
modality_agnostic: {
Scans: {
selectors: ['suffix == "scans"', 'extension == ".tsv"'],
initial_columns: ['filename'],
columns: {
filename: {
level: 'required',
description_addendum:
'There MUST be exactly one row for each file.',
},
acq_time__scans: 'optional',
},
index_columns: ['filename'],
additional_columns: 'allowed',
},
},
},
},
}

Expand Down Expand Up @@ -107,3 +125,23 @@ Deno.test(
assert(context.issues.hasIssue({ key: 'CHECK_ERROR' }))
},
)

Deno.test('check column contents', async (t) => {
const schema = await loadSchema()

await t.step('check invalid datetime (scans.tsv:acq_time)', () => {
const context = {
path: '/sub-01/sub-01_scans.tsv',
extension: '.tsv',
sidecar: {},
columns: {
filename: ['func/sub-01_task-rest_bold.nii.gz'],
acq_time: ['1900-01-01T00:00:78'],
},
issues: new DatasetIssues(),
}
const rule = schemaDefs.rules.tabular_data.modality_agnostic.Scans
evalColumns(rule, context, schema, 'rules.tabular_data.modality_agnostic.Scans')
assert(context.issues.hasIssue({ key: 'TSV_VALUE_INCORRECT_TYPE_NONREQUIRED' }))
})
})
2 changes: 1 addition & 1 deletion bids-validator/src/schema/applyRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function sidecarDefinedTypeCheck(
* otherwise we type check each value in the column according to the type
* specified in the schema rule (or sidecar type information if applicable).
*/
function evalColumns(
export function evalColumns(
rule: GenericRule,
context: BIDSContext,
schema: GenericSchema,
Expand Down

0 comments on commit b1ce66a

Please sign in to comment.