Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-sdk-tools by
Diff: tests.py
- Revision:
- 22:9e85236d8716
- Parent:
- 13:ab47a20b66f0
- Child:
- 24:25bff2709c20
--- a/tests.py Fri Jul 15 22:58:15 2016 +0100 +++ b/tests.py Sat Jul 16 00:34:03 2016 +0100 @@ -16,6 +16,13 @@ """ from tools.paths import * from tools.data.support import * +from argparse import ArgumentTypeError +from utils import columnate + +try: + import tools.private_settings as ps +except: + ps = object() TEST_CMSIS_LIB = join(TEST_DIR, "cmsis", "lib") TEST_MBED_LIB = join(TEST_DIR, "mbed", "env") @@ -1217,3 +1224,19 @@ return None TEST_MAP = dict([(test['id'], Test(i)) for i, test in enumerate(TESTS)]) + +# parser helpers +def test_known(string): + i = int(string) + if i >= 0 and i < len(TESTS): + return i + else: + raise ArgumentTypeError("{0} does not index a test. The accepted range is 0 to {1}\nThe test mapping is:\n{2}".format(i, len(TEST_MAP) - 1, columnate([str(i) + ":" + t['id'] for i,t in zip(range(len(TESTS)), TESTS)]))) + +def test_name_known(string): + if string not in TEST_MAP.keys() and \ + (getattr(ps, "test_alias", None) is None or \ + ps.test_alias.get(test_id, "") not in TEST_MAP.keys()): + raise ArgumentTypeError("Program with name '{0}' not found. Supported tests are: \n{1}".format(string, columnate([t['id'] for t in TESTS]))) + + return TEST_MAP[string].n