Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/
Date: Sat, 24 Apr 2021 21:02:25
Message-Id: 1619294156.e974bf337cc427283be3e10e986151cba281a023.zmedico@gentoo
1 commit: e974bf337cc427283be3e10e986151cba281a023
2 Author: Marco Sirabella <marco <AT> sirabella <DOT> org>
3 AuthorDate: Sat Apr 24 07:13:28 2021 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sat Apr 24 19:55:56 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e974bf33
7
8 portage/tests: Be a bit more fancy with argparser
9
10 Signed-off-by: Marco Sirabella <marco <AT> sirabella.org>
11 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
12
13 lib/portage/tests/__init__.py | 15 +++++++++------
14 1 file changed, 9 insertions(+), 6 deletions(-)
15
16 diff --git a/lib/portage/tests/__init__.py b/lib/portage/tests/__init__.py
17 index 8712937f8..22124e62e 100644
18 --- a/lib/portage/tests/__init__.py
19 +++ b/lib/portage/tests/__init__.py
20 @@ -62,11 +62,14 @@ def main():
21 suite = unittest.TestSuite()
22 basedir = Path(__file__).resolve().parent
23
24 - usage = "usage: %s [options] [tests to run]" % Path(sys.argv[0]).name
25 + argv0 = Path(sys.argv[0])
26 +
27 + usage = "usage: %s [options] [tests to run]" % argv0.name
28 parser = argparse.ArgumentParser(usage=usage)
29 parser.add_argument("-l", "--list", help="list all tests",
30 action="store_true", dest="list_tests")
31 - options, args = parser.parse_known_args(args=sys.argv)
32 + parser.add_argument("tests", nargs='*', type=Path)
33 + options = parser.parse_args(args=sys.argv)
34
35 if (os.environ.get('NOCOLOR') in ('yes', 'true') or
36 os.environ.get('TERM') == 'dumb' or
37 @@ -74,15 +77,15 @@ def main():
38 portage.output.nocolor()
39
40 if options.list_tests:
41 - testdir = Path(sys.argv[0]).parent
42 + testdir = argv0.parent
43 for mydir in getTestDirs(basedir):
44 testsubdir = mydir.name
45 for name in getTestNames(mydir):
46 print("%s/%s/%s.py" % (testdir, testsubdir, name))
47 return os.EX_OK
48
49 - if len(args) > 1:
50 - suite.addTests(getTestFromCommandLine(args[1:], basedir))
51 + if len(options.tests) > 1:
52 + suite.addTests(getTestFromCommandLine(options.tests[1:], basedir))
53 else:
54 for mydir in getTestDirs(basedir):
55 suite.addTests(getTests(mydir, basedir))
56 @@ -102,7 +105,7 @@ def my_import(name):
57 def getTestFromCommandLine(args, base_path):
58 result = []
59 for arg in args:
60 - realpath = Path(arg).resolve()
61 + realpath = arg.resolve()
62 path = realpath.parent
63 f = realpath.relative_to(path)