Skip to content

Fix pylint errors #51

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 4 commits into from
Nov 8, 2022
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
7 changes: 5 additions & 2 deletions adafruit_midi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,15 @@ def send(self, msg, channel=None):
channel = self.out_channel
if isinstance(msg, MIDIMessage):
msg.channel = channel
data = msg.__bytes__() # bytes(object) does not work in uPy
# bytes(object) does not work in uPy
data = msg.__bytes__() # pylint: disable=unnecessary-dunder-call
else:
data = bytearray()
for each_msg in msg:
each_msg.channel = channel
data.extend(each_msg.__bytes__())
data.extend(
each_msg.__bytes__() # pylint: disable=unnecessary-dunder-call
)

self._send(data, len(data))

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

# pylint: disable=invalid-name

import unittest

Expand Down Expand Up @@ -32,9 +32,7 @@

# pylint: disable=invalid-name
class Test_MIDIMessage_from_message_byte_tests(unittest.TestCase):
# 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 @@ -50,7 +48,6 @@ def test_NoteOn_basic(self): # pylint: disable=invalid-name
self.assertEqual(msg.channel, 0)

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

Expand All @@ -71,7 +68,6 @@ def test_NoteOn_awaitingthirdbyte(self): # pylint: disable=invalid-name
self.assertEqual(skipped, 0)

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

Expand All @@ -91,7 +87,6 @@ def test_NoteOn_predatajunk(self): # pylint: disable=invalid-name
self.assertEqual(msg.channel, 0)

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 @@ -128,7 +123,6 @@ def test_NoteOn_prepartialsysex(self): # pylint: disable=invalid-name
self.assertEqual(msg.channel, 0)

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 @@ -144,7 +138,6 @@ def test_NoteOn_postNoteOn(self): # pylint: disable=invalid-name
self.assertEqual(msg.channel, 8)

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

Expand All @@ -160,7 +153,6 @@ def test_NoteOn_postpartialNoteOn(self): # pylint: disable=invalid-name
self.assertEqual(msg.channel, 0)

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 @@ -175,10 +167,9 @@ def test_NoteOn_preotherchannel(self): # pylint: disable=invalid-name
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 3)

