| 
0
 | 
     1 #!/usr/bin/env python3
 | 
| 
 | 
     2 import unittest
 | 
| 
 | 
     3 import os
 | 
| 
 | 
     4 import subprocess
 | 
| 
 | 
     5 
 | 
| 
 | 
     6 
 | 
| 
 | 
     7 test_names = ["test1", "test3"]
 | 
| 
 | 
     8 test_data = {
 | 
| 
 | 
     9     test_names[0]: "data/test_isolate_01.fa",  # Test published resistance
 | 
| 
 | 
    10     test_names[1]: "data/test_isolate_03.fa",  # Test no resistance
 | 
| 
 | 
    11 }
 | 
| 
 | 
    12 run_test_dir = "unit_tests"
 | 
| 
 | 
    13 blast_out_dir = "blast_out"
 | 
| 
 | 
    14 
 | 
| 
 | 
    15 configs = {}
 | 
| 
 | 
    16 
 | 
| 
 | 
    17 
 | 
| 
 | 
    18 class ResFinderTest(unittest.TestCase):
 | 
| 
 | 
    19 
 | 
| 
 | 
    20     def setUp(self):
 | 
| 
 | 
    21         # Change working dir to test dir
 | 
| 
 | 
    22         os.chdir(os.path.dirname(os.path.realpath(__file__)))
 | 
| 
 | 
    23         # Does not allow running two tests in parallel
 | 
| 
 | 
    24         os.makedirs(run_test_dir, exist_ok=False)
 | 
| 
 | 
    25         with open("test_config.txt", "r") as fh:
 | 
| 
 | 
    26             for line in fh:
 | 
| 
 | 
    27                 line = line.rstrip()
 | 
| 
 | 
    28 
 | 
| 
 | 
    29                 if not(line):
 | 
| 
 | 
    30                     continue
 | 
| 
 | 
    31 
 | 
| 
 | 
    32                 if(line.startswith("#")):
 | 
| 
 | 
    33                     continue
 | 
| 
 | 
    34 
 | 
| 
 | 
    35                 key, path = line.split()
 | 
| 
 | 
    36                 configs[key] = path
 | 
| 
 | 
    37 
 | 
| 
 | 
    38     def test_run_resfinder(self):
 | 
| 
 | 
    39 
 | 
| 
 | 
    40         test1_dir = run_test_dir + "/" + test_names[0]
 | 
| 
 | 
    41         test1_blast_dir = test1_dir + "/" + blast_out_dir
 | 
| 
 | 
    42         os.makedirs(test1_dir)
 | 
| 
 | 
    43         os.makedirs(test1_blast_dir)
 | 
| 
 | 
    44 
 | 
| 
 | 
    45         cmd = ("python3 ../ResFinder.py"
 | 
| 
 | 
    46                + " -i " + test_data[test_names[0]]
 | 
| 
 | 
    47                + " -o " + test1_blast_dir
 | 
| 
 | 
    48                + " -p " + configs["resfinder_dbs"]
 | 
| 
 | 
    49                + " -l 0.6"
 | 
| 
 | 
    50                + " -t 0.9")
 | 
| 
 | 
    51 
 | 
| 
 | 
    52         print("Run cmd: " + cmd)
 | 
| 
 | 
    53 
 | 
| 
 | 
    54         process = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE,
 | 
| 
 | 
    55                                  stderr=subprocess.PIPE)
 | 
| 
 | 
    56 
 | 
| 
 | 
    57         outs = process.stdout.decode()
 | 
| 
 | 
    58         errs = process.stderr.decode()
 | 
| 
 | 
    59 
 | 
| 
 | 
    60         self.assertNotIn("Error", errs)
 | 
| 
 | 
    61 
 | 
| 
 | 
    62 
 | 
| 
 | 
    63 if __name__ == "__main__":
 | 
| 
 | 
    64     unittest.main()
 |