diff --git a/bin/test b/bin/test index 7a95cf0aaa6d..671227c8e3fe 100755 --- a/bin/test +++ b/bin/test @@ -17,6 +17,32 @@ import re from get_sympy import path_hack path_hack() +# callback to support variable length argument in optparse +# docs.python.org/2/library/optparse.html#callback-example-6-variable-arguments +def vararg_callback(option, opt_str, value, parser): + assert value is None + value = [] + + def floatable(str): + try: + float(str) + return True + except ValueError: + return False + + for arg in parser.rargs: + # stop on --foo like options + if arg[:2] == "--" and len(arg) > 2: + break + # stop on -a, but not on -3 or -3.0 + if arg[:1] == "-" and len(arg) > 1 and not floatable(arg): + break + value.append(arg) + + del parser.rargs[:len(value)] + setattr(parser.values, option.dest, value) + + parser = OptionParser() parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False) @@ -27,8 +53,8 @@ parser.add_option("--no-colors", action="store_false", dest="colors", parser.add_option("--force-colors", action="store_true", dest="force_colors", default=False, help="Always use colors, even if the output is not to a terminal.") parser.add_option("-k", dest="kw", - help="only run tests matching the given keyword expression", - metavar="KEYWORD", default="") + help="only run tests matching the given keyword expressions", + metavar="KEYWORDS", action="callback", callback=vararg_callback) parser.add_option("--tb", dest="tb", help="traceback verboseness (short/no) [default: %default]", metavar="TBSTYLE", default="short") diff --git a/sympy/utilities/runtests.py b/sympy/utilities/runtests.py index aae5e0f99766..7e789a97ffde 100644 --- a/sympy/utilities/runtests.py +++ b/sympy/utilities/runtests.py @@ -452,7 +452,10 @@ def _test(*paths, **kwargs): """ verbose = kwargs.get("verbose", False) tb = kwargs.get("tb", "short") - kw = kwargs.get("kw", "") + kw = kwargs.get("kw", []) + # ensure that kw is a tuple (list is fine too) + if isinstance(kw, str): + kw = (kw, ) post_mortem = kwargs.get("pdb", False) colors = kwargs.get("colors", True) force_colors = kwargs.get("force_colors", False) @@ -1136,9 +1139,12 @@ def matches(self, x): Always returns True if self._kw is "". """ - if self._kw == "": + if not self._kw: return True - return x.__name__.find(self._kw) != -1 + for kw in self._kw: + if x.__name__.find(kw) != -1: + return True + return False def get_test_files(self, dir, pat='test_*.py'): """