Skip to content

Commit 0b95fc8

Browse files
committed
feat: get targets filtered by soc attrs
1 parent 54987be commit 0b95fc8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pytest-embedded-idf/pytest_embedded_idf/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from esp_bool_parser import PREVIEW_TARGETS, SUPPORTED_TARGETS
6+
from esp_bool_parser.bool_parser import parse_bool_expr
67

78
supported_targets = ContextVar('supported_targets', default=SUPPORTED_TARGETS)
89
preview_targets = ContextVar('preview_targets', default=PREVIEW_TARGETS)
@@ -90,3 +91,12 @@ def decorator(func):
9091
return pytest.mark.parametrize(','.join(param_list), processed_values, indirect=indirect)(func)
9192

9293
return decorator
94+
95+
96+
def soc_filtered_targets(soc_statement: str) -> t.List[str]:
97+
stm = parse_bool_expr(soc_statement)
98+
result = []
99+
for target in [*supported_targets.get(), *preview_targets.get()]:
100+
if stm.get_value(target, ''):
101+
result.append(target)
102+
return result

pytest-embedded-idf/tests/test_idf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,22 @@ def test_skip_if_for_condition():
11531153
run_test_for_condition(c, cf)
11541154

11551155

1156+
def test_soc_filtered_targets(testdir, copy_mock_esp_idf, monkeypatch): # noqa: ARG001
1157+
monkeypatch.setenv('IDF_PATH', str(testdir))
1158+
from pytest_embedded_idf.utils import soc_filtered_targets
1159+
1160+
assert soc_filtered_targets('SOC_A == 1') == ['esp32c3', 'esp32s3', 'esp32c6', 'esp32c5']
1161+
assert soc_filtered_targets('SOC_A == 1 or SOC_B == 1') == [
1162+
'esp32',
1163+
'esp32c3',
1164+
'esp32s3',
1165+
'esp32c2',
1166+
'esp32c6',
1167+
'esp32h2',
1168+
'esp32c5',
1169+
]
1170+
1171+
11561172
def test_skip_if_soc_target_in_args(testdir, copy_mock_esp_idf, monkeypatch): # noqa: ARG001
11571173
monkeypatch.setenv('IDF_PATH', str(testdir))
11581174

0 commit comments

Comments
 (0)