From 0fefa3e792bf5061762bd1d1d59ec254130a0403 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Thu, 4 Aug 2022 07:42:08 -0500 Subject: [PATCH 1/5] Added basic unit tests for HEDVersion with libraries --- bids-validator/tests/events.spec.js | 108 ++++++++++++++++++++++++ bids-validator/validators/events/hed.js | 34 ++++++-- package-lock.json | 4 +- 3 files changed, 138 insertions(+), 8 deletions(-) diff --git a/bids-validator/tests/events.spec.js b/bids-validator/tests/events.spec.js index 34f4e1c9e..9d6cbc1e3 100644 --- a/bids-validator/tests/events.spec.js +++ b/bids-validator/tests/events.spec.js @@ -182,6 +182,77 @@ describe('Events', function() { }) }) + it('should not throw an issue if a value column is annotated', () => { + const events = [ + { + file: { path: '/sub01/sub01_task-test_events.tsv' }, + path: '/sub01/sub01_task-test_events.tsv', + contents: + 'onset\tduration\ttest\tHED\n' + '7\t3.0\tone\tSpeed/30 mph\n', + }, + ] + const jsonDictionary = { + '/sub01/sub01_task-test_events.json': { + myCodes: { + test: { + HED: { + one: 'Label/#', + }, + }, + }, + }, + '/dataset_description.json': { HEDVersion: '8.0.0' }, + } + + return validate.Events.validateEvents( + events, + [], + headers, + jsonDictionary, + jsonFiles, + '', + ).then(issues => { + assert.deepStrictEqual(issues, []) + }) + }) + + it('should not throw an issue if a library schema is included', () => { + const events = [ + { + file: { path: '/sub01/sub01_task-test_events.tsv' }, + path: '/sub01/sub01_task-test_events.tsv', + contents: + 'onset\tduration\ttest\tHED\n' + '7\t3.0\tone\tSpeed/30 mph\n', + }, + ] + + const jsonDictionary = { + '/sub01/sub01_task-test_events.json': { + myCodes: { + test: { + HED: { + one: 'ts:Sensory-presentation, Label/#', + }, + }, + }, + }, + '/dataset_description.json': { + HEDVersion: ['8.0.0', 'ts:testlib_1.0.2'], + }, + } + + return validate.Events.validateEvents( + events, + [], + headers, + jsonDictionary, + jsonFiles, + '', + ).then(issues => { + assert.deepStrictEqual(issues, []) + }) + }) + it('should throw an issue if the HED data is invalid', () => { const events = [ { @@ -216,6 +287,43 @@ describe('Events', function() { }) }) + it('should not throw an issue if multiple library schemas are included', () => { + const events = [ + { + file: { path: '/sub01/sub01_task-test_events.tsv' }, + path: '/sub01/sub01_task-test_events.tsv', + contents: + 'onset\tduration\ttest\tHED\n' + '7\t3.0\tone\tSpeed/30 mph\n', + }, + ] + + const jsonDictionary = { + '/sub01/sub01_task-test_events.json': { + myCodes: { + test: { + HED: { + one: 'ts:Sensory-presentation, Label/#, sc:Sleep-deprivation', + }, + }, + }, + }, + '/dataset_description.json': { + HEDVersion: ['8.0.0', 'ts:testlib_1.0.2', 'sc:score_0.0.1'], + }, + } + + return validate.Events.validateEvents( + events, + [], + headers, + jsonDictionary, + jsonFiles, + '', + ).then(issues => { + assert.deepStrictEqual(issues, []) + }) + }) + it('should properly issue warnings when appropriate', () => { const events = [ { diff --git a/bids-validator/validators/events/hed.js b/bids-validator/validators/events/hed.js index 5f1e24760..9aedd1da8 100644 --- a/bids-validator/validators/events/hed.js +++ b/bids-validator/validators/events/hed.js @@ -1,6 +1,4 @@ import hedValidator from 'hed-validator' -import path from 'path' -import semver from 'semver' import union from 'lodash/union' import utils from '../../utils' import parseTsv from '../tsv/tsvParser' @@ -14,14 +12,25 @@ export default function checkHedStrings(events, jsonContents, jsonFiles, dir) { if (!hedDataExists) { return Promise.resolve([]) } - const dataset = new hedValidator.validator.BidsDataset(eventData, sidecarData) - const [schemaDefinition, schemaDefinitionIssues] = parseHedVersion( - jsonContents, + // New stuff here + const datasetDescription = jsonContents['/dataset_description.json'] + const datasetDescriptionData = new hedValidator.validator.BidsJsonFile( + '/dataset_description.json', + datasetDescription, + jsonFiles['/dataset_description.json'], + ) + const dataset = new hedValidator.validator.BidsDataset( + eventData, + sidecarData, + datasetDescriptionData, dir, ) + // New stuff end does parseHedVersion need to be called anymore? + const schemaDefinitionIssues = parseHedVersion(jsonContents) + // Change here schemaDefinition is not passed to validateBidsDataset. try { return hedValidator.validator - .validateBidsDataset(dataset, schemaDefinition) + .validateBidsDataset(dataset) .then(hedValidationIssues => { return schemaDefinitionIssues.concat( convertHedIssuesToBidsIssues(hedValidationIssues), @@ -99,6 +108,7 @@ function sidecarValueHasHed(sidecarValue) { ) } +/* function parseHedVersion(jsonContents, dir) { const schemaDefinition = {} const datasetDescription = jsonContents['/dataset_description.json'] @@ -119,6 +129,18 @@ function parseHedVersion(jsonContents, dir) { return [schemaDefinition, issues] } + */ + +function parseHedVersion(jsonContents) { + const datasetDescription = jsonContents['/dataset_description.json'] + + if (!(datasetDescription && datasetDescription.HEDVersion)) { + return [new Issue({ code: 109 })] + } else { + return [] + } +} + function internalHedValidatorIssue(error) { return Issue.errorToIssue(error, 107) } diff --git a/package-lock.json b/package-lock.json index 9c167261d..ef4cf1075 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ } }, "bids-validator": { - "version": "1.9.5-dev.0", + "version": "1.9.8-dev.0", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.9.0", @@ -72,7 +72,7 @@ } }, "bids-validator-web": { - "version": "1.9.5-dev.0", + "version": "1.9.8-dev.0", "license": "MIT", "dependencies": { "@babel/runtime": "^7.16.7", From 2c0f71cba7337369c32ad4ba6cb225465fd4c7df Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Thu, 4 Aug 2022 08:36:12 -0500 Subject: [PATCH 2/5] Removed commented out code --- bids-validator/validators/events/hed.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/bids-validator/validators/events/hed.js b/bids-validator/validators/events/hed.js index 9aedd1da8..fb1ff4651 100644 --- a/bids-validator/validators/events/hed.js +++ b/bids-validator/validators/events/hed.js @@ -108,29 +108,6 @@ function sidecarValueHasHed(sidecarValue) { ) } -/* -function parseHedVersion(jsonContents, dir) { - const schemaDefinition = {} - const datasetDescription = jsonContents['/dataset_description.json'] - const issues = [] - - if (!(datasetDescription && datasetDescription.HEDVersion)) { - issues.push(new Issue({ code: 109 })) - } else if (semver.valid(datasetDescription.HEDVersion)) { - schemaDefinition.version = datasetDescription.HEDVersion - } else { - schemaDefinition.path = path.join( - path.resolve(dir), - 'sourcedata', - datasetDescription.HEDVersion, - ) - } - - return [schemaDefinition, issues] -} - - */ - function parseHedVersion(jsonContents) { const datasetDescription = jsonContents['/dataset_description.json'] From 061ad8fadeada8c453a5ad0e9b7453e17bddbded Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Fri, 26 Aug 2022 06:10:27 -0500 Subject: [PATCH 3/5] Updated the creation of the dataset description object --- bids-validator/validators/events/hed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bids-validator/validators/events/hed.js b/bids-validator/validators/events/hed.js index 0f9197233..1561a0e5d 100644 --- a/bids-validator/validators/events/hed.js +++ b/bids-validator/validators/events/hed.js @@ -17,7 +17,7 @@ export default function checkHedStrings(events, jsonContents, jsonFiles, dir) { const datasetDescriptionData = new hedValidator.validator.BidsJsonFile( '/dataset_description.json', datasetDescription, - jsonFiles['/dataset_description.json'], + getSidecarFileObject('/dataset_description.json', jsonFiles), ) const dataset = new hedValidator.validator.BidsDataset( eventData, From 28dff0aa86ed91f60ec81497ca3614fe6315411e Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Mon, 29 Aug 2022 12:49:02 -0500 Subject: [PATCH 4/5] Bumped hed-validator version for hed library schema support --- bids-validator/package.json | 2 +- bids-validator/validators/events/hed.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bids-validator/package.json b/bids-validator/package.json index c868f1c1e..35b32a623 100644 --- a/bids-validator/package.json +++ b/bids-validator/package.json @@ -44,7 +44,7 @@ "date-fns": "^2.7.0", "events": "^3.3.0", "exifreader": "^4.1.0", - "hed-validator": "^3.7.1", + "hed-validator": "^3.8.0", "ignore": "^4.0.2", "is-utf8": "^0.2.1", "jshint": "^2.9.6", diff --git a/bids-validator/validators/events/hed.js b/bids-validator/validators/events/hed.js index 1561a0e5d..ce4b54bbe 100644 --- a/bids-validator/validators/events/hed.js +++ b/bids-validator/validators/events/hed.js @@ -12,7 +12,7 @@ export default function checkHedStrings(events, jsonContents, jsonFiles, dir) { if (!hedDataExists) { return Promise.resolve([]) } - // New stuff here + const datasetDescription = jsonContents['/dataset_description.json'] const datasetDescriptionData = new hedValidator.validator.BidsJsonFile( '/dataset_description.json', From f830f7a22d81d2eaa44135c982effcc0ab2d3b58 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Tue, 30 Aug 2022 14:21:54 -0500 Subject: [PATCH 5/5] update package-lock.json for hed validator 3.8 --- package-lock.json | 54 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index df026e818..b6331560e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "date-fns": "^2.7.0", "events": "^3.3.0", "exifreader": "^4.1.0", - "hed-validator": "^3.7.1", + "hed-validator": "^3.8.0", "ignore": "^4.0.2", "is-utf8": "^0.2.1", "jshint": "^2.9.6", @@ -11485,13 +11485,16 @@ } }, "node_modules/hed-validator": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/hed-validator/-/hed-validator-3.7.1.tgz", - "integrity": "sha512-nrOOmEGQ6Pp97aQpql6ICWkJdzqD+qM+kLB1NaEHv16ycS8fOUJvL75UTXIV9TirHQiLVc4LtmKSH+u0kYiXNw==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/hed-validator/-/hed-validator-3.8.0.tgz", + "integrity": "sha512-T0CMJOs02NqKeZsaqnb0TgJdurCQ7zA0VFYgzWPsEIrCFLDw8q18MxtTnyxF+B8Jm9V6Km3SpwtyTcdIl4k3xQ==", "dependencies": { + "buffer": "^6.0.3", "date-and-time": "^0.14.2", "date-fns": "^2.17.0", + "events": "^3.3.0", "lodash": "^4.17.21", + "path": "^0.12.7", "pluralize": "^8.0.0", "semver": "^7.3.4", "then-request": "^6.0.2", @@ -11501,6 +11504,29 @@ "node": ">=12.12.0" } }, + "node_modules/hed-validator/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/hed-validator/node_modules/semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", @@ -28097,7 +28123,7 @@ "eslint-plugin-prettier": "^2.6.2", "events": "^3.3.0", "exifreader": "^4.1.0", - "hed-validator": "^3.7.1", + "hed-validator": "^3.8.0", "husky": "^1.0.0-rc.13", "ignore": "^4.0.2", "is-utf8": "^0.2.1", @@ -31372,19 +31398,31 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, "hed-validator": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/hed-validator/-/hed-validator-3.7.1.tgz", - "integrity": "sha512-nrOOmEGQ6Pp97aQpql6ICWkJdzqD+qM+kLB1NaEHv16ycS8fOUJvL75UTXIV9TirHQiLVc4LtmKSH+u0kYiXNw==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/hed-validator/-/hed-validator-3.8.0.tgz", + "integrity": "sha512-T0CMJOs02NqKeZsaqnb0TgJdurCQ7zA0VFYgzWPsEIrCFLDw8q18MxtTnyxF+B8Jm9V6Km3SpwtyTcdIl4k3xQ==", "requires": { + "buffer": "^6.0.3", "date-and-time": "^0.14.2", "date-fns": "^2.17.0", + "events": "^3.3.0", "lodash": "^4.17.21", + "path": "^0.12.7", "pluralize": "^8.0.0", "semver": "^7.3.4", "then-request": "^6.0.2", "xml2js": "^0.4.23" }, "dependencies": { + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "semver": { "version": "7.3.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",