Universal Python library for hardware toggle switch testing automation
Project description
toggletest
Universal Python library for hardware toggle switch testing automation.
Supports Arduino (USB-Serial), Raspberry Pi (GIPO), and a software Mock backend all through the same API.
Built by: Vaishnavi Rathi | MS ECE @ Northeastern University
Install
pip install toggletest # core only (mock backend)
pip install toggletest[arduino] # + pyserial for Arduino
pip install toggletest[rpi] # + RPi.GPIO for Raspberry Pi
pip install toggletest[all] # everything including pytest
Arduino setup
Upload examples/arduino_firmware/toggle_bridge.ino to your Arduino before using ArduinoBackend.
Quick start
With Arduino (hardware)
from toggletest import Toggle, ArduinoBackend
with ArduinoBackend(port='/dev/ttyUSB0') as hw:
t = Toggle(hw, pin=2, mode='INPUT', debounce_ms=50, label='power_switch')
events = t.monitor(duration=10.0, poll_hz=100)
print(t.summary())
With MockBackend (no hardware — great for CI)
from toggletest import Toggle, MockBackend
with MockBackend(initial_states={2: False}) as hw:
t = Toggle(hw, pin=2, mode='INPUT', debounce_ms=50)
hw.set_state(2, True) # simulate switch press
print(t.read()) # True
print(t.change_count) # 1
Driving an output toggle
with ArduinoBackend() as hw:
t = Toggle(hw, pin=3, mode='OUTPUT', label='relay')
t.write(True)
t.pulse(duration_ms=200)
t.toggle()
pytest integration
Add to conftest.py:
pytest_plugins = ["toggletest.pytest_plugin"]
from toggletest import assert_state, assert_changed, assert_no_bounce, assert_transition
def test_power_switch(mock_toggle, mock_backend, toggle_logger):
toggle_logger.attach(mock_toggle)
mock_backend.set_state(mock_toggle.pin, True)
mock_toggle.read()
assert_state(mock_toggle, True)
assert_changed(mock_toggle, 1)
assert_transition(mock_toggle, from_state=False, to_state=True)
assert_no_bounce(mock_toggle, window_ms=50)
Run without hardware:
pytest --no-hardware
Run with Arduino:
pytest --arduino-port /dev/ttyUSB0 --toggle-pin 2
CLI
toggletest scan
toggletest ping --port /dev/ttyUSB0
toggletest read --port /dev/ttyUSB0 --pin 2
toggletest write --port /dev/ttyUSB0 --pin 3 --state high
toggletest pulse --port /dev/ttyUSB0 --pin 3 --duration-ms 500
toggletest monitor --port /dev/ttyUSB0 --pin 2 --duration 10 --output results.csv
toggletest report --port /dev/ttyUSB0 --pin 2 --duration 10 --output-csv run.csv
Adding a new backend
from toggletest.backends.base import HardwareBackend
class MyCustomBackend(HardwareBackend):
def connect(self): ...
def disconnect(self): ...
def configure_pin(self, pin, mode): ...
def read_pin(self, pin) -> bool: ...
def write_pin(self, pin, state): ...
Project structure
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toggletest_hw-1.0.1.tar.gz.
File metadata
- Download URL: toggletest_hw-1.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbea35f82a9beb494adba4ede613628d2f18f840f434cc5cfb0c108d239870bc
|
|
| MD5 |
537c8f73c3efd10a90b05ac4acd97430
|
|
| BLAKE2b-256 |
7a71878333736e9635e3550253024e9642b985474478a3727bc44791eb069ff1
|
File details
Details for the file toggletest_hw-1.0.1-py3-none-any.whl.
File metadata
- Download URL: toggletest_hw-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26c496517769af8214f5a355d23257f56261f8d394d3e661ff3e1fab677dc4f8
|
|
| MD5 |
f0050fd89c55a0a72e0b98e7c3d1736d
|
|
| BLAKE2b-256 |
2d69c2adba0d6c8afe31a6e1166417ef2410e96b54da802351cf81f39ccd10ad
|