Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Small cleanups from recent test fixes #1992

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/std@0.217.0/path/mod.ts'
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'
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 })
})