Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
psot.repository
Commits
8b138dd0
Commit
8b138dd0
authored
Jan 31, 2018
by
hmueller
Browse files
Use pythons context manager to ensure temp dir removal in tests (resolves #44).
parent
09d53eb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_fetch_informations.py
View file @
8b138dd0
import
unittest
import
pkg_resources
from
tempfile
import
mkdtemp
from
shutil
import
rmtree
from
tempfile
import
TemporaryDirectory
from
subprocess
import
run
import
os.path
import
json
...
...
@@ -9,24 +8,23 @@ import json
class
TestFetchInformations
(
unittest
.
TestCase
):
def
test_that_psot_runs_with_fetch_informations
(
self
):
self
.
run_psot
([
'-i'
])
self
.
run_psot
([
'-i'
])
def
test_that_psot_runs_with_fetch_informations_and_live_results
(
self
):
self
.
run_psot
([
'-i'
,
'-l'
])
self
.
run_psot
([
'-i'
,
'-l'
])
def
run_psot
(
self
,
parameters
):
testdata
=
pkg_resources
.
resource_filename
(
'tests'
,
'data/single.fas'
)
result_directory
=
mkdtemp
()
execution
=
[
"psot"
,
'analyze'
,
'-f'
,
testdata
,
'-o'
,
result_directory
,
'-p'
,
'complete'
]
execution
.
extend
(
parameters
)
proc
=
run
(
execution
)
# first check if the result file exists
expected_file
=
result_directory
+
'/seq_1.cds_10.json'
self
.
assertTrue
(
os
.
path
.
exists
(
expected_file
))
# now check if it is a valid json and contains the id and a non-empty list of results
with
open
(
expected_file
,
'r'
)
as
f
:
result
=
json
.
load
(
f
)
self
.
assertTrue
(
'id'
in
result
)
self
.
assertTrue
(
'computations'
in
result
)
self
.
assertGreater
(
len
(
result
[
'computations'
]),
0
)
rmtree
(
result_directory
)
with
TemporaryDirectory
()
as
result_directory
:
execution
=
[
"psot"
,
'analyze'
,
'-f'
,
testdata
,
'-o'
,
result_directory
,
'-p'
,
'complete'
]
execution
.
extend
(
parameters
)
proc
=
run
(
execution
)
# first check if the result file exists
expected_file
=
result_directory
+
'/seq_1.cds_10.json'
self
.
assertTrue
(
os
.
path
.
exists
(
expected_file
))
# now check if it is a valid json and contains the id and a non-empty list of results
with
open
(
expected_file
,
'r'
)
as
f
:
result
=
json
.
load
(
f
)
self
.
assertTrue
(
'id'
in
result
)
self
.
assertTrue
(
'computations'
in
result
)
self
.
assertGreater
(
len
(
result
[
'computations'
]),
0
)
tests/test_psot.py
View file @
8b138dd0
import
unittest
import
pkg_resources
from
tempfile
import
mkdtemp
from
shutil
import
rmtree
from
tempfile
import
TemporaryDirectory
from
subprocess
import
run
import
os.path
import
json
...
...
@@ -17,16 +16,14 @@ class TestPsot(unittest.TestCase):
testdata
=
pkg_resources
.
resource_filename
(
'tests'
,
'data/single.fas'
)
for
profile
in
profiles
:
with
self
.
subTest
(
profile
=
profile
):
result_directory
=
mkdtemp
()
proc
=
run
([
"psot"
,
'analyze'
,
'-f'
,
testdata
,
'-o'
,
result_directory
,
'-p'
,
profile
])
# first check if the result file exists
expected_file
=
result_directory
+
'/seq_1.cds_10.json'
self
.
assertTrue
(
os
.
path
.
exists
(
expected_file
))
# now check if it is a valid json and contains the id and a non-empty list of results
with
open
(
expected_file
,
'r'
)
as
f
:
result
=
json
.
load
(
f
)
self
.
assertTrue
(
'id'
in
result
)
self
.
assertTrue
(
'computations'
in
result
)
self
.
assertGreater
(
len
(
result
[
'computations'
]),
0
)
rmtree
(
result_directory
)
with
TemporaryDirectory
()
as
result_directory
:
proc
=
run
([
"psot"
,
'analyze'
,
'-f'
,
testdata
,
'-o'
,
result_directory
,
'-p'
,
profile
])
# first check if the result file exists
expected_file
=
result_directory
+
'/seq_1.cds_10.json'
self
.
assertTrue
(
os
.
path
.
exists
(
expected_file
))
# now check if it is a valid json and contains the id and a non-empty list of results
with
open
(
expected_file
,
'r'
)
as
f
:
result
=
json
.
load
(
f
)
self
.
assertTrue
(
'id'
in
result
)
self
.
assertTrue
(
'computations'
in
result
)
self
.
assertGreater
(
len
(
result
[
'computations'
]),
0
)
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