Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
eccc9b28
Commit
eccc9b28
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Test new unambviguous flag to addExt. A few other tweaks
parent
b57dfd23
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_fsl_utils_path.py
+58
-0
58 additions, 0 deletions
tests/test_fsl_utils_path.py
with
58 additions
and
0 deletions
tests/test_fsl_utils_path.py
+
58
−
0
View file @
eccc9b28
...
...
@@ -17,6 +17,8 @@ import pytest
import
fsl.utils.path
as
fslpath
import
fsl.data.image
as
fslimage
from
.
import
testdir
def
make_dummy_file
(
path
):
with
open
(
path
,
'
wt
'
)
as
f
:
...
...
@@ -491,6 +493,11 @@ def test_addExt_noExist():
(
'
file.blob
'
,
'
.img
'
,
allowedExts
,
'
file.blob.img
'
),
(
'
file.blob
'
,
'
img
'
,
None
,
'
file.blobimg
'
),
(
'
file.blob
'
,
'
.img
'
,
None
,
'
file.blob.img
'
),
# If no defaultExt or allowedExts, the
# prefix should be returned unchanged
(
'
file
'
,
None
,
None
,
'
file
'
),
(
'
file.blob
'
,
None
,
None
,
'
file.blob
'
),
]
for
prefix
,
defaultExt
,
allowedExts
,
expected
in
tests
:
...
...
@@ -501,6 +508,46 @@ def test_addExt_noExist():
mustExist
=
False
)
==
expected
def
test_addExt_unambiguous
():
allowedExts
=
fslimage
.
ALLOWED_EXTENSIONS
fileGroups
=
fslimage
.
FILE_GROUPS
# files to create, prefix, file groups, allowedExts, defaultExt, expected,
tests
=
[
(
'
file.img file.hdr
'
,
'
file.img
'
,
None
,
None
,
None
,
'
file.img
'
),
(
'
file.img file.hdr
'
,
'
file.hdr
'
,
None
,
None
,
None
,
'
file.hdr
'
),
(
'
file.img file.hdr
'
,
'
file.hdr
'
,
None
,
None
,
None
,
'
file.hdr
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
None
,
None
,
'
.hdr
'
,
'
file.hdr
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
None
,
None
,
'
.img
'
,
'
file.img
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
None
,
allowedExts
,
None
,
'
file.hdr file.img
'
),
(
'
file.img file.hdr
'
,
'
file.img
'
,
None
,
allowedExts
,
None
,
'
file.img
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
fileGroups
,
allowedExts
,
None
,
'
file.hdr file.img
'
),
(
'
file.img file.hdr
'
,
'
file.img
'
,
fileGroups
,
allowedExts
,
None
,
'
file.img
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
None
,
allowedExts
,
'
.img
'
,
'
file.hdr file.img
'
),
(
'
file.img file.hdr
'
,
'
file.img
'
,
None
,
allowedExts
,
'
.img
'
,
'
file.img
'
),
(
'
file.img file.hdr
'
,
'
file
'
,
fileGroups
,
allowedExts
,
'
.img
'
,
'
file.hdr file.img
'
),
(
'
file.img file.hdr
'
,
'
file.img
'
,
fileGroups
,
allowedExts
,
'
.img
'
,
'
file.img
'
),
]
for
create
,
prefix
,
groups
,
exts
,
defaultExt
,
expected
in
tests
:
create
=
create
.
split
()
expected
=
expected
.
split
()
with
testdir
(
create
)
as
td
:
result
=
fslpath
.
addExt
(
prefix
,
allowedExts
=
exts
,
fileGroups
=
groups
,
defaultExt
=
defaultExt
,
unambiguous
=
False
)
assert
sorted
(
expected
)
==
sorted
(
result
)
def
test_removeExt
():
allowedExts
=
fslimage
.
ALLOWED_EXTENSIONS
...
...
@@ -1071,6 +1118,11 @@ def test_removeDuplicates_otherFiles_shouldPass():
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1 file1.a file2 file2.a
'
,
'
.a .b
'
,
[
'
.a .b
'
],
'
file1.a file2.a
'
),
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1 file2
'
,
'
.a .b
'
,
[
'
.a .b
'
],
'
file1.a file2.a
'
),
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1 file1.a file2
'
,
'
.a .b
'
,
[
'
.a .b
'
],
'
file1.a file2.a
'
),
# no file groups - should still work
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1.a
'
,
''
,
[],
'
file1.a
'
),
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1.a file1.b
'
,
''
,
[],
'
file1.a file1.b
'
),
(
'
file1.a file1.b file2.a file2.b
'
,
'
file1.a file2.a
'
,
''
,
[],
'
file1.a file2.a
'
),
]
...
...
@@ -1254,5 +1306,11 @@ def test_uniquePrefix():
assert
result
==
expected
# test that an error is raised on an invalid path
with
pytest
.
raises
(
fslpath
.
PathError
):
fslpath
.
uniquePrefix
(
op
.
join
(
workdir
,
'
not-a-valid-path
'
))
with
pytest
.
raises
(
fslpath
.
PathError
):
fslpath
.
uniquePrefix
(
op
.
join
(
workdir
,
'
100307
'
))
finally
:
shutil
.
rmtree
(
workdir
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment