Spaces:
Running
Running
| """Shared fixtures for the SYNTHIA test suite.""" | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| # Ensure project root is importable (needed for config, midi, engines, app). | |
| PROJECT_ROOT = Path(__file__).resolve().parent.parent | |
| if str(PROJECT_ROOT) not in sys.path: | |
| sys.path.insert(0, str(PROJECT_ROOT)) | |
| # --------------------------------------------------------------------------- | |
| # Sample MIDI events | |
| # --------------------------------------------------------------------------- | |
| def c_major_chord_events(): | |
| """C-E-G chord with note_on/note_off pairs.""" | |
| return [ | |
| {"type": "note_on", "note": 60, "velocity": 100, "time": 0.0, "channel": 0}, | |
| {"type": "note_on", "note": 64, "velocity": 100, "time": 0.0, "channel": 0}, | |
| {"type": "note_on", "note": 67, "velocity": 100, "time": 0.0, "channel": 0}, | |
| {"type": "note_off", "note": 60, "velocity": 0, "time": 0.5, "channel": 0}, | |
| {"type": "note_off", "note": 64, "velocity": 0, "time": 0.5, "channel": 0}, | |
| {"type": "note_off", "note": 67, "velocity": 0, "time": 0.5, "channel": 0}, | |
| ] | |
| def melody_events(): | |
| """Simple ascending melody: C4 D4 E4.""" | |
| return [ | |
| {"type": "note_on", "note": 60, "velocity": 80, "time": 0.0, "channel": 0}, | |
| {"type": "note_off", "note": 60, "velocity": 0, "time": 0.3, "channel": 0}, | |
| {"type": "note_on", "note": 62, "velocity": 80, "time": 0.4, "channel": 0}, | |
| {"type": "note_off", "note": 62, "velocity": 0, "time": 0.7, "channel": 0}, | |
| {"type": "note_on", "note": 64, "velocity": 80, "time": 0.8, "channel": 0}, | |
| {"type": "note_off", "note": 64, "velocity": 0, "time": 1.1, "channel": 0}, | |
| ] | |
| def single_note_events(): | |
| """One note_on + note_off pair (middle C).""" | |
| return [ | |
| {"type": "note_on", "note": 60, "velocity": 100, "time": 0.0, "channel": 0}, | |
| {"type": "note_off", "note": 60, "velocity": 0, "time": 0.5, "channel": 0}, | |
| ] | |
| # --------------------------------------------------------------------------- | |
| # Source file helpers | |
| # --------------------------------------------------------------------------- | |
| def js_source(): | |
| """Raw contents of static/keyboard.js.""" | |
| return (PROJECT_ROOT / "static" / "keyboard.js").read_text() | |
| def app_source(): | |
| """Raw contents of app.py.""" | |
| return (PROJECT_ROOT / "app.py").read_text() | |
| def html_source(): | |
| """Raw contents of keyboard.html.""" | |
| return (PROJECT_ROOT / "keyboard.html").read_text() | |