From 1400ab41cdc586fafa838dd896532b0a17754b5a Mon Sep 17 00:00:00 2001 From: Kirill Bessonov Date: Fri, 22 Dec 2023 23:19:17 -0500 Subject: [PATCH] updated unit tests --- mob_suite/tests/test_mobrecon.py | 11 ++++++----- mob_suite/tests/test_mobtyper.py | 6 ++++-- mob_suite/tests/test_mobtyper_vs_biomarker_report.py | 7 +++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mob_suite/tests/test_mobrecon.py b/mob_suite/tests/test_mobrecon.py index 3a16cd4..9d9d446 100644 --- a/mob_suite/tests/test_mobrecon.py +++ b/mob_suite/tests/test_mobrecon.py @@ -7,13 +7,13 @@ LOG_FORMAT = '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]' logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG) -if not os.path.exists(os.path.join(TEST_ROOT,"run_test")): - os.mkdir(os.path.join(TEST_ROOT,"run_test")) +def check_if_output_dir_exists_and_create(): + if not os.path.exists(os.path.join(TEST_ROOT,"run_test")): + os.mkdir(os.path.join(TEST_ROOT,"run_test")) def test_mob_recon_with_mob_typer_report(): - if os.path.exists("run_test") == False: - os.mkdir("run_test") + check_if_output_dir_exists_and_create() #IncFIB,IncFII multi-plasmids args = [ "--infile", os.path.dirname(__file__) + "/TestData/Pseudomonas/test_contigs.fasta", @@ -28,7 +28,7 @@ def test_mob_recon_with_mob_typer_report(): assert sum(1 for line in open(mobtyper_results_file)) == 2 , "Results file is empty, something went wrong" def test_mob_recon_no_plasmid_biomarkers(): - + check_if_output_dir_exists_and_create() args = [ "--infile", ROOT_MODULE + "/example/assembly_no_biomarkers.fasta", "--outdir", TEST_ROOT + "/run_test/mob_recon_no_plasmid_markers", @@ -41,6 +41,7 @@ def test_mob_recon_no_plasmid_biomarkers(): assert os.path.exists(os.path.join(TEST_ROOT,"run_test/mob_recon_no_plasmid_markers/biomarker_report.txt")) == False def test_mob_recon_typical_run(): + check_if_output_dir_exists_and_create() args = [ "--infile", ROOT_MODULE + "/example/SRR3703080_illumina_unicycler.fasta", "--outdir", TEST_ROOT+"/run_test/mob_recon_SRR3703080", diff --git a/mob_suite/tests/test_mobtyper.py b/mob_suite/tests/test_mobtyper.py index 20d0aa1..973f518 100644 --- a/mob_suite/tests/test_mobtyper.py +++ b/mob_suite/tests/test_mobtyper.py @@ -9,11 +9,13 @@ logger=logging.getLogger(__name__) logger.setLevel(logging.INFO) +def check_if_output_dir_exists_and_create(): + if not os.path.exists(os.path.join(TEST_ROOT,"run_test")): + os.mkdir(os.path.join(TEST_ROOT,"run_test")) def test_mean_and_multireplicon_frame(): logger.info("Testing MOB-typer") - if os.path.exists("run_test") == False: - os.mkdir("run_test") + check_if_output_dir_exists_and_create() args = [ "--infile", os.path.dirname(__file__) + "/TestData/pCAV1453-208.fasta", "--out_file", TEST_ROOT + "/run_test/mobtyper_pCAV1453-208_results.txt", diff --git a/mob_suite/tests/test_mobtyper_vs_biomarker_report.py b/mob_suite/tests/test_mobtyper_vs_biomarker_report.py index 096d8eb..ab613b0 100644 --- a/mob_suite/tests/test_mobtyper_vs_biomarker_report.py +++ b/mob_suite/tests/test_mobtyper_vs_biomarker_report.py @@ -23,10 +23,13 @@ def clean_missing_dashes(L): return [i for i in L if i != '-'] +def check_if_output_dir_exists_and_create(): + if not os.path.exists(os.path.join(TEST_ROOT,"run_test")): + os.mkdir(os.path.join(TEST_ROOT,"run_test")) + def test_mean_and_multireplicon_frame(mode = None): - if os.path.exists("run_test") == False: - os.mkdir("run_test") + check_if_output_dir_exists_and_create() if mode == None: return 0