Skip to content

Commit 4aeea23

Browse files
committed
test: add test case for hello_esp32 example
1 parent ac6e6b3 commit 4aeea23

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ jobs:
2121
- run: hatch run ruff format --check .
2222
- run: hatch run ruff check .
2323
- run: hatch run mypy .
24+
- name: Run a Wokwi CI server
25+
uses: wokwi/wokwi-ci-server-action@v1
2426
- run: hatch run dev:pytest
27+
env:
28+
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}

examples/hello_esp32/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"hello_world.bin": f"{HELLO_WORLD_URL}/hello_world.bin",
1616
"hello_world.elf": f"{HELLO_WORLD_URL}/hello_world.elf",
1717
}
18+
SLEEP_TIME = int(os.getenv("WOKWI_SLEEP_TIME", "10"))
1819

1920

2021
async def main() -> None:
@@ -50,10 +51,10 @@ async def main() -> None:
5051
elf="hello_world.elf",
5152
)
5253

53-
# Stream serial output for 10 seconds
54+
# Stream serial output for a few seconds
5455
serial_task = asyncio.create_task(client.serial_monitor_cat())
55-
print("Simulation started, waiting for 10 seconds…")
56-
await asyncio.sleep(10)
56+
print(f"Simulation started, waiting for {SLEEP_TIME} seconds…")
57+
await asyncio.sleep(SLEEP_TIME)
5758
serial_task.cancel()
5859

5960
# Disconnect from the simulator

tests/test_hello_esp32.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2025-present CodeMagic LTD
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
import subprocess
7+
import sys
8+
9+
10+
def test_hello_esp32_example() -> None:
11+
"""`python -m examples.hello_esp32.main` runs the hello_esp32 example and exits with 0."""
12+
13+
assert os.environ.get("WOKWI_CLI_TOKEN") is not None, (
14+
"WOKWI_CLI_TOKEN environment variable is not set. You can get it from https://wokwi.com/dashboard/ci."
15+
)
16+
17+
result = subprocess.run(
18+
[sys.executable, "-m", "examples.hello_esp32.main"],
19+
check=False,
20+
capture_output=True,
21+
text=True,
22+
env={**os.environ, "WOKWI_SLEEP_TIME": "1"},
23+
)
24+
25+
assert result.returncode == 0
26+
assert "main_task: Calling app_main()" in result.stdout

0 commit comments

Comments
 (0)