def test_NoteOn_preotherchannelplusintermediatejunk(
def test_NoteOn_preotherchannelplusintermediatejunk( # pylint: disable=invalid-name
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 @@ -196,7 +187,6 @@ def test_NoteOn_preotherchannelplusintermediatejunk(
self.assertEqual(msg.channel, 3)

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

Expand All @@ -209,7 +199,6 @@ def test_NoteOn_wrongchannel(self): # pylint: disable=invalid-name
self.assertEqual(skipped, 0)

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

Expand All @@ -224,7 +213,6 @@ def test_NoteOn_partialandpreotherchannel1(self): # pylint: disable=invalid-nam
self.assertEqual(skipped, 0)

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

Expand All @@ -239,7 +227,6 @@ def test_NoteOn_partialandpreotherchannel2(self): # pylint: disable=invalid-nam
self.assertEqual(skipped, 0)

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 @@ -265,7 +252,6 @@ def test_NoteOn_constructor_int(self): # pylint: disable=invalid-name
self.assertIsNone(object4.channel)

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 @@ -293,10 +279,9 @@ def test_SystemExclusive_NoteOn(self): # pylint: disable=invalid-name
self.assertEqual(skipped, 0)
self.assertEqual(msg.channel, 14)

def test_SystemExclusive_NoteOn_premalterminatedsysex(
def test_SystemExclusive_NoteOn_premalterminatedsysex( # pylint: disable=invalid-name
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 @@ -312,7 +297,6 @@ def test_SystemExclusive_NoteOn_premalterminatedsysex(
)

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

Expand All @@ -326,7 +310,6 @@ def test_Unknown_SinglebyteStatus(self): # pylint: disable=invalid-name
self.assertIsNone(msg.channel)

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

Expand All @@ -343,7 +326,6 @@ 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 @@ -369,7 +351,6 @@ def test_NoteOn_constructor_valueerror3(self): # pylint: disable=invalid-name
NoteOn(128, 0x7F)

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)
Expand All @@ -383,12 +364,11 @@ def test_NoteOn_constructor_bogusstring(self): # pylint: disable=invalid-name
NoteOn("CC4", 0x7F)


class Test_MIDIMessage_NoteOff_constructor(
class Test_MIDIMessage_NoteOff_constructor( # pylint: disable=invalid-name
unittest.TestCase
): # pylint: disable=invalid-name
):
# mostly cut and paste from NoteOn above
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 Down Expand Up @@ -418,7 +398,6 @@ def test_NoteOff_constructor_valueerror3(self): # pylint: disable=invalid-name
NoteOff(128, 0x7F)

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)
Expand Down
13 changes: 3 additions & 10 deletions tests/test_MIDI_unittests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pylint: disable=invalid-name
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# pylint: enable=invalid-name

# pylint: disable=invalid-name

import unittest
from unittest.mock import Mock, call
Expand Down Expand Up @@ -37,7 +37,6 @@

# For loopback/echo tests
def MIDI_mocked_both_loopback(in_c, out_c): # pylint: disable=invalid-name
# pylint: enable=invalid-name
usb_data = bytearray()

def write(buffer, length):
Expand All @@ -61,7 +60,6 @@ def read(length):


def MIDI_mocked_receive(in_c, data, read_sizes): # pylint: disable=invalid-name
# pylint: enable=invalid-name
usb_data = bytearray(data)
chunks = read_sizes
chunk_idx = 0
Expand Down Expand Up @@ -101,7 +99,6 @@ def test_no_inout(self):
class Test_MIDI(unittest.TestCase):
# pylint: disable=too-many-branches
def test_captured_data_one_byte_reads(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
channel = 0
# From an M-Audio AXIOM controller
raw_data = bytearray(
Expand Down Expand Up @@ -173,7 +170,6 @@ def test_captured_data_one_byte_reads(self): # pylint: disable=invalid-name
self.assertIsNone(msg)

def test_unknown_before_NoteOn(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
channel = 0
# From an M-Audio AXIOM controller
raw_data = bytes(
Expand All @@ -184,7 +180,7 @@ def test_unknown_before_NoteOn(self): # pylint: disable=invalid-name
) + bytes(NoteOn("C5", 0x7F, channel=channel))
midi = MIDI_mocked_receive(channel, raw_data, [2, 2, 1, 1, 3])

for unused in range(4): # pylint: disable=unused-variable
for _ in range(4):
msg = midi.receive()
self.assertIsInstance(msg, adafruit_midi.midi_message.MIDIUnknownEvent)
self.assertIsNone(msg.channel)
Expand All @@ -197,7 +193,6 @@ def test_unknown_before_NoteOn(self): # pylint: disable=invalid-name

# See https://github.com/adafruit/Adafruit_CircuitPython_MIDI/issues/8
def test_running_status_when_implemented(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
channel = 8
raw_data = (
bytes(NoteOn("C5", 0x7F, channel=channel))
Expand All @@ -210,7 +205,6 @@ def test_running_status_when_implemented(self): # pylint: disable=invalid-name
# self.assertEqual(TOFINISH, WHENIMPLEMENTED)

def test_somegood_somemissing_databytes(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
channel = 8
raw_data = (
bytes(NoteOn("C5", 0x7F, channel=channel))
Expand Down Expand Up @@ -468,7 +462,6 @@ def test_send_basic_sequences(self):
nextcall += 1

def test_termination_with_random_data(self): # pylint: disable=invalid-name
# pylint: enable=invalid-name
"""Test with a random stream of bytes to ensure that the parsing code
termates and returns, i.e. does not go into any infinite loops.
"""
Expand Down