From bf1597619a5ffc57e0c306d024ab22a57d22831b Mon Sep 17 00:00:00 2001 From: David Emms <david_emms@hotmail.com> Date: Tue, 6 Sep 2016 16:01:32 +0100 Subject: [PATCH] Refactor unittest argument parsing --- README.md | 2 +- Tests/test_orthofinder.py | 51 +++++++++++++++++++++------------------ orthofinder/__init__.py | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 586a9a6..6b3fe1b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ What does OrthoFinder do? ========== -OrthoFinder is a fast, accurate and comprehensive analysis tool for comparative genomics. It finds orthologs, orthogroups, infers gene trees for all orthogroups and infers a species tree for the species being analysed. OrthoFinder also identifies the root of the species tree and provides lots of useful statistics for comparative genomic analyses. OrthoFinder is very simple to use and all you need to run it is a set of protein sequence files (one per species) in FASTA format . +OrthoFinder is a fast, accurate and comprehensive analysis tool for comparative genomics. It finds orthologues, orthogroups, infers gene trees for all orthogroups and infers a species tree for the species being analysed. OrthoFinder also identifies the root of the species tree and provides lots of useful statistics for comparative genomic analyses. OrthoFinder is very simple to use and all you need to run it is a set of protein sequence files (one per species) in FASTA format . For more details see the OrthoFinder paper below. diff --git a/Tests/test_orthofinder.py b/Tests/test_orthofinder.py index a2b9b27..66b13ae 100755 --- a/Tests/test_orthofinder.py +++ b/Tests/test_orthofinder.py @@ -7,7 +7,6 @@ Created on Wed Dec 16 11:25:10 2015 """ import os -import sys import time import types import datetime @@ -18,6 +17,7 @@ import filecmp import glob import random import csv +import argparse __skipLongTests__ = False @@ -657,28 +657,31 @@ Test to add: """ if __name__ == "__main__": - test = None - if len(sys.argv) == 1: - # run suite - suite = unittest.TestLoader().loadTestsFromTestCase(TestCommandLine) - unittest.TextTestRunner(verbosity=2).run(suite) - else: - if len(sys.argv) > 1: - if sys.argv[1] == "-binary": - qBinary = True - print("Running tests using binary file") - if len(sys.argv) > 2: - test = sys.argv[2] - else: - test = sys.argv[1] - if test == None: - suite = unittest.TestLoader().loadTestsFromTestCase(TestCommandLine) - unittest.TextTestRunner(verbosity=2).run(suite) - else: - suite = unittest.TestSuite() - suite.addTest(TestCommandLine(test)) - runner = unittest.TextTestRunner() - runner.run(suite) - + parser = argparse.ArgumentParser() + parser.add_argument("-b", "--binaries", action="store_true", help="Run tests on binary files") + parser.add_argument("-t", "--test", help="Individual test to run") + parser.add_argument("-d", "--dir", help="Test program in specified directory") + + args = parser.parse_args() + if args.dir: + orthofinder = args.dir + "/orthofinder.py" + orthofinder_bin = os.path.splitext(orthofinder)[0] + trees_for_orthogroups = args.dir + "/trees_from_MSA.py" + trees_for_orthogroups_bin = os.path.splitext(trees_for_orthogroups)[0] + qBinary = args.binaries + print("Testing:") + print(" " + orthofinder_bin if qBinary else orthofinder) + print(" " + trees_for_orthogroups_bin if qBinary else trees_for_orthogroups) + print("") + + if args.test != None: + suite = unittest.TestSuite() + print("Running single test: %s" % args.test) + suite.addTest(TestCommandLine(args.test)) + runner = unittest.TextTestRunner() + runner.run(suite) + else: + suite = unittest.TestLoader().loadTestsFromTestCase(TestCommandLine) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/orthofinder/__init__.py b/orthofinder/__init__.py index 120282a..ffe9e5c 100644 --- a/orthofinder/__init__.py +++ b/orthofinder/__init__.py @@ -1 +1 @@ -__all__ = ["orthofinder", "scripts"] +#__all__ = ["orthofinder", "trees_from_MSA", "scripts"] -- GitLab