Skip to content

mcp23009e: Add test scenario for I/O expander driver.#49

Merged
nedseb merged 5 commits intomainfrom
tests/mcp23009e-scenario
Mar 12, 2026
Merged

mcp23009e: Add test scenario for I/O expander driver.#49
nedseb merged 5 commits intomainfrom
tests/mcp23009e-scenario

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 12, 2026

Closes #35

Summary

  • Add YAML test scenario for MCP23009E I/O expander
  • Add mock_pins support to test framework for drivers requiring constructor pin args
  • Add hardware_init support to mpremote bridge for custom device initialization on hardware
  • Add hardware_script action type for running complete MicroPython scripts on board
  • Add interactive action type for prompt-then-read tests
  • Add wait: false option to skip Enter between grouped interactive tests
  • Add D-PAD button tests: 4 polling + 4 interrupt (LED_GREEN signals readiness)
  • Decode D-PAD button states individually in manual test for readability
  • MCP23009E requires reset_pin (RST_EXPANDER on STeaMi) for constructor

Tests

Test Mode Description
Read IODIR default value mock + hardware Verify default 0xFF
Read GPIO register mock + hardware Non-null GPIO read
Read individual GPIO level mock get_level(0) returns value
D-PAD buttons state hardware (manual) Display per-button state
D-PAD UP/DOWN/LEFT/RIGHT (polling) hardware LED verte, appui, get_level() == 0
D-PAD UP/DOWN/LEFT/RIGHT (interrupt) hardware LED verte, appui, INTF flag detected

Test commands

# Mock tests (CPython)
python3 -m pytest tests/ -v --driver mcp23009e

# Hardware tests (STeaMi board)
python3 -m pytest tests/ -v --port /dev/ttyACM0 --driver mcp23009e -s

Test results

============================== test session starts ==============================
platform linux -- Python 3.13.7, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/nedjar/sandbox/micropython-steami-lib
configfile: pytest.ini
plugins: typeguard-4.4.2
collected 72 items / 58 deselected / 14 selected                                                                                                                                                                                                                            

tests/test_scenarios.py::test_scenario[mcp23009e/Read IODIR default value/mock] 0xFF
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/Read IODIR default value/hardware] 0xFF
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/Read GPIO register/mock] 240
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/Read GPIO register/hardware] 240
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/Read individual GPIO level/mock] 0
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD buttons state/hardware]   UP (GP7): 1 (1=relâché, 0=appuyé)
  DOWN (GP5): 1 (1=relâché, 0=appuyé)
  LEFT (GP6): 1 (1=relâché, 0=appuyé)
  RIGHT (GP4): 1 (1=relâché, 0=appuyé)
  [MANUAL] Tous les boutons sont-ils relâchés (valeur 1) ? [y/n] Y
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD UP button (polling)/hardware]   [INTERACTIVE] Test polling D-PAD : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP. 
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD DOWN button (polling)/hardware]   [INTERACTIVE] Bouton DOWN
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD LEFT button (polling)/hardware]   [INTERACTIVE] Bouton LEFT
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD RIGHT button (polling)/hardware]   [INTERACTIVE] Bouton RIGHT
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD UP button (interrupt)/hardware]   [INTERACTIVE] Test interrupt D-PAD : appuyez brièvement sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP. 
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD DOWN button (interrupt)/hardware]   [INTERACTIVE] Bouton DOWN
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD LEFT button (interrupt)/hardware]   [INTERACTIVE] Bouton LEFT
True
PASSED
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD RIGHT button (interrupt)/hardware]   [INTERACTIVE] Bouton RIGHT
True
PASSED

================= 14 passed, 58 deselected in 99.18s (0:01:39) ==================

@nedseb nedseb requested review from Charly-sketch and Copilot March 12, 2026 13:06
@nedseb nedseb self-assigned this Mar 12, 2026
@nedseb nedseb added enhancement New feature or request test labels Mar 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new YAML-driven test scenario for the mcp23009e I/O expander driver and extends the scenario runner/bridge to support drivers that require extra constructor Pin arguments or custom hardware-side initialization.

Changes:

  • Add tests/scenarios/mcp23009e.yaml covering mock + hardware + manual checks for MCP23009E.
  • Extend the mock scenario runner to pass additional constructor kwargs via mock_pins.
  • Extend the mpremote bridge / scenario runner to support hardware_init for custom device initialization on hardware.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/test_scenarios.py Adds mock_pins handling for mock instantiation and threads hardware_init into hardware method calls.
tests/scenarios/mcp23009e.yaml New MCP23009E scenario with mock register setup, method-call tests, and a manual hardware check.
tests/runner/mpremote_bridge.py Adds hardware_init option to override device initialization code executed on-board.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_scenarios.py
Comment thread tests/test_scenarios.py
@nedseb nedseb force-pushed the tests/mcp23009e-scenario branch from 89fc570 to 394e5a1 Compare March 12, 2026 13:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/runner/executor.py
Comment thread tests/runner/mpremote_bridge.py
Comment thread tests/runner/mpremote_bridge.py
Comment thread tests/scenarios/mcp23009e.yaml
Comment thread tests/test_scenarios.py
@nedseb nedseb merged commit 1643d64 into main Mar 12, 2026
3 checks passed
@nedseb nedseb deleted the tests/mcp23009e-scenario branch March 12, 2026 14:09
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: Add test scenario for MCP23009E I/O expander.

2 participants