Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
3bbde6b4
Commit
3bbde6b4
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for platform and settings modules
parent
728f40f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_platform.py
+134
-0
134 additions, 0 deletions
tests/test_platform.py
tests/test_settings.py
+101
-0
101 additions, 0 deletions
tests/test_settings.py
with
235 additions
and
0 deletions
tests/test_platform.py
0 → 100644
+
134
−
0
View file @
3bbde6b4
#!/usr/bin/env python
#
# test_platform.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
os
import
os.path
as
op
import
shutil
import
tempfile
import
fsl.utils.platform
as
fslplatform
def
test_atts
():
p
=
fslplatform
.
platform
p
.
os
p
.
frozen
p
.
haveGui
p
.
canHaveGui
p
.
inSSHSession
p
.
wxPlatform
p
.
wxFlavour
p
.
fsldir
p
.
fslVersion
p
.
glVersion
p
.
glRenderer
p
.
glIsSoftwareRenderer
def
test_gui
():
import
wx
p
=
fslplatform
.
platform
app
=
wx
.
App
()
frame
=
wx
.
Frame
(
None
)
passed
=
[
False
]
frame
.
Show
()
def
runtest
():
try
:
p
.
haveGui
p
.
wxPlatform
p
.
wxFlavour
passed
[
0
]
=
True
finally
:
frame
.
Destroy
()
app
.
ExitMainLoop
()
wx
.
CallLater
(
500
,
runtest
)
app
.
MainLoop
()
assert
passed
[
0
]
def
test_gl
():
p
=
fslplatform
.
platform
p
.
glVersion
=
'
2.1
'
p
.
glRenderer
=
'
Fake renderer
'
def
test_fsldir
():
# We have to make a dummy directory that looks like FSL
testdir
=
tempfile
.
mkdtemp
()
fsldir
=
op
.
join
(
testdir
,
'
fsl
'
)
def
makeFSL
():
os
.
makedirs
(
op
.
join
(
fsldir
,
'
etc
'
))
with
open
(
op
.
join
(
fsldir
,
'
etc
'
,
'
fslversion
'
),
'
wt
'
)
as
f
:
f
.
write
(
'
Dummy FSL
\n
'
)
try
:
makeFSL
()
p
=
fslplatform
.
platform
newFSLDir
=
[
None
]
def
fsldirChanged
(
p
,
t
,
val
):
newFSLDir
[
0
]
=
val
p
.
register
(
'
callback
'
,
fsldirChanged
)
p
.
fsldir
=
fsldir
p
.
deregister
(
'
callback
'
)
assert
os
.
environ
[
'
FSLDIR
'
]
==
fsldir
assert
newFSLDir
[
0
]
==
fsldir
assert
p
.
fsldir
==
fsldir
assert
p
.
fslVersion
==
'
Dummy FSL
'
finally
:
shutil
.
rmtree
(
testdir
)
def
test_IsWidgetAlive
():
import
wx
passed
=
[
False
]
app
=
wx
.
App
()
frame
=
wx
.
Frame
(
None
)
btn
=
wx
.
Button
(
frame
)
frame
.
Show
()
def
runtest
():
try
:
passed
[
0
]
=
fslplatform
.
isWidgetAlive
(
btn
)
btn
.
Destroy
()
passed
[
0
]
=
passed
[
0
]
and
(
not
fslplatform
.
isWidgetAlive
(
btn
))
finally
:
frame
.
Destroy
()
app
.
ExitMainLoop
()
wx
.
CallLater
(
500
,
runtest
)
app
.
MainLoop
()
assert
passed
[
0
]
This diff is collapsed.
Click to expand it.
tests/test_settings.py
0 → 100644
+
101
−
0
View file @
3bbde6b4
#!/usr/bin/env python
#
# test_settings.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
fsl.utils.settings
as
settings
def
test_strToBool
():
assert
settings
.
strToBool
(
'
FALSE
'
)
is
False
assert
settings
.
strToBool
(
'
False
'
)
is
False
assert
settings
.
strToBool
(
'
false
'
)
is
False
assert
settings
.
strToBool
(
False
)
is
False
assert
settings
.
strToBool
(
'
TRUE
'
)
is
True
assert
settings
.
strToBool
(
'
True
'
)
is
True
assert
settings
.
strToBool
(
'
true
'
)
is
True
assert
settings
.
strToBool
(
True
)
is
True
def
_do_wx_settings_test
(
func
):
import
wx
passed
=
[
False
]
app
=
wx
.
App
()
frame
=
wx
.
Frame
(
None
)
def
wrap
():
try
:
func
()
passed
[
0
]
=
True
finally
:
frame
.
Destroy
()
app
.
ExitMainLoop
()
frame
.
Show
()
wx
.
CallLater
(
500
,
wrap
)
app
.
MainLoop
()
assert
passed
[
0
]
def
test_readwrite
():
_do_wx_settings_test
(
_test_readwrite
)
def
_test_readwrite
():
tests
=
[(
'
string_setting
'
,
'
string_value
'
),
(
'
int_setting
'
,
123
),
(
'
float_setting
'
,
123.0
),
(
'
bool_setting1
'
,
True
),
(
'
bool_setting2
'
,
True
),
(
'
tuple_setting
'
,
(
1
,
2
,
'
blah
'
)),
(
'
list_setting
'
,
[
1
,
2
,
'
blah
'
])]
for
k
,
v
in
tests
:
settings
.
write
(
k
,
v
)
assert
settings
.
read
(
k
)
==
str
(
v
)
assert
settings
.
read
(
'
non-existent
'
)
is
None
assert
settings
.
read
(
'
non-existent
'
,
'
default
'
)
==
'
default
'
def
test_readdefault
():
_do_wx_settings_test
(
_test_readdefault
)
def
_test_readdefault
():
assert
settings
.
read
(
'
non-existent
'
)
is
None
assert
settings
.
read
(
'
non-existent
'
,
'
default
'
)
==
'
default
'
def
test_delete
():
_do_wx_settings_test
(
_test_delete
)
def
_test_delete
():
settings
.
delete
(
'
non-existent
'
)
assert
settings
.
read
(
'
non-existent
'
)
is
None
settings
.
write
(
'
my_setting
'
,
'
abcdef
'
)
assert
settings
.
read
(
'
my_setting
'
)
==
'
abcdef
'
settings
.
delete
(
'
my_setting
'
)
assert
settings
.
read
(
'
my_setting
'
)
is
None
def
test_clear
():
_do_wx_settings_test
(
_test_clear
)
def
_test_clear
():
tests
=
[(
'
setting1
'
,
'
1
'
),
(
'
setting2
'
,
'
2
'
),
(
'
setting3
'
,
'
3
'
)]
for
k
,
v
in
tests
:
settings
.
write
(
k
,
v
)
for
k
,
v
in
tests
:
assert
settings
.
read
(
k
)
==
v
settings
.
clear
()
for
k
,
v
in
tests
:
assert
settings
.
read
(
k
)
is
None
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