Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
BioHPC
clair-singularity
Commits
21e88886
Commit
21e88886
authored
Aug 24, 2017
by
David Trudgian
Browse files
Test some non Clair server dependent things
parent
0fa38190
Changes
3
Hide whitespace changes
Inline
Side-by-side
.travis.yml
View file @
21e88886
sudo
:
false
sudo
:
required
dist
:
trusty
language
:
python
python
:
-
"
2.7"
-
"
3.4"
-
"
3.5"
-
"
3.6"
before_install
:
-
wget -O- http://neuro.debian.net/lists/trusty.us-nh.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
-
sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
-
sudo apt-get -qq update
-
sudo apt-get install -y singularity-container
install
:
-
pip install --only-binary=numpy,scipy,scikit-learn numpy scipy scikit-learn
-
pip install --only-binary=numpy,scipy,scikit-learn
,pandas
numpy scipy scikit-learn
pandas
-
pip install flake8 pytest pytest-cov pytest-flake8
-
python setup.py install
script
:
pytest --cov --flake8
script
:
pytest --cov --flake8
clair_singularity/
tests/test_image.py
0 → 100644
View file @
21e88886
import
multiprocessing
import
os
import
subprocess
import
sys
import
time
import
pytest
import
requests
from
clair_singularity.image
import
image_to_tgz
,
check_image
,
http_server
from
clair_singularity.util
import
sha256
@
pytest
.
fixture
def
testimage
(
tmpdir
):
"""Fetch a test singularity image"""
cwd
=
os
.
getcwd
()
os
.
chdir
(
tmpdir
.
strpath
)
# This pulls a singularity hello world image
subprocess
.
call
([
'singularity'
,
'pull'
,
'shub://396'
])
os
.
chdir
(
cwd
)
return
os
.
path
.
join
(
tmpdir
.
strpath
,
'vsoch-singularity-hello-world-master.img'
)
def
check_image
(
testimage
):
# Valid image return True
assert
check_image
(
testimage
)
# Sys exit for invalid image
with
pytest
.
raises
(
SystemExit
)
as
pytest_wrapped_e
:
check_image
(
'i_do_not_exist.img'
)
assert
pytest_wrapped_e
.
type
==
SystemExit
assert
pytest_wrapped_e
.
value
.
code
==
66
def
test_image_to_tgz
(
testimage
):
(
temp_dir
,
tar_file
)
=
image_to_tgz
(
testimage
)
# Should have created a temporary dir
assert
os
.
path
.
isdir
(
temp_dir
)
# The tar.gz should exist
assert
os
.
path
.
isfile
(
tar_file
)
# With the correct sha256
# NO - the tar create in not reproducible (dir/file order?)
# assert sha256(tar_file) == '337436d1b561fd4d174a43474baf742c9d436d4a58a343275322517bad044d75'
# Use simple size check for now
statinfo
=
os
.
stat
(
tar_file
)
assert
statinfo
.
st_size
==
50843856
def
test_http_server
(
testimage
,
tmpdir
):
"""Test we can retrieve the test image from in-built http server"""
httpd
=
multiprocessing
.
Process
(
target
=
http_server
,
args
=
(
os
.
path
.
dirname
(
testimage
),
'127.0.0.1'
,
8088
))
httpd
.
start
()
time
.
sleep
(
2
)
r
=
requests
.
get
(
'http://127.0.0.1:8088/vsoch-singularity-hello-world-master.img'
,
proxies
=
{
'http://127.0.0.1'
:
''
},
stream
=
True
)
tmpfile
=
os
.
path
.
join
(
tmpdir
.
strpath
,
'downloaded.img'
)
# Check the file is good
with
open
(
tmpfile
,
'wb'
)
as
fd
:
for
block
in
r
.
iter_content
(
1024
):
fd
.
write
(
block
)
httpd
.
terminate
()
assert
r
.
status_code
==
requests
.
codes
.
ok
assert
sha256
(
tmpfile
)
==
'4dba283867ee8bd6178cb6f58778bf8b59e14833468fab58c4e52d9eeae7759f'
tests/test_util.py
0 → 100644
View file @
21e88886
import
pytest
from
clair_singularity.util
import
sha256
def
test_sha256
():
"""Check we can get a sha256 on something that won't change often"""
assert
sha256
(
'.gitignore'
)
==
'da04d844bb8a1fd051cfc7cb8bba1437f3f237f48d2974d72f749ad7fbfd1d96'
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment