From 8002091fdcf783be8f3d18de2e4ceb87c08b3f6d Mon Sep 17 00:00:00 2001 From: Kirill Bessonov Date: Tue, 30 Jul 2024 22:57:04 -0400 Subject: [PATCH] fixed pytest issues --- ectyper/speciesIdentification.py | 5 +++-- test/test_complex_inputs.py | 4 ++-- test/test_ectyper_integration.py | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ectyper/speciesIdentification.py b/ectyper/speciesIdentification.py index b02360c..0b74294 100644 --- a/ectyper/speciesIdentification.py +++ b/ectyper/speciesIdentification.py @@ -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() @@ -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 @@ -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, diff --git a/test/test_complex_inputs.py b/test/test_complex_inputs.py index e3e7e8b..d90e8d0 100644 --- a/test/test_complex_inputs.py +++ b/test/test_complex_inputs.py @@ -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 == {} diff --git a/test/test_ectyper_integration.py b/test/test_ectyper_integration.py index 998aa17..efe7a80 100644 --- a/test/test_ectyper_integration.py +++ b/test/test_ectyper_integration.py @@ -17,6 +17,7 @@ def set_input(input, percent_iden=None, verify = True, output=tempfile.mkdtemp(), + maxdirdepth=0, cores=1, print_sequence=False): """ @@ -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: @@ -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"