Skip to content

Linted tests directory #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: pylint
name: pylint (library code)
types: [python]
exclude: "^(docs/|examples/|setup.py$)"
exclude: "^(docs/|tests/|examples/|setup.py$)"
- repo: local
hooks:
- id: pylint_examples
Expand All @@ -32,3 +32,11 @@ repos:
entry: /usr/bin/env bash -c
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
language: system
- repo: local
hooks:
- id: pylint_tests
name: pylint (tests code)
description: Run pylint rules on "tests/*.py" files
entry: /usr/bin/env bash -c
args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)']
language: system
14 changes: 9 additions & 5 deletions adafruit_midi/note_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"


class NoteOff(MIDIMessage):
class NoteOff(MIDIMessage): # pylint: disable=duplicate-code
"""Note Off Change MIDI message.

:param note: The note (key) number either as an ``int`` (0-127) or a
Expand All @@ -36,15 +36,19 @@ class NoteOff(MIDIMessage):
LENGTH = 3

def __init__(self, note, velocity=0, *, channel=None):
self.note = note_parser(note)
self.velocity = velocity
self._note = note_parser(note)
self._velocity = velocity
super().__init__(channel=channel)
if not 0 <= self.note <= 127 or not 0 <= self.velocity <= 127:
if not 0 <= self._note <= 127 or not 0 <= self._velocity <= 127:
raise self._EX_VALUEERROR_OOR

def __bytes__(self):
return bytes(
[self._STATUS | (self.channel & self.CHANNELMASK), self.note, self.velocity]
[
self._STATUS | (self.channel & self.CHANNELMASK),
self._note,
self._velocity,
]
)

@classmethod
Expand Down
109 changes: 67 additions & 42 deletions tests/test_MIDIMessage_unittests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# pylint: disable=invalid-name
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# pylint: enable=invalid-name

import unittest
from unittest.mock import Mock, MagicMock


import os

verbose = int(os.getenv("TESTVERBOSE", "2"))

# pylint: disable=wrong-import-position
# adafruit_midi had an import usb_midi
import sys

Expand All @@ -22,21 +24,17 @@
import adafruit_midi

# Full monty
from adafruit_midi.channel_pressure import ChannelPressure
from adafruit_midi.control_change import ControlChange
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend
from adafruit_midi.polyphonic_key_pressure import PolyphonicKeyPressure
from adafruit_midi.program_change import ProgramChange
from adafruit_midi.start import Start
from adafruit_midi.stop import Stop
from adafruit_midi.system_exclusive import SystemExclusive
from adafruit_midi.timing_clock import TimingClock

# pylint: enable=wrong-import-position

# pylint: disable=invalid-name
class Test_MIDIMessage_from_message_byte_tests(unittest.TestCase):
def test_NoteOn_basic(self):
# pylint: enable=invalid-name
def test_NoteOn_basic(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90, 0x30, 0x7F])
ichannel = 0

Expand All @@ -51,7 +49,8 @@ def test_NoteOn_basic(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 0)

def test_NoteOn_awaitingthirdbyte(self):
def test_NoteOn_awaitingthirdbyte(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90, 0x30])
ichannel = 0

Expand All @@ -71,7 +70,8 @@ def test_NoteOn_awaitingthirdbyte(self):
)
self.assertEqual(skipped, 0)

def test_NoteOn_predatajunk(self):
def test_NoteOn_predatajunk(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x20, 0x64, 0x90, 0x30, 0x32])
ichannel = 0

Expand All @@ -90,7 +90,8 @@ def test_NoteOn_predatajunk(self):
self.assertEqual(skipped, 2)
self.assertEqual(msg.channel, 0)

def test_NoteOn_prepartialsysex(self):
def test_NoteOn_prepartialsysex(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x01, 0x02, 0x03, 0x04, 0xF7, 0x90, 0x30, 0x32])
ichannel = 0

Expand Down Expand Up @@ -118,15 +119,16 @@ def test_NoteOn_prepartialsysex(self):
self.assertIsInstance(
msg,
NoteOn,
"NoteOn is expected if SystemExclusive is loaded otherwise it would be MIDIUnknownEvent",
"NoteOn is expected if SystemExclusive is loaded otherwise it'd be MIDIUnknownEvent",
)
self.assertEqual(msg.note, 0x30)
self.assertEqual(msg.velocity, 0x32)
self.assertEqual(msgendidxplusone, 3, "NoteOn message removed")
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 0)

def test_NoteOn_postNoteOn(self):
def test_NoteOn_postNoteOn(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90 | 0x08, 0x30, 0x7F, 0x90 | 0x08, 0x37, 0x64])
ichannel = 8

Expand All @@ -141,7 +143,8 @@ def test_NoteOn_postNoteOn(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 8)

def test_NoteOn_postpartialNoteOn(self):
def test_NoteOn_postpartialNoteOn(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90, 0x30, 0x7F, 0x90, 0x37])
ichannel = 0

Expand All @@ -156,7 +159,8 @@ def test_NoteOn_postpartialNoteOn(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 0)

def test_NoteOn_preotherchannel(self):
def test_NoteOn_preotherchannel(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90 | 0x05, 0x30, 0x7F, 0x90 | 0x03, 0x37, 0x64])
ichannel = 3

Expand All @@ -171,7 +175,10 @@ def test_NoteOn_preotherchannel(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 3)

def test_NoteOn_preotherchannelplusintermediatejunk(self):
def test_NoteOn_preotherchannelplusintermediatejunk(
self,
): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x90 | 0x05, 0x30, 0x7F, 0x00, 0x00, 0x90 | 0x03, 0x37, 0x64])
ichannel = 3

Expand All @@ -188,7 +195,8 @@ def test_NoteOn_preotherchannelplusintermediatejunk(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 3)

def test_NoteOn_wrongchannel(self):
def test_NoteOn_wrongchannel(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x95, 0x30, 0x7F])
ichannel = 3

Expand All @@ -200,7 +208,8 @@ def test_NoteOn_wrongchannel(self):
self.assertEqual(msgendidxplusone, 3, "wrong channel message discarded")
self.assertEqual(skipped, 0)

def test_NoteOn_partialandpreotherchannel1(self):
def test_NoteOn_partialandpreotherchannel1(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x95, 0x30, 0x7F, 0x93])
ichannel = 3

Expand All @@ -214,7 +223,8 @@ def test_NoteOn_partialandpreotherchannel1(self):
)
self.assertEqual(skipped, 0)

def test_NoteOn_partialandpreotherchannel2(self):
def test_NoteOn_partialandpreotherchannel2(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0x95, 0x30, 0x7F, 0x93, 0x37])
ichannel = 3

Expand All @@ -228,7 +238,8 @@ def test_NoteOn_partialandpreotherchannel2(self):
)
self.assertEqual(skipped, 0)

def test_NoteOn_constructor_int(self):
def test_NoteOn_constructor_int(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
object1 = NoteOn(60, 0x7F)

self.assertEqual(object1.note, 60)
Expand All @@ -253,7 +264,8 @@ def test_NoteOn_constructor_int(self):
self.assertEqual(object4.velocity, 127)
self.assertIsNone(object4.channel)

def test_SystemExclusive_NoteOn(self):
def test_SystemExclusive_NoteOn(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0xF0, 0x42, 0x01, 0x02, 0x03, 0x04, 0xF7, 0x90 | 14, 0x30, 0x60])
ichannel = 14

Expand Down Expand Up @@ -281,7 +293,10 @@ def test_SystemExclusive_NoteOn(self):
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 14)

def test_SystemExclusive_NoteOn_premalterminatedsysex(self):
def test_SystemExclusive_NoteOn_premalterminatedsysex(
self,
): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0xF0, 0x42, 0x01, 0x02, 0x03, 0x04, 0xF0, 0x90, 0x30, 0x32])
ichannel = 0

Expand All @@ -296,7 +311,8 @@ def test_SystemExclusive_NoteOn_premalterminatedsysex(self):
skipped, 0, "If SystemExclusive class is imported then this must be 0"
)

def test_Unknown_SinglebyteStatus(self):
def test_Unknown_SinglebyteStatus(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([0xFD])
ichannel = 0

Expand All @@ -309,7 +325,8 @@ def test_Unknown_SinglebyteStatus(self):
self.assertEqual(skipped, 0)
self.assertIsNone(msg.channel)

def test_Empty(self):
def test_Empty(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
data = bytes([])
ichannel = 0

Expand All @@ -322,8 +339,11 @@ def test_Empty(self):
self.assertEqual(skipped, 0)


class Test_MIDIMessage_NoteOn_constructor(unittest.TestCase):
def test_NoteOn_constructor_string(self):
class Test_MIDIMessage_NoteOn_constructor(
unittest.TestCase
): # pylint: disable=invalid-name
def test_NoteOn_constructor_string(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
object1 = NoteOn("C4", 0x64)
self.assertEqual(object1.note, 60)
self.assertEqual(object1.velocity, 0x64)
Expand All @@ -336,35 +356,39 @@ def test_NoteOn_constructor_string(self):
self.assertEqual(object3.note, 61)
self.assertEqual(object3.velocity, 0)

def test_NoteOn_constructor_valueerror1(self):
def test_NoteOn_constructor_valueerror1(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOn(60, 0x80) # pylint is happier if return value not stored

def test_NoteOn_constructor_valueerror2(self):
def test_NoteOn_constructor_valueerror2(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOn(-1, 0x7F)

def test_NoteOn_constructor_valueerror3(self):
def test_NoteOn_constructor_valueerror3(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOn(128, 0x7F)

def test_NoteOn_constructor_upperrange1(self):
def test_NoteOn_constructor_upperrange1(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
object1 = NoteOn("G9", 0x7F)
self.assertEqual(object1.note, 127)
self.assertEqual(object1.velocity, 0x7F)

def test_NoteOn_constructor_upperrange2(self):
def test_NoteOn_constructor_upperrange2(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOn("G#9", 0x7F) # just above max note

def test_NoteOn_constructor_bogusstring(self):
def test_NoteOn_constructor_bogusstring(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOn("CC4", 0x7F)


class Test_MIDIMessage_NoteOff_constructor(unittest.TestCase):
class Test_MIDIMessage_NoteOff_constructor(
unittest.TestCase
): # pylint: disable=invalid-name
# mostly cut and paste from NoteOn above
def test_NoteOff_constructor_string(self):
def test_NoteOff_constructor_string(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
object1 = NoteOff("C4", 0x64)
self.assertEqual(object1.note, 60)
self.assertEqual(object1.velocity, 0x64)
Expand All @@ -381,28 +405,29 @@ def test_NoteOff_constructor_string(self):
self.assertEqual(object4.note, 61)
self.assertEqual(object4.velocity, 0)

def test_NoteOff_constructor_valueerror1(self):
def test_NoteOff_constructor_valueerror1(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOff(60, 0x80)

def test_NoteOff_constructor_valueerror2(self):
def test_NoteOff_constructor_valueerror2(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOff(-1, 0x7F)

def test_NoteOff_constructor_valueerror3(self):
def test_NoteOff_constructor_valueerror3(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOff(128, 0x7F)

def test_NoteOff_constructor_upperrange1(self):
def test_NoteOff_constructor_upperrange1(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
object1 = NoteOff("G9", 0x7F)
self.assertEqual(object1.note, 127)
self.assertEqual(object1.velocity, 0x7F)

def test_NoteOff_constructor_upperrange2(self):
def test_NoteOff_constructor_upperrange2(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOff("G#9", 0x7F) # just above max note

def test_NoteOff_constructor_bogusstring(self):
def test_NoteOff_constructor_bogusstring(self): # pylint: disable=invalid-name
with self.assertRaises(ValueError):
NoteOff("CC4", 0x7F)

Expand Down
Loading