Skip to content

Commit

Permalink
fix(tests): Remove assumptions about tmpfile location, clean up
Browse files Browse the repository at this point in the history
OSX tests are failing because we assume temporary files exist in /tmp,
while OSX has different defaults. This creates a temporary file and
splits the returned path to ensure we can point to existing files.
  • Loading branch information
effigies committed Jun 8, 2024
1 parent aa76b84 commit 09e46d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
10 changes: 8 additions & 2 deletions bids-validator/src/validators/filenameIdentify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ Deno.test('test hasMatch', async (t) => {
})

await t.step('No match', async () => {
const fileName = Deno.makeTempFileSync().split('/')[2]
const file = new BIDSFileDeno('/tmp', fileName, ignore)
const tmpFile = Deno.makeTempFileSync()
const parts = tmpFile.split('/')
const file = new BIDSFileDeno(
parts.slice(0, parts.length - 1).join('/'),
parts[parts.length - 1],
ignore,
)

const context = new BIDSContext(fileTree, file, issues)
await hasMatch(schema, context)
Expand All @@ -86,6 +91,7 @@ Deno.test('test hasMatch', async (t) => {
.includes('NOT_INCLUDED'),
true,
)
Deno.removeSync(tmpFile)
})
await t.step('2 matches, no pruning', async () => {
const path = `${PATH}/../bids-examples/fnirs_automaticity`
Expand Down
28 changes: 20 additions & 8 deletions bids-validator/src/validators/filenameValidate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,52 @@ 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) => {
await t.step('File with underscore and no hyphens errors out.', async () => {
const fileName = Deno.makeTempFileSync({
const tmpFile = Deno.makeTempFileSync({
prefix: 'no_labels_',
suffix: '_entities.wav',
}).split('/')[2]
let file = new BIDSFileDeno('/tmp', fileName, ignore)
})
const { dirname, basename } = splitFile(tmpFile)
const file = new BIDSFileDeno(dirname, basename, ignore)

let context = new BIDSContext(fileTree, file, issues)
const context = new BIDSContext(fileTree, file, issues)
await missingLabel(schema, context)
assertEquals(
context.issues
.getFileIssueKeys(context.file.path)
.includes('ENTITY_WITH_NO_LABEL'),
true,
)
Deno.removeSync(tmpFile)
})

await t.step(
"File with underscores and hyphens doesn't error out.",
async () => {
const fileName = Deno.makeTempFileSync({
const tmpFile = Deno.makeTempFileSync({
prefix: 'we-do_have-',
suffix: '_entities.wav',
}).split('/')[2]
let file = new BIDSFileDeno('/tmp', fileName, ignore)
let context = new BIDSContext(fileTree, file, issues)
})
const { dirname, basename } = splitFile(tmpFile)
const file = new BIDSFileDeno(dirname, basename, ignore)
const context = new BIDSContext(fileTree, file, issues)
await missingLabel(schema, context)
assertEquals(
context.issues
.getFileIssueKeys(context.file.path)
.includes('ENTITY_WITH_NO_LABEL'),
false,
)
Deno.removeSync(tmpFile)
},
)
})

0 comments on commit 09e46d6

Please sign in to comment.