Skip to content

Commit

Permalink
Merge pull request #240 from horw/feat/dut-factory
Browse files Browse the repository at this point in the history
hfudev authored Apr 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 98de6a6 + 2744830 commit f538abd
Showing 6 changed files with 915 additions and 379 deletions.
49 changes: 49 additions & 0 deletions pytest-embedded-idf/tests/test_idf.py
Original file line number Diff line number Diff line change
@@ -130,6 +130,55 @@ def test_no_matching_word_pass_rest(dut):
result.assert_outcomes(passed=2, failed=2)


def test_custom_idf_device_dut(testdir):
p = os.path.join(testdir.tmpdir, 'hello_world_esp32')
p_c3 = os.path.join(testdir.tmpdir, 'hello_world_esp32c3')
unity_test_path = os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
unity_test_path_c3 = os.path.join(testdir.tmpdir, 'unit_test_app_esp32c3')
testdir.makepyfile(f"""
import pytest
def test_idf_custom_dev():
from pytest_embedded.dut_factory import DutFactory
dut = DutFactory.create(embedded_services='esp,idf', app_path=r'{p}')
dut.expect("Hello")
def test_idf_mixed(dut):
from pytest_embedded.dut_factory import DutFactory
dutc = DutFactory.create(embedded_services='esp,idf', app_path=r'{p_c3}')
dutc.expect("Hello")
dut.expect("Hello")
assert dutc.serial.port!=dut.serial.port
def test_idf_unity_tester():
from pytest_embedded.dut_factory import DutFactory
dut1 = DutFactory.create(embedded_services='esp,idf', app_path=r'{unity_test_path}')
dut2 = DutFactory.create(embedded_services='esp,idf', app_path=r'{unity_test_path_c3}')
tester = DutFactory.unity_tester(dut1, dut2)
tester.run_all_cases()
def test_idf_run_all_single_board_cases():
from pytest_embedded.dut_factory import DutFactory
dut1 = DutFactory.create(embedded_services='esp,idf', app_path=r'{unity_test_path}')
dut1.run_all_single_board_cases()
""")

result = testdir.runpytest(
'-s',
'--app-path', p,
'--embedded-services', 'esp,idf',
'--junitxml', 'report.xml',
)
result.assert_outcomes(passed=4, errors=0)

junit_report = ET.parse('report.xml').getroot()[0]

assert junit_report.attrib['errors'] == '0'
assert junit_report.attrib['failures'] == '2'
assert junit_report.attrib['skipped'] == '0'
assert junit_report.attrib['tests'] == '7'


def test_idf_serial_flash_with_erase_nvs(testdir):
testdir.makepyfile("""
import pexpect
58 changes: 58 additions & 0 deletions pytest-embedded-serial/tests/test_serial.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,64 @@
import pytest


def test_custom_serial_device(testdir):
testdir.makepyfile(r"""
import pytest
def test_serial_mixed(dut):
from pytest_embedded.dut_factory import DutFactory
assert len(dut)==2
another_dut = DutFactory.create()
st = set(
(
dut[0].serial.port,
dut[1].serial.port,
another_dut.serial.port
)
)
assert len(st) == 3
def test_custom_dut():
from pytest_embedded.dut_factory import DutFactory
another_dut = DutFactory.create(embedded_services='esp,serial')
""")

result = testdir.runpytest(
'-s',
'--embedded-services', 'esp,serial',
'--count', 2,
)
result.assert_outcomes(passed=2, errors=0)


def test_custom_serial_device_dut_count_1(testdir):
testdir.makepyfile(r"""
import pytest
def test_serial_device_created_dut_count_1(dut):
from pytest_embedded.dut_factory import DutFactory
another_dut = DutFactory.create()
another_dut2 = DutFactory.create()
st = set(
(
dut.serial.port,
another_dut.serial.port,
another_dut2.serial.port
)
)
assert len(st) == 3
""")

result = testdir.runpytest(
'-s',
'--embedded-services', 'esp,serial',
'--count', 1,
)
result.assert_outcomes(passed=1, errors=0)


@pytest.mark.skipif(sys.platform == 'win32', reason='No socat support on windows')
@pytest.mark.flaky(reruns=3, reruns_delay=2)
def test_serial_port(testdir):
3 changes: 2 additions & 1 deletion pytest-embedded/pytest_embedded/__init__.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

from .app import App
from .dut import Dut
from .dut_factory import DutFactory

__all__ = ['App', 'Dut']
__all__ = ['App', 'Dut', 'DutFactory']

__version__ = '1.8.4'
Loading

0 comments on commit f538abd

Please sign in to comment.