Commit 6c90be0e authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Merge branch 'secure-tmpdir-removal' into 'develop'

Use pythons context manager to ensure temp dir removal in tests (resolves #44).

Closes #44

See merge request SOaAS/psot!10
parents 09d53eb3 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)
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment