test_fetch_informations.py 1.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import unittest
import pkg_resources
from tempfile import mkdtemp
from shutil import rmtree
from subprocess import run
import os.path
import json

class TestFetchInformations(unittest.TestCase):

    def test_that_psot_runs_with_fetch_informations(self):
      self.run_psot(['-i'])

    def test_that_psot_runs_with_fetch_informations_and_live_results(self):
      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)