2024-01-12 08:42:00 -05:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
2023-11-28 08:38:47 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2024-01-30 05:18:41 -05:00
|
|
|
import textwrap
|
2023-11-28 08:38:47 -05:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from idf_pytest.constants import CollectMode
|
2023-12-18 09:29:58 -05:00
|
|
|
from idf_pytest.script import get_pytest_cases
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
TEMPLATE_SCRIPT = '''
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
def test_foo_single(dut):
|
|
|
|
pass
|
|
|
|
|
2024-08-08 07:10:57 -04:00
|
|
|
@pytest.mark.parametrize('target', [
|
|
|
|
'esp32',
|
|
|
|
'esp32c3',
|
|
|
|
])
|
|
|
|
def test_foo_single_with_param(dut):
|
|
|
|
pass
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count, target', [
|
|
|
|
(2, 'esp32|esp32s2'),
|
|
|
|
(3, 'esp32s2|esp32s2|esp32s3'),
|
|
|
|
], indirect=True
|
|
|
|
)
|
|
|
|
def test_foo_multi(dut):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count', [2], indirect=True
|
|
|
|
)
|
|
|
|
def test_foo_multi_with_marker(dut):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2024-01-26 08:10:46 -05:00
|
|
|
def test_get_pytest_cases_single_specific(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_get_pytest_cases_single_specific.py'
|
2023-11-28 08:38:47 -05:00
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
2024-01-26 08:10:46 -05:00
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32')
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2024-08-08 07:10:57 -04:00
|
|
|
assert len(cases) == 2
|
2023-11-28 08:38:47 -05:00
|
|
|
assert cases[0].targets == ['esp32']
|
2024-08-08 07:10:57 -04:00
|
|
|
assert cases[0].name == 'test_foo_single'
|
|
|
|
assert cases[1].targets == ['esp32']
|
|
|
|
assert cases[1].name == 'test_foo_single_with_param'
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
|
2024-01-26 08:10:46 -05:00
|
|
|
def test_get_pytest_cases_multi_specific(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_get_pytest_cases_multi_specific.py'
|
2023-11-28 08:38:47 -05:00
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
2024-01-26 08:10:46 -05:00
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32s2,esp32s2, esp32s3')
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
assert len(cases) == 1
|
|
|
|
assert cases[0].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
|
2024-01-26 08:10:46 -05:00
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32s3,esp32s2,esp32s2') # order matters
|
2024-01-12 08:42:00 -05:00
|
|
|
assert len(cases) == 0
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2024-01-26 08:10:46 -05:00
|
|
|
def test_get_pytest_cases_multi_all(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_get_pytest_cases_multi_all.py'
|
2023-11-28 08:38:47 -05:00
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
2024-01-26 08:10:46 -05:00
|
|
|
cases = get_pytest_cases([str(work_dirpath)], CollectMode.MULTI_ALL_WITH_PARAM)
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
assert len(cases) == 2
|
|
|
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
|
|
|
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
|
|
|
|
|
2024-01-26 08:10:46 -05:00
|
|
|
def test_get_pytest_cases_all(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_get_pytest_cases_all.py'
|
2023-11-28 08:38:47 -05:00
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
2024-01-26 08:10:46 -05:00
|
|
|
cases = get_pytest_cases([str(work_dirpath)], CollectMode.ALL)
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2024-08-08 07:10:57 -04:00
|
|
|
assert len(cases) == 8
|
2023-11-28 08:38:47 -05:00
|
|
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
|
|
|
assert cases[0].name == 'test_foo_multi'
|
|
|
|
|
|
|
|
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
assert cases[1].name == 'test_foo_multi'
|
|
|
|
|
|
|
|
assert cases[2].targets == ['esp32', 'esp32']
|
|
|
|
assert cases[2].name == 'test_foo_multi_with_marker'
|
|
|
|
|
|
|
|
assert cases[3].targets == ['esp32s2', 'esp32s2']
|
|
|
|
assert cases[3].name == 'test_foo_multi_with_marker'
|
|
|
|
|
|
|
|
assert cases[4].targets == ['esp32']
|
|
|
|
assert cases[4].name == 'test_foo_single'
|
|
|
|
|
|
|
|
assert cases[5].targets == ['esp32s2']
|
|
|
|
assert cases[5].name == 'test_foo_single'
|
2024-01-30 05:18:41 -05:00
|
|
|
|
2024-08-08 07:10:57 -04:00
|
|
|
assert cases[6].targets == ['esp32']
|
|
|
|
assert cases[6].name == 'test_foo_single_with_param'
|
|
|
|
|
|
|
|
assert cases[7].targets == ['esp32c3']
|
|
|
|
assert cases[7].name == 'test_foo_single_with_param'
|
|
|
|
|
2024-01-30 05:18:41 -05:00
|
|
|
|
|
|
|
def test_multi_with_marker_and_app_path(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_multi_with_marker_and_app_path.py'
|
|
|
|
script.write_text(
|
|
|
|
textwrap.dedent(
|
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.esp32c2
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count,app_path', [
|
|
|
|
(2, 'foo|bar'),
|
|
|
|
(3, 'foo|bar|baz'),
|
|
|
|
], indirect=True
|
|
|
|
)
|
|
|
|
def test_foo_multi_with_marker_and_app_path(dut):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
)
|
|
|
|
)
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32c3,esp32c3')
|
|
|
|
assert len(cases) == 0
|
|
|
|
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32c2,esp32c2')
|
|
|
|
assert len(cases) == 1
|
|
|
|
assert cases[0].targets == ['esp32c2', 'esp32c2']
|
|
|
|
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32c2,esp32c2,esp32c2')
|
|
|
|
assert len(cases) == 1
|
|
|
|
assert cases[0].targets == ['esp32c2', 'esp32c2', 'esp32c2']
|
2024-03-12 06:04:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_filter_with_sdkconfig_name(work_dirpath: Path) -> None:
|
|
|
|
script = work_dirpath / 'pytest_filter_with_sdkconfig_name.py'
|
|
|
|
script.write_text(
|
|
|
|
textwrap.dedent(
|
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'config', [
|
|
|
|
'foo',
|
|
|
|
'bar',
|
|
|
|
], indirect=True
|
|
|
|
)
|
|
|
|
def test_filter_with_sdkconfig_name_single_dut(dut):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count', [2], indirect=True
|
|
|
|
)
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'config', [
|
|
|
|
'foo|bar',
|
|
|
|
'bar|baz',
|
|
|
|
], indirect=True
|
|
|
|
)
|
|
|
|
def test_filter_with_sdkconfig_name_multi_dut(dut):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32', config_name='foo')
|
|
|
|
assert len(cases) == 1
|
|
|
|
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32,esp32', config_name='foo')
|
|
|
|
assert len(cases) == 1
|
|
|
|
|
|
|
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32,esp32', config_name='bar')
|
|
|
|
assert len(cases) == 2
|