Skip to content

Commit

Permalink
Added test of no directory specified and testing for multiple files i…
Browse files Browse the repository at this point in the history
…nputs. Added solution to issue #87
  • Loading branch information
kbessonov1984 committed Oct 3, 2024
1 parent 02bc7c7 commit 7481376
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions ectyper/ectyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def create_output_directory(args):
str(datetime.datetime.now().time()).replace(':', '.')
])
out_dir = os.path.join(definitions.WORKPLACE_DIR, date_dir)
LOG.info(f"No output folder specified .... All output will be saved in {out_dir}")
args.output = out_dir
else:
if os.path.isabs(args.output):
Expand Down
8 changes: 5 additions & 3 deletions ectyper/subprocess_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import subprocess
import timeit
import timeit, os

LOG = logging.getLogger(__name__)

Expand All @@ -17,7 +17,8 @@ def run_subprocess(cmd, input_data=None, un=False, ignorereturncode=False):
Returns:
stdout (str): The stdout of cmd
"""

env_copy = os.environ.copy()
env_copy['LC_ALL'] = "C" #issue 87 to get consistent sorting (https://github.com/phac-nml/ecoli_serotyping/issues/87)
start_time = timeit.default_timer()
comp_proc = subprocess.run(
cmd,
Expand All @@ -26,7 +27,8 @@ def run_subprocess(cmd, input_data=None, un=False, ignorereturncode=False):
check=False,
universal_newlines=un,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
env=env_copy
)


Expand Down
33 changes: 31 additions & 2 deletions test/test_complex_inputs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import pytest
import tempfile
import os, json
from ectyper import ectyper
import os, json, logging
from ectyper import ectyper, commandLineOptions



Expand Down Expand Up @@ -66,4 +66,33 @@ def test_invalid_fasta():
assert filesnotfound_dict == {}


def test_no_output_dir_specified():
fastafile=os.path.join(TEST_ROOT, 'Data/Escherichia.fna')
set_input(input=fastafile, output=None)
args = commandLineOptions.parse_command_line()
output_directory = ectyper.create_output_directory(args)
print (output_directory)
assert 'ectyper_' in output_directory, "The output directory does not contain 'ectyper_' pattern"
assert os.path.exists(output_directory), f"{output_directory} does not exist"

def test_multiple_inputs(caplog):
caplog.set_level(logging.DEBUG)
fastafiles=",".join([os.path.join(TEST_ROOT, 'Data/EscherichiaO17H18.fasta'),
os.path.join(TEST_ROOT, 'Data/EscherichiaO28H5.fasta')])


set_input(input=fastafiles, output=os.path.join(TEST_ROOT,"ectyper_multiple_comma_inputs"))
args = commandLineOptions.parse_command_line()
ectyper.run_program()
output_tsv = os.path.join(args.output,"output.tsv")
output_blastn_antigens = os.path.join(args.output,"blastn_output_alleles.txt")
assert os.path.exists(output_tsv), f"File missing {output_tsv}"
with open(output_tsv) as fp:
output_tsv_lines = fp.readlines()
with open(output_blastn_antigens) as fp:
output_blastn_antigens_lines = fp.readlines()
assert any([True if 'O17/O77/O44/O106:H18' in line else False for line in output_tsv_lines]), "No matches of 'O17/O77/O44/O106:H18' serotype"
assert any([True if 'O28/O42:H25' in line else False for line in output_tsv_lines]), "No matches of 'O28/O42:H25' serotype"
assert any([True if 'EscherichiaO17H18' in line else False for line in output_blastn_antigens_lines]), "No matches of 'EscherichiaO17H18' in BLAST output"
assert any([True if 'EscherichiaO28H5' in line else False for line in output_blastn_antigens_lines]), "No matches of 'EscherichiaO28H5' in BLAST output"

1 change: 0 additions & 1 deletion test/test_ectyper_speciesID.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def test_failed_species_identification_nospeciesverify(caplog):
file = os.path.join(TEST_ROOT, 'Data/GCF_001672015.1.fna')
set_input(input=file, verify=False)
ectyper.run_program()
print()
assert "GCF_001672015.1\tEscherichia coli\t-\tH8\t-:H8\t-" in caplog.text


Expand Down

0 comments on commit 7481376

Please sign in to comment.