diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe551a831b4a550d8cab630aaf71246a5bd59f5a..88daf3499f43e448eea715c1231d05cdda0bf185 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -113,7 +113,6 @@ func-test-ubuntu: # - py.test test/test_functional/test_align* -vx - py.test test/test_functional/test_align-parser.py -vx - py.test test/test_functional/test_tree* -vx - - py.test test/test_functional/test_tree-parser.py -vx - py.test test/test_functional/test_annote-parser.py -vx - py.test test/test_functional/test_annote.py -xv - mv .coverage .coverage-functional diff --git a/PanACoTA/subcommands/prepare.py b/PanACoTA/subcommands/prepare.py index 135628d52eca8b7864bbed4b56c48796daf9b5bf..ebe85ea69753ca1d6e2bac136df10d14f4a635e9 100644 --- a/PanACoTA/subcommands/prepare.py +++ b/PanACoTA/subcommands/prepare.py @@ -245,7 +245,7 @@ def main(cmd, NCBI_species, NCBI_taxid, levels, outdir, tmp_dir, threads, no_ref else: logger.warning('You asked to run only mash steps.') if not os.path.exists(info_file): # info-file missing -> error and exit - logger.error(f"Your info file {info_file} does not exist. Please Provide the " + logger.error(f"Your info file {info_file} does not exist. Please provide the " "right name/path, or remove the '--mash-only option to rerun " "quality control.") sys.exit(1) diff --git a/PanACoTA/utils.py b/PanACoTA/utils.py index 090435061f416fb25ed06fdd9fc785f341d8daf6..9828d464b413ea503e7cf1a27daf808c623028ed 100755 --- a/PanACoTA/utils.py +++ b/PanACoTA/utils.py @@ -824,7 +824,7 @@ def read_genomes_info(list_file, name, date=None, logger=None): if len(genomes) > 0: logger.info(("Found {} genomes in total").format(len(genomes))) else: - logger.error(f"no genome listed in {list_file} were found.") + logger.error(f"No genome listed in {list_file} was found.") sys.exit(1) return genomes diff --git a/PanACoTA/utils_argparse.py b/PanACoTA/utils_argparse.py index 9f4d1e4b2eb63996fe03bcbea325dc41162300fd..f553a571f80c99d7e5ed42793dd165306558f03b 100644 --- a/PanACoTA/utils_argparse.py +++ b/PanACoTA/utils_argparse.py @@ -120,6 +120,6 @@ def mash_dist(param): msg = f"error: mash distance: invalid float value: '{param}'" raise argparse.ArgumentTypeError(msg) if param < 0 or param > 1: - msg = f"error: mash_distance must be between 0 and 1: invalid value: '{param}'" + msg = f"error: mash distance must be between 0 and 1: invalid value: '{param}'" raise argparse.ArgumentTypeError(msg) return param diff --git a/test/test_functional/test_annote.py b/test/test_functional/test_annote.py index 950a6179548d7b7ddc772b7c5318826bb887ed1a..e4c3ca1c21d6124c2010968289cc6f30d02ca45c 100755 --- a/test/test_functional/test_annote.py +++ b/test/test_functional/test_annote.py @@ -582,8 +582,8 @@ def test_main_novalid_genome_frominfo(capsys): prodigal_only=True, small=True) out, err = capsys.readouterr() # Check logs - assert ("no genome listed in test/data/annotate/test_files/lstinfo-no-genome.lst " - "were found.") in err + assert ("No genome listed in test/data/annotate/test_files/lstinfo-no-genome.lst " + "was found.") in err # Check output folders not created protdir = os.path.join(GENEPATH, "Proteins") diff --git a/test/test_functional/test_corepers.py b/test/test_functional/test_corepers.py index d4e778ca64528dbc547c81b125893bdca3ee0ae0..9d07b7999f5b76afe15585021d3f08d875b11567 100755 --- a/test/test_functional/test_corepers.py +++ b/test/test_functional/test_corepers.py @@ -34,7 +34,8 @@ def setup_teardown_module(): - remove all log files - remove directory with generated results """ - os.mkdir(GENEPATH) + if not os.path.isdir(GENEPATH): + os.mkdir(GENEPATH) shutil.copyfile(OPAN, UPAN) print("setup") diff --git a/test/test_functional/test_prepare-parser.py b/test/test_functional/test_prepare-parser.py index 30d7a4fbed986359289a78edda07b15462f764df..b05717101897e61ef17b9d980e29b6751b417bf3 100644 --- a/test/test_functional/test_prepare-parser.py +++ b/test/test_functional/test_prepare-parser.py @@ -164,12 +164,12 @@ def test_max_mash_dist(capsys): with pytest.raises(SystemExit): prepare.parse(parser, "--max_dist 1.5".split()) _, err = capsys.readouterr() - assert "error: mash_distance must be between 0 and 1: invalid value: '1.5'" in err + assert "error: mash distance must be between 0 and 1: invalid value: '1.5'" in err # < 0 with pytest.raises(SystemExit): prepare.parse(parser, "--max_dist -0.5".split()) _, err = capsys.readouterr() - assert "error: mash_distance must be between 0 and 1: invalid value: '-0.5'" in err + assert "error: mash distance must be between 0 and 1: invalid value: '-0.5'" in err def test_min_mash_dist(capsys): @@ -191,12 +191,12 @@ def test_min_mash_dist(capsys): with pytest.raises(SystemExit): prepare.parse(parser, "--min_dist 1.5".split()) _, err = capsys.readouterr() - assert "error: mash_distance must be between 0 and 1: invalid value: '1.5'" in err + assert "error: mash distance must be between 0 and 1: invalid value: '1.5'" in err # < 0 with pytest.raises(SystemExit): prepare.parse(parser, "--min_dist -0.5".split()) _, err = capsys.readouterr() - assert "error: mash_distance must be between 0 and 1: invalid value: '-0.5'" in err + assert "error: mash distance must be between 0 and 1: invalid value: '-0.5'" in err def test_min_sup_max(capsys): diff --git a/test/test_functional/test_prepare.py b/test/test_functional/test_prepare.py index f60f3d72d21359aeb51556ba11eae2143dab3eaf..4a84da725e45cc45dea21e0b0ddbaeccc2dd5f06 100644 --- a/test/test_functional/test_prepare.py +++ b/test/test_functional/test_prepare.py @@ -485,3 +485,87 @@ def test_only_mash(capsys): assert tutil.compare_order_content(out_lst, exp_lst) +def test_only_mash_empty_lstinfo(capsys): + """ + Running only mash step giving an empty lstinfo file -> error, no genome found + """ + NCBI_species = "" + NCBI_taxid = "" + levels = "" + outdir = GENEPATH + tmp_dir = "" + threads = 1 + no_refseq = False + db_dir = "" + only_mash = True + # Create empty lstinfo file + info_file = os.path.join(GENEPATH, "LSTINFO-empty.lst") + open(info_file, "w").close() + l90 = 100 + nbcont = 999 + cutn = 5 + min_dist = 1e-4 + max_dist = 0.06 + verbose = 1 + quiet = False + with pytest.raises(SystemExit): + prepare.main("cmd", NCBI_species, NCBI_taxid, levels, outdir, tmp_dir, threads, no_refseq, + db_dir, only_mash, info_file, l90, nbcont, cutn, min_dist, max_dist, + verbose, quiet) + out, err = capsys.readouterr() + assert ("You asked to run only mash steps") in err + assert ("You want to run only mash steps. Getting information from " + "test/data/prepare/generated_by_func-tests/LSTINFO-empty.lst") in out + assert ("No genome listed in test/data/prepare/generated_by_func-tests/LSTINFO-empty.lst " + "was found.") in err + + # Check output files + assert len(os.listdir(os.path.join(outdir, "tmp_files"))) == 0 + # Check logfiles are here + log_files = glob.glob(os.path.join(outdir, "*log*")) + assert len(log_files) == 3 + # Check lstinfo file is still here and still empty + assert os.stat(info_file).st_size == 0 + + +def test_only_mash_no_lstinfo(capsys): + """ + Running only mash step giving an info file which does not exist -> error missing infofile + """ + NCBI_species = "" + NCBI_taxid = "" + levels = "" + outdir = GENEPATH + tmp_dir = "" + threads = 1 + no_refseq = False + db_dir = "" + only_mash = True + # Create empty lstinfo file + info_file = "info_file.lst" + l90 = 100 + nbcont = 999 + cutn = 5 + min_dist = 1e-4 + max_dist = 0.06 + verbose = 1 + quiet = False + with pytest.raises(SystemExit): + prepare.main("cmd", NCBI_species, NCBI_taxid, levels, outdir, tmp_dir, threads, no_refseq, + db_dir, only_mash, info_file, l90, nbcont, cutn, min_dist, max_dist, + verbose, quiet) + out, err = capsys.readouterr() + assert ("You asked to run only mash steps") in err + assert ("Your info file info_file.lst does not exist. Please provide the " + "right name/path, or remove the '--mash-only option to rerun " + "quality control.") in err + + # Check output files + assert len(os.listdir(os.path.join(outdir, "tmp_files"))) == 0 + # Check logfiles are here + log_files = glob.glob(os.path.join(outdir, "*log*")) + assert len(log_files) == 3 + # Check that outdir contains only 4 elements: 3 logs + tmp_files repo + files = os.listdir(outdir) + files = [f for f in files if "fuse" not in f] + assert len(files) == 4 diff --git a/test/test_unit/test_utils-argparse.py b/test/test_unit/test_utils-argparse.py index 61d3efded931314bb15b71590b85aa1d2b4912f3..fb2a35cc3b940a22f2ddd0e41261ba6d41189c65 100644 --- a/test/test_unit/test_utils-argparse.py +++ b/test/test_unit/test_utils-argparse.py @@ -97,3 +97,39 @@ def test_thread_num(): assert ("Please provide a positive number of threads (or 0 for all threads): " "Invalid value: -1") in str(err.value) assert autils.thread_num(0) == nb_cpu + + +def test_positive_int(): + """ + Test checking that given argument is a positive integer + """ + assert autils.positive_int("1") == 1 + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.positive_int("1.1") + assert ("argument --cutn: invalid int value: '1.1'") in str(err.value) + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.positive_int("-1") + assert ("error: argument --cutn must be a positive integer: " + "invalid int value: '-1'") in str(err.value) + + +def test_mash_dist(): + """ + Test checking that given value is ok for a mash distance + """ + assert autils.mash_dist("0.05") == 0.05 + assert autils.mash_dist("1e-4") == 0.0001 + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.mash_dist("1.1.1") + assert ("error: mash distance: invalid float value: '1.1.1'") in str(err.value) + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.mash_dist("one") + assert ("error: mash distance: invalid float value: 'one'") in str(err.value) + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.mash_dist("1.000001") + assert ("error: mash distance must be between 0 and 1: " + "invalid value: '1.000001'") in str(err.value) + with pytest.raises(argparse.ArgumentTypeError) as err: + a = autils.mash_dist("-1e-4") + assert ("error: mash distance must be between 0 and 1: " + "invalid value: '-0.0001'") in str(err.value) diff --git a/test/test_unit/test_utils-logging.py b/test/test_unit/test_utils-logging.py index 0f093f93fcb4b9557267740cb1c17f41823141c9..8c59c708d49372ab32d7316040cf6c8d553b1422 100755 --- a/test/test_unit/test_utils-logging.py +++ b/test/test_unit/test_utils-logging.py @@ -20,11 +20,16 @@ def setup_teardown_module(): """ # Init logger to level detail (15) # utils.init_logger(LOGFILE_BASE, logging.DEBUG, 'test_utils', verbose=1) - os.mkdir(GENEPATH) + if os.path.isdir(GENEPATH): + content = os.listdir(GENEPATH) + for f in content: + assert f.startswith(".fuse") + else: + os.mkdir(GENEPATH) print("setup") yield - shutil.rmtree(GENEPATH) + shutil.rmtree(GENEPATH, ignore_errors=True) print("teardown") @@ -288,7 +293,9 @@ def test_logger_info_verbose1(capsys): assert "info warning" in err assert "info error" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") @@ -322,7 +329,9 @@ def test_logger_info_verbose2(capsys): assert "info warning" in err assert "info error" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") @@ -354,7 +363,9 @@ def test_logger_warning(capsys): assert "info info" in out assert "info error" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") @@ -387,7 +398,9 @@ def test_logger_warning_verbose1(capsys): assert "info error" in err assert "info warning" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") @@ -421,7 +434,9 @@ def test_logger_warning_verbose2(capsys): assert "info error" in err assert "info warning" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") @@ -454,7 +469,9 @@ def test_logger_critical(capsys): assert "info info" in out assert "info error" in err assert "info critical" in err - assert len(os.listdir(GENEPATH)) == 2 + files = os.listdir(GENEPATH) + files = [f for f in files if "fuse" not in f] + assert len(files) == 2 with open(logfile + ".log", "r") as logf: assert logf.readline().endswith(" :: INFO :: info info\n") assert logf.readline().endswith(" :: WARNING :: info warning\n") diff --git a/test/test_unit/test_utils.py b/test/test_unit/test_utils.py index 83917d1a76e4bc887f654665bea7789d91cfeea1..cd653d4ed87a32ff1d392d4e8e872f3938454942 100755 --- a/test/test_unit/test_utils.py +++ b/test/test_unit/test_utils.py @@ -660,8 +660,8 @@ def test_read_genomes_info_no_genomes(caplog): utils.read_genomes_info(lstinfo_file, name) assert ("Reading given information on your genomes in " "test/data/annotate/test_files/lstinfo-no-genome.lst") in caplog.text - assert ("no genome listed in test/data/annotate/test_files/lstinfo-no-genome.lst " - "were found.") in caplog.text + assert ("No genome listed in test/data/annotate/test_files/lstinfo-no-genome.lst " + "was found.") in caplog.text def test_read_genomes_info_ok(caplog):