Skip to content

Commit

Permalink
fixed pytest issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kbessonov1984 committed Jul 31, 2024
1 parent 41a5093 commit 8002091
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ectyper/speciesIdentification.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def verify_ecoli_and_inputs(fasta_fastq_files_dict, ofiles, filesnotfound, args)
ecoli_files_dict = {}
other_files_dict = {}
filesnotfound_dict = {}
failverifyerrormessage = ''

fasta_files = fasta_fastq_files_dict.keys()

Expand All @@ -279,7 +280,7 @@ def verify_ecoli_and_inputs(fasta_fastq_files_dict, ofiles, filesnotfound, args)
raise ValueError(error_msg)

if is_valid_fasta_file(fasta, sampleName) == False:
failverifyerrormessage = f"Sample {sampleName} FASTA file ({fasta}) is invalid/empty. This could happen when FASTA file generated from FASTQ input lacks raw reads mapping to O- and H- antigens database or input FASTA is empty/corrupted. Please check sequence input file of {sampleName}"
failverifyerrormessage += f"Sample {sampleName} FASTA file ({fasta}) is invalid/empty. This could happen when FASTA file generated from FASTQ input lacks raw reads mapping to O- and H- antigens or input FASTA is corrupted. Please check sequence input file '{sampleName}'."


#do species always regardless of --verify param. Do prediction on fastq files if available for better accuracy
Expand All @@ -290,7 +291,7 @@ def verify_ecoli_and_inputs(fasta_fastq_files_dict, ofiles, filesnotfound, args)
speciesname = get_species(fasta, args, args.cores)

if args.verify:
failverifyerrormessage = "Sample identified as " + speciesname + ": serotyping results are only available for E.coli samples." \
failverifyerrormessage += "Sample identified as " + speciesname + ": serotyping results are only valid for E.coli samples." \
"If sure that sample is E.coli run without --verify parameter."
if re.match("Escherichia coli", speciesname):
ecoli_files_dict[sampleName] = {"species":speciesname,
Expand Down
4 changes: 2 additions & 2 deletions test/test_complex_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def test_emtpy_BLAST_antigen_hits(tmpdir):

def test_invalid_fasta():
fastafile=os.path.join(TEST_ROOT, 'Data/invalid_fasta.fasta')
set_input(input=fastafile, verify=False, refseqmash=True)
set_input(input=fastafile, verify=True, refseqmash=True)
args = ectyper.commandLineOptions.parse_command_line()
ecoli_files_dict, other_files_dict,filesnotfound_dict = ectyper.speciesIdentification.verify_ecoli_and_inputs(fasta_fastq_files_dict={fastafile:''}, ofiles=[], filesnotfound=[], args=args)
assert ecoli_files_dict == {}
assert other_files_dict['invalid_fasta']['error'] != ''
assert 'is empty' in other_files_dict['invalid_fasta']['error'], f'"is empty" not found in "{other_files_dict['invalid_fasta']['error']}"'
assert 'is invalid/empty' in other_files_dict['invalid_fasta']['error'], f'"is invalid/empty" not found in "{other_files_dict['invalid_fasta']['error']}"'
assert filesnotfound_dict == {}


Expand Down
9 changes: 5 additions & 4 deletions test/test_ectyper_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def set_input(input,
percent_iden=None,
verify = True,
output=tempfile.mkdtemp(),
maxdirdepth=0,
cores=1,
print_sequence=False):
"""
Expand All @@ -27,7 +28,7 @@ def set_input(input,
:return: None
"""
args = ['-i', input,
#'-r', os.path.join(TEST_ROOT, 'Data/test_sketch.msh'),
'--maxdirdepth', str(maxdirdepth),
'-c', str(cores)]

if percent_iden:
Expand Down Expand Up @@ -134,10 +135,10 @@ def test_multiple_directories(caplog):
:return: None
"""
the_dir = os.path.join(TEST_ROOT, 'Data/test_dir')
set_input(the_dir, cores=4, verify=True, print_sequence=True)
set_input(the_dir, cores=4, verify=True, maxdirdepth=1, print_sequence=True)
ectyper.run_program()
assert any([True if re.match(r".+sample2.+WARNING\s+\(WRONG\s+SPECIES\)", line) else False for line in caplog.text.splitlines()]), "Issue with sample2"
assert any([True if re.match(r".+sample3.+WARNING\s+\(WRONG\s+SPECIES\)", line) else False for line in caplog.text.splitlines()]), "Issue with sample3"
assert any([True if re.match(r".+sample2.+WARNING\s+\(WRONG\s+SPECIES\)", line) else False for line in caplog.text.splitlines()]), "Issue with sample 2"
assert any([True if re.match(r".+sample3.+WARNING\s+\(WRONG\s+SPECIES\)", line) else False for line in caplog.text.splitlines()]), "Issue with sample 3"
assert any([True if re.match(r".+sample4.+WARNING\s+\(WRONG\s+SPECIES\)", line) else False for line in caplog.text.splitlines()]), "Issue with sample 4"
assert any([True if re.match(r".+badfasta.+WARNING\s+\(WRONG\s+SPECIES\).+Non fasta / fastq file", line) else False for line in caplog.text.splitlines()]), "Issue with badfasta"
assert any([True if re.match(r".+sample.fasta.+WARNING\s+\(WRONG\s+SPECIES\).+Non fasta / fastq file", line) else False for line in caplog.text.splitlines()]), "Issue with sample.fasta"
Expand Down

0 comments on commit 8002091

Please sign in to comment.