Skip to content

Commit dda5786

Browse files
nashifdkalowsk
authored andcommitted
twister: adapt tests for new TestConfiguration class
Adapt test to new test configuration class. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 4d82c48 commit dda5786

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

scripts/tests/twister/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
1616
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
1717
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts"))
18-
from twisterlib.testplan import TestPlan
18+
from twisterlib.testplan import TestPlan, TestConfiguration
1919
from twisterlib.testinstance import TestInstance
2020
from twisterlib.environment import TwisterEnv, add_parse_arguments, parse_arguments
2121

@@ -60,7 +60,7 @@ def testplan_obj(test_data, class_env, testsuites_dir, tmpdir_factory):
6060
env.test_roots = [testsuites_dir + '/tests', testsuites_dir + '/samples']
6161
env.outdir = tmpdir_factory.mktemp("sanity_out_demo")
6262
plan = TestPlan(env)
63-
plan.parse_configuration(config_file=env.test_config)
63+
plan.test_config = TestConfiguration(config_file=env.test_config)
6464
return plan
6565

6666
@pytest.fixture(name='all_testsuites_dict')
@@ -78,7 +78,7 @@ def all_platforms_list(test_data, class_testplan):
7878
Testsuite class and return the Platforms list"""
7979
class_testplan.env.board_roots = [os.path.abspath(os.path.join(test_data, "board_config"))]
8080
plan = TestPlan(class_testplan.env)
81-
plan.parse_configuration(config_file=class_testplan.env.test_config)
81+
plan.test_config = TestConfiguration(config_file=class_testplan.env.test_config)
8282
plan.add_configurations()
8383
return plan.platforms
8484

scripts/tests/twister/test_testplan.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
1818

1919
from twisterlib.statuses import TwisterStatus
20-
from twisterlib.testplan import TestPlan, change_skip_to_error_if_integration
20+
from twisterlib.testplan import TestPlan, TestConfiguration, change_skip_to_error_if_integration
2121
from twisterlib.testinstance import TestInstance
2222
from twisterlib.testsuite import TestSuite
2323
from twisterlib.platform import Platform
@@ -60,7 +60,7 @@ def test_add_configurations_short(test_data, class_env, board_root_dir):
6060
"""
6161
class_env.board_roots = [os.path.abspath(test_data + board_root_dir)]
6262
plan = TestPlan(class_env)
63-
plan.parse_configuration(config_file=class_env.test_config)
63+
plan.test_config = TestConfiguration(class_env.test_config)
6464
if board_root_dir == "board_config":
6565
plan.add_configurations()
6666
print(sorted(plan.default_platforms))
@@ -69,6 +69,7 @@ def test_add_configurations_short(test_data, class_env, board_root_dir):
6969
plan.add_configurations()
7070
assert sorted(plan.default_platforms) != sorted(['demo_board_1'])
7171

72+
plan.levels = plan.test_config.get_levels(plan.scenarios)
7273

7374
def test_get_all_testsuites_short(class_testplan, all_testsuites_dict):
7475
""" Testing get_all_testsuites function of TestPlan class in Twister """
@@ -470,12 +471,12 @@ def test_testplan_parse_configuration(tmp_path, config_yaml, expected_scenarios)
470471
tmp_config_file.write_text(config_yaml)
471472

472473
with pytest.raises(TwisterRuntimeError) if not config_yaml else nullcontext():
473-
testplan.parse_configuration(tmp_config_file)
474-
475-
if not testplan.levels:
476-
assert expected_scenarios == {}
477-
for level in testplan.levels:
478-
assert sorted(level.scenarios) == sorted(expected_scenarios[level.name])
474+
tc = TestConfiguration(tmp_config_file)
475+
testplan.levels = tc.get_levels(testplan.scenarios)
476+
if not testplan.levels:
477+
assert expected_scenarios == {}
478+
for level in testplan.levels:
479+
assert sorted(level.scenarios) == sorted(expected_scenarios[level.name])
479480

480481

481482
TESTDATA_2 = [
@@ -535,7 +536,6 @@ def test_testplan_find_subtests(
535536
(0, 0, [], False, [], TwisterRuntimeError, []),
536537
(1, 1, [], False, [], TwisterRuntimeError, []),
537538
(1, 0, [], True, [], TwisterRuntimeError, ['No quarantine list given to be verified']),
538-
# (1, 0, ['qfile.yaml'], False, ['# empty'], None, ['Quarantine file qfile.yaml is empty']),
539539
(1, 0, ['qfile.yaml'], False, ['- platforms:\n - demo_board_3\n comment: "board_3"'], None, []),
540540
]
541541

@@ -557,15 +557,22 @@ def test_testplan_discover(
557557
exception,
558558
expected_logs
559559
):
560+
# Just a dummy test configuration file
561+
tc = "options: {}\n"
562+
tmp_tc = tmp_path / 'test_config.yaml'
563+
tmp_tc.write_text(tc)
564+
560565
for qf, data in zip(ql, ql_data):
561566
tmp_qf = tmp_path / qf
562567
tmp_qf.write_text(data)
563568

564-
testplan = TestPlan(env=mock.Mock())
569+
env = mock.Mock()
570+
env.test_config = tmp_tc
571+
testplan = TestPlan(env=env)
565572
testplan.options = mock.Mock(
566573
test='ts1',
567574
quarantine_list=[tmp_path / qf for qf in ql],
568-
quarantine_verify=qv,
575+
quarantine_verify=qv
569576
)
570577
testplan.testsuites = {
571578
'ts1': mock.Mock(id=1),
@@ -576,7 +583,7 @@ def test_testplan_discover(
576583
testplan.add_testsuites = mock.Mock(return_value=added_testsuite_count)
577584
testplan.find_subtests = mock.Mock()
578585
testplan.report_duplicates = mock.Mock()
579-
testplan.parse_configuration = mock.Mock()
586+
testplan.test_config = mock.Mock()
580587
testplan.add_configurations = mock.Mock()
581588

582589
with pytest.raises(exception) if exception else nullcontext():
@@ -1113,13 +1120,9 @@ def test_testplan_add_configurations(
11131120
env = mock.Mock(board_roots=[tmp_path / 'boards'], soc_roots=[tmp_path], arch_roots=[tmp_path])
11141121

11151122
testplan = TestPlan(env=env)
1116-
1117-
testplan.test_config = {
1118-
'platforms': {
1119-
'override_default_platforms': override_default_platforms,
1120-
'default_platforms': ['p3', 'p1e1']
1121-
}
1122-
}
1123+
testplan.test_config = mock.Mock()
1124+
testplan.test_config.override_default_platforms = override_default_platforms
1125+
testplan.test_config.default_platforms = ['p3', 'p1e1']
11231126

11241127
def mock_gen_plat(board_roots, soc_roots, arch_roots):
11251128
assert [tmp_path] == board_roots

0 commit comments

Comments
 (0)