Skip to content

Commit e4c6bcd

Browse files
committed
Move test parsers to tests.py
1 parent b98c8c1 commit e4c6bcd

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

tools/make.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,13 @@
3838
from tools.paths import UBLOX_LIBRARY
3939
from tools.tests import TESTS, Test, TEST_MAP
4040
from tools.tests import TEST_MBED_LIB
41+
from tools.tests import test_known, test_name_known
4142
from tools.targets import TARGET_MAP
4243
from tools.options import get_default_options_parser
4344
from tools.build_api import build_project
4445
from tools.build_api import mcu_toolchain_matrix
4546
from utils import argparse_filestring_type
4647
from argparse import ArgumentTypeError
47-
try:
48-
import tools.private_settings as ps
49-
except:
50-
ps = object()
51-
52-
def test_known(string):
53-
i = int(string)
54-
if i >= 0 and i < len(TESTS) : return i
55-
else : raise ArgumentTypeError("{0} does not index a test".format(i))
56-
57-
def test_name_known(string):
58-
nlist = string.split(',')
59-
for test_id in nlist:
60-
if test_id not in TEST_MAP.keys():
61-
raise ArgumentTypeError("Program with name '%s' not found"% test_id)
62-
63-
return [TEST_MAP[n].n for n in nlist]
6448

6549
if __name__ == '__main__':
6650
# Parse Options

tools/tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"""
1717
from tools.paths import *
1818
from tools.data.support import *
19+
from argparse import ArgumentTypeError
20+
21+
try:
22+
import tools.private_settings as ps
23+
except:
24+
ps = object()
1925

2026
TEST_CMSIS_LIB = join(TEST_DIR, "cmsis", "lib")
2127
TEST_MBED_LIB = join(TEST_DIR, "mbed", "env")
@@ -1212,3 +1218,19 @@ def __getitem__(self, key):
12121218
return None
12131219

12141220
TEST_MAP = dict([(test['id'], Test(i)) for i, test in enumerate(TESTS)])
1221+
1222+
# parser helpers
1223+
def test_known(string):
1224+
i = int(string)
1225+
if i >= 0 and i < len(TESTS) : return i
1226+
else : raise ArgumentTypeError("{0} does not index a test".format(i))
1227+
1228+
def test_name_known(string):
1229+
nlist = string.split(',')
1230+
for test_id in nlist:
1231+
if test_id not in TEST_MAP.keys():
1232+
if getattr(ps, "test_alias", None) is None or \
1233+
ps.test_alias.get(test_id, "") not in TEST_MAP.keys():
1234+
raise ArgumentTypeError("Program with name '%s' not found"% test_id)
1235+
1236+
return [TEST_MAP[n].n for n in nlist]

0 commit comments

Comments
 (0)