Skip to content

Commit

Permalink
ref: create dut-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Feb 9, 2024
1 parent 7498230 commit c2d13ef
Show file tree
Hide file tree
Showing 6 changed files with 863 additions and 397 deletions.
47 changes: 47 additions & 0 deletions pytest-embedded-idf/tests/test_idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,53 @@ 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')
unity_test_path = os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
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}')
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}')
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
Expand Down
58 changes: 58 additions & 0 deletions pytest-embedded-serial/tests/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion pytest-embedded/pytest_embedded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.4'
Loading

0 comments on commit c2d13ef

Please sign in to comment.