Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
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
base
Commits
661241c8
Commit
661241c8
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
CI: Basic unit tests for wrapper creation/removal
parent
0fa112b4
No related branches found
No related tags found
1 merge request
!1
Enh/create wrapper
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.ci/test_create_remove_wrapper.py
+178
-0
178 additions, 0 deletions
.ci/test_create_remove_wrapper.py
.gitlab-ci.yml
+18
-0
18 additions, 0 deletions
.gitlab-ci.yml
with
196 additions
and
0 deletions
.ci/test_create_remove_wrapper.py
0 → 100755
+
178
−
0
View file @
661241c8
#!/usr/bin/env python
#
# test_create_remove_wrapper.py - Test the createFSLWrapper.sh and
# removeFSLWrapper.sh scripts. Requires Python 3.7.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
os.path
as
op
import
subprocess
as
sp
import
textwrap
as
tw
import
os
import
shlex
import
shutil
import
tempfile
import
contextlib
from
unittest
import
mock
BASE_DIR
=
op
.
abspath
(
op
.
join
(
op
.
dirname
(
__file__
),
'
..
'
))
CREATE_WRAPPER
=
op
.
join
(
BASE_DIR
,
'
etc
'
,
'
fslconf
'
,
'
createFSLWrapper.sh
'
)
REMOVE_WRAPPER
=
op
.
join
(
BASE_DIR
,
'
etc
'
,
'
fslconf
'
,
'
removeFSLWrapper.sh
'
)
def
run
(
cmd
,
**
kwargs
):
return
sp
.
run
(
shlex
.
split
(
cmd
),
check
=
True
,
**
kwargs
)
@contextlib.contextmanager
def
temp_fsldir
():
testdir
=
tempfile
.
mkdtemp
()
prevdir
=
os
.
getcwd
()
fsldir
=
op
.
join
(
testdir
,
'
fsl
'
)
wrapperdir
=
op
.
join
(
testdir
,
'
fsl
'
,
'
share
'
,
'
fsl
'
,
'
bin
'
)
try
:
os
.
chdir
(
testdir
)
os
.
mkdir
(
fsldir
)
with
mock
.
patch
.
dict
(
os
.
environ
,
{
'
FSLDIR
'
:
fsldir
,
'
PREFIX
'
:
fsldir
,
'
FSL_CREATE_WRAPPER_SCRIPTS
'
:
'
1
'
}):
yield
fsldir
,
wrapperdir
finally
:
os
.
chdir
(
prevdir
)
shutil
.
rmtree
(
testdir
)
def
touch
(
path
):
dirname
=
op
.
dirname
(
path
)
if
not
op
.
exists
(
dirname
):
os
.
makedirs
(
dirname
)
with
open
(
path
,
'
wt
'
)
as
f
:
f
.
write
(
'
.
'
)
def
test_env_vars_not_set
():
"""
Test that wrapper scripts are not created if the
FSL_CREATE_WRAPPER_SCRIPTS, FSLDIR, or PREFIX environment variables
are not set.
"""
with
temp_fsldir
()
as
(
fsldir
,
wrapperdir
):
touch
(
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script
'
))
env
=
os
.
environ
.
copy
()
env
.
pop
(
'
FSL_CREATE_WRAPPER_SCRIPTS
'
)
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
,
env
=
env
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
env
=
os
.
environ
.
copy
()
env
.
pop
(
'
FSLDIR
'
)
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
,
env
=
env
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
env
=
os
.
environ
.
copy
()
env
.
pop
(
'
PREFIX
'
)
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
,
env
=
env
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
# FSLDIR invalid
env
=
os
.
environ
.
copy
()
env
[
'
FSLDIR
'
]
=
'
/some/non-existent/path
'
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
,
env
=
env
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
# FSLDIR != PREFIX
env
=
os
.
environ
.
copy
()
env
[
'
FSLDIR
'
]
=
op
.
join
(
env
[
'
PREFIX
'
],
'
other_fsl
'
)
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
,
env
=
env
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
def
test_create_python_wrapper
():
"""
Test creation of a wrapper script for a python executable
"""
with
temp_fsldir
()
as
(
fsldir
,
wrapperdir
):
script_path
=
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script
'
)
wrapper_path
=
op
.
join
(
wrapperdir
,
'
test_script
'
)
touch
(
script_path
)
with
open
(
script_path
,
'
wt
'
)
as
f
:
f
.
write
(
'
#!/usr/bin/env python
\n
'
)
f
.
write
(
'
print(
"
hello
"
)
\n
'
)
expect
=
tw
.
dedent
(
f
"""
#!/usr/bin/env bash
{
fsldir
}
/bin/python -I
{
script_path
}
"
$@
"
"""
).
strip
()
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
)
assert
op
.
exists
(
wrapper_path
)
with
open
(
wrapper_path
,
'
rt
'
)
as
f
:
got
=
f
.
read
().
strip
()
assert
got
==
expect
def
test_create_other_wrapper
():
"""
Test creation of a wrapper script for a non-python executable.
"""
with
temp_fsldir
()
as
(
fsldir
,
wrapperdir
):
script_path
=
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script
'
)
wrapper_path
=
op
.
join
(
wrapperdir
,
'
test_script
'
)
touch
(
script_path
)
with
open
(
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script
'
),
'
wt
'
)
as
f
:
f
.
write
(
'
#!/usr/bin/env bash
\n
'
)
f
.
write
(
'
echo
"
hello
"
\n
'
)
expect
=
tw
.
dedent
(
f
"""
#!/usr/bin/env bash
{
script_path
}
"
$@
"
"""
).
strip
()
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
)
assert
op
.
exists
(
wrapper_path
)
with
open
(
wrapper_path
,
'
rt
'
)
as
f
:
got
=
f
.
read
().
strip
()
assert
got
==
expect
def
test_permissions_preserved
():
"""
Test that wrapper script has same permissions as wrapped script.
"""
with
temp_fsldir
()
as
(
fsldir
,
wrapperdir
):
perms
=
[
0o777
,
0o755
,
0o644
,
0o600
,
0o755
,
0o700
]
script_path
=
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script
'
)
wrapper_path
=
op
.
join
(
wrapperdir
,
'
test_script
'
)
touch
(
script_path
)
for
perm
in
perms
:
os
.
chmod
(
script_path
,
perm
)
run
(
f
'
{
CREATE_WRAPPER
}
test_script
'
)
stat
=
os
.
stat
(
wrapper_path
)
assert
(
stat
.
st_mode
&
0o777
)
==
perm
def
test_create_remove_wrappers
():
"""
Tests normal usage.
"""
with
temp_fsldir
()
as
(
fsldir
,
wrapperdir
):
touch
(
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script1
'
))
touch
(
op
.
join
(
fsldir
,
'
bin
'
,
'
test_script2
'
))
run
(
f
'
{
CREATE_WRAPPER
}
test_script1 test_script2
'
)
assert
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
assert
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script2
'
))
run
(
f
'
{
REMOVE_WRAPPER
}
test_script1 test_script2
'
)
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script1
'
))
assert
not
op
.
exists
(
op
.
join
(
wrapperdir
,
'
test_script2
'
))
This diff is collapsed.
Click to expand it.
.gitlab-ci.yml
0 → 100644
+
18
−
0
View file @
661241c8
include
:
-
project
:
fsl/fsl-ci-rules
file
:
.gitlab-ci.yml
stages
:
-
test
-
fsl-ci-pre
-
fsl-ci-build
-
fsl-ci-deploy
test
:
stage
:
test
image
:
python:3.7
tags
:
-
docker
script
:
-
pip install pytest
-
pytest -v .ci
\ No newline at end of file
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