From 9bba8a49f1172e7bdb155a5d70b19743c09a5c0b Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 10 Jun 2024 08:11:48 -0400 Subject: [PATCH 1/2] fix: Import posix mod separately, as path.posix is deprecated --- bids-validator/src/deps/path.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bids-validator/src/deps/path.ts b/bids-validator/src/deps/path.ts index 0c24472c3..a74f07300 100644 --- a/bids-validator/src/deps/path.ts +++ b/bids-validator/src/deps/path.ts @@ -5,7 +5,6 @@ export { basename, dirname, extname, - posix, fromFileUrl, parse, SEPARATOR_PATTERN, @@ -13,3 +12,4 @@ export { export { globToRegExp, } from 'https://deno.land/std@0.217.0/path/glob_to_regexp.ts' +export * as posix from 'https://deno.land/std@0.217.0/path/posix/mod.ts' From 56bada5ac051a50f5d33ff8f4565d14e812c5855 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 10 Jun 2024 11:13:04 -0400 Subject: [PATCH 2/2] fix(test): Avoid explicit /tmp, use fresh issues and clean up tmpdir --- .../src/validators/filenameValidate.test.ts | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/bids-validator/src/validators/filenameValidate.test.ts b/bids-validator/src/validators/filenameValidate.test.ts index 2f349c3cc..02ffe82fa 100644 --- a/bids-validator/src/validators/filenameValidate.test.ts +++ b/bids-validator/src/validators/filenameValidate.test.ts @@ -9,28 +9,21 @@ import { FileIgnoreRules } from '../files/ignore.ts' import { loadSchema } from '../setup/loadSchema.ts' const schema = (await loadSchema()) as unknown as GenericSchema -const fileTree = new FileTree('/tmp', '/') -const issues = new DatasetIssues() const ignore = new FileIgnoreRules([]) -const splitFile = (path: string) => { - const parts = path.split('/') - return { - dirname: parts.slice(0, parts.length - 1).join('/'), - basename: parts[parts.length - 1], - } -} - Deno.test('test missingLabel', async (t) => { + const tmpDir = Deno.makeTempDirSync() + const fileTree = new FileTree(tmpDir, '/') await t.step('File with underscore and no hyphens errors out.', async () => { - const tmpFile = Deno.makeTempFileSync({ - prefix: 'no_labels_', - suffix: '_entities.wav', - }) - const { dirname, basename } = splitFile(tmpFile) - const file = new BIDSFileDeno(dirname, basename, ignore) + const basename = 'no_label_entities.wav' + Deno.writeTextFileSync(`${tmpDir}/${basename}`, '') + + const context = new BIDSContext( + fileTree, + new BIDSFileDeno(tmpDir, `/${basename}`, ignore), + new DatasetIssues(), + ) - const context = new BIDSContext(fileTree, file, issues) await missingLabel(schema, context) assertEquals( context.issues @@ -38,19 +31,20 @@ Deno.test('test missingLabel', async (t) => { .includes('ENTITY_WITH_NO_LABEL'), true, ) - Deno.removeSync(tmpFile) }) await t.step( "File with underscores and hyphens doesn't error out.", async () => { - const tmpFile = Deno.makeTempFileSync({ - prefix: 'we-do_have-', - suffix: '_entities.wav', - }) - const { dirname, basename } = splitFile(tmpFile) - const file = new BIDSFileDeno(dirname, basename, ignore) - const context = new BIDSContext(fileTree, file, issues) + const basename = 'we-do_have-some_entities.wav' + Deno.writeTextFileSync(`${tmpDir}/${basename}`, '') + + const context = new BIDSContext( + fileTree, + new BIDSFileDeno(tmpDir, `/${basename}`, ignore), + new DatasetIssues(), + ) + await missingLabel(schema, context) assertEquals( context.issues @@ -58,7 +52,7 @@ Deno.test('test missingLabel', async (t) => { .includes('ENTITY_WITH_NO_LABEL'), false, ) - Deno.removeSync(tmpFile) }, ) + Deno.removeSync(tmpDir, { recursive: true }) })