-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
349 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
exclude_lines = | ||
pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ bundles | |
dist | ||
**/*.egg-info | ||
.vscode | ||
.nox | ||
.nox | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "lib/winterbloom_smolmidi"] | ||
path = lib/winterbloom_smolmidi | ||
url = https://github.com/theacodes/Winterbloom_SmolMIDI | ||
[submodule "lib/winterbloom_voltageio"] | ||
path = lib/winterbloom_voltageio | ||
url = https://github.com/theacodes/Winterbloom_VoltageIO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule winterbloom_smolmidi
added at
e4f55a
Submodule winterbloom_voltageio
added at
aa82fa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import glob | ||
|
||
import nox | ||
|
||
|
||
@nox.session(python="3") | ||
def blacken(session): | ||
"""Run black code formater.""" | ||
session.install("black==19.3b0", "isort==4.3.21") | ||
files = ["noxfile.py", "winterbloom_sol.py"] | ||
files = ["noxfile.py"] + glob.glob("winterbloom_sol/*.py") | ||
session.run("black", *files) | ||
session.run("isort", "--recursive", *files) | ||
|
||
|
||
@nox.session(python="3") | ||
def lint(session): | ||
session.install("flake8==3.7.8", "black==19.3b0") | ||
files = ["noxfile.py", "winterbloom_sol.py"] | ||
files = ["noxfile.py"] + glob.glob("winterbloom_sol/*.py") | ||
session.run("black", "--check", *files) | ||
session.run("flake8", *files) | ||
|
||
|
||
@nox.session(python="3") | ||
def test(session): | ||
session.install("pytest") | ||
session.run("python", "-m", "pytest", "tests") | ||
session.install("pytest", "pytest-cov") | ||
session.run("python", "-m", "pytest", | ||
"--cov=winterbloom_sol", | ||
"--cov-report=term-missing", | ||
"tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import os | ||
import sys | ||
|
||
HERE = os.path.abspath(os.path.dirname(__file__)) | ||
ROOT = os.path.abspath(os.path.join(HERE, '..')) | ||
STUBS = os.path.join(HERE, 'stubs') | ||
LIB = os.path.join(ROOT, 'lib') | ||
|
||
# Insert import stubs directory into sys.path. | ||
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), 'stubs'))) | ||
sys.path.insert(1, STUBS) | ||
|
||
# Insert libs into sys.path | ||
for path in os.listdir(LIB): | ||
sys.path.insert(1, os.path.join(LIB, path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Copyright (c) 2019 Alethea Flowers for Winterbloom | ||
# Licensed under the MIT License | ||
|
||
import pytest | ||
|
||
import winterbloom_smolmidi as smolmidi | ||
from winterbloom_sol import _midi_ext | ||
|
||
|
||
def make_message(type, *data): | ||
msg = smolmidi.Message() | ||
msg.type = type | ||
msg.data = data | ||
return msg | ||
|
||
|
||
class MidiInStub: | ||
def __init__(self, messages): | ||
self._messages = iter(messages) | ||
|
||
def receive(self): | ||
return next(self._messages) | ||
|
||
def receive_sysex(self): | ||
return [0x01, 0x02] | ||
|
||
|
||
def test_normal_stream(): | ||
midi_in = _midi_ext.DeduplicatingMidiIn(MidiInStub([ | ||
make_message(smolmidi.NOTE_ON, 0x64, 0x65), | ||
make_message(smolmidi.NOTE_OFF, 0x64, 0x70), | ||
None | ||
])) | ||
|
||
assert midi_in.receive().type == smolmidi.NOTE_ON | ||
assert midi_in.receive().type == smolmidi.NOTE_OFF | ||
assert midi_in.receive() is None | ||
|
||
|
||
def test_stream_with_duplicates(): | ||
midi_in = _midi_ext.DeduplicatingMidiIn(MidiInStub([ | ||
make_message(smolmidi.NOTE_ON, 0x64, 0x65), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x01), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x02), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x03), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x04), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x05), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x06), | ||
make_message(smolmidi.NOTE_OFF, 0x64, 0x70), | ||
None | ||
])) | ||
|
||
assert midi_in.receive().type == smolmidi.NOTE_ON | ||
msg = midi_in.receive() | ||
assert msg.type == smolmidi.CHANNEL_PRESSURE | ||
assert msg.data[0] == 0x06 | ||
assert midi_in.receive().type == smolmidi.NOTE_OFF | ||
assert midi_in.receive() is None | ||
|
||
|
||
def test_stream_with_discontinous_duplicates(): | ||
midi_in = _midi_ext.DeduplicatingMidiIn(MidiInStub([ | ||
make_message(smolmidi.NOTE_ON, 0x64, 0x65), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x01), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x02), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x03), | ||
None, | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x04), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x05), | ||
make_message(smolmidi.CHANNEL_PRESSURE, 0x06), | ||
make_message(smolmidi.NOTE_OFF, 0x64, 0x70), | ||
None | ||
])) | ||
|
||
assert midi_in.receive().type == smolmidi.NOTE_ON | ||
msg = midi_in.receive() | ||
assert msg.type == smolmidi.CHANNEL_PRESSURE | ||
assert msg.data[0] == 0x03 | ||
msg = midi_in.receive() | ||
# It does *not* return the "None" in the middle of the stream, | ||
# instead, it just returns the next valid message. | ||
assert msg.type == smolmidi.CHANNEL_PRESSURE | ||
assert msg.data[0] == 0x06 | ||
assert midi_in.receive().type == smolmidi.NOTE_OFF | ||
assert midi_in.receive() is None | ||
|
||
|
||
def test_receive_sysex(): | ||
midi_in = _midi_ext.DeduplicatingMidiIn(MidiInStub([])) | ||
|
||
assert midi_in.receive_sysex() == [0x01, 0x02] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2019 Alethea Flowers for Winterbloom | ||
# Licensed under the MIT License | ||
|
||
from unittest import mock | ||
|
||
from winterbloom_sol import trigger | ||
|
||
|
||
class DigitalInOutStub: | ||
def __init__(self): | ||
self.value = False | ||
|
||
|
||
@mock.patch("time.monotonic", autospec=True) | ||
def test_trigger_basic(time_monotonic): | ||
output = DigitalInOutStub() | ||
trig = trigger.Trigger(output) | ||
|
||
time_monotonic.return_value = 0 | ||
trig() | ||
|
||
assert output.value is True | ||
|
||
time_monotonic.return_value = 0.014 | ||
trig.step() | ||
assert output.value is True | ||
|
||
time_monotonic.return_value = 0.016 | ||
trig.step() | ||
assert output.value is False | ||
|
||
|
||
def test_retrigger(): | ||
output = DigitalInOutStub() | ||
trig = trigger.Trigger(output) | ||
|
||
assert trig(True) | ||
assert not trig(True) | ||
|
||
|
||
@mock.patch("time.monotonic", autospec=True) | ||
def test_trigger_custom_duration(time_monotonic): | ||
output = DigitalInOutStub() | ||
trig = trigger.Trigger(output) | ||
|
||
time_monotonic.return_value = 0 | ||
trig(duration=50) | ||
|
||
time_monotonic.return_value = 0.049 | ||
trig.step() | ||
assert output.value is True | ||
|
||
time_monotonic.return_value = 0.051 | ||
trig.step() | ||
assert output.value is False | ||
|
||
|
||
def test_empty_step(): | ||
output = DigitalInOutStub() | ||
trig = trigger.Trigger(output) | ||
|
||
trig.step() | ||
|
||
assert output.value is False |
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.