Skip to content

Commit

Permalink
Merge pull request #1992 from effigies/rf/clean-filename-tests
Browse files Browse the repository at this point in the history
fix: Small cleanups from recent test fixes
  • Loading branch information
nellh authored Jun 10, 2024
2 parents 07cbca5 + 56bada5 commit 15d1a2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bids-validator/src/deps/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export {
basename,
dirname,
extname,
posix,
fromFileUrl,
parse,
SEPARATOR_PATTERN,
} from 'https://deno.land/[email protected]/path/mod.ts'
export {
globToRegExp,
} from 'https://deno.land/[email protected]/path/glob_to_regexp.ts'
export * as posix from 'https://deno.land/[email protected]/path/posix/mod.ts'
46 changes: 20 additions & 26 deletions bids-validator/src/validators/filenameValidate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,50 @@ 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
.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 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
.getFileIssueKeys(context.file.path)
.includes('ENTITY_WITH_NO_LABEL'),
false,
)
Deno.removeSync(tmpFile)
},
)
Deno.removeSync(tmpDir, { recursive: true })
})

0 comments on commit 15d1a2c

Please sign in to comment.