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 2 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
28 changes: 15 additions & 13 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,20 +24,16 @@
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

class Test_MIDIMessage_from_message_byte_tests(unittest.TestCase):

class Test_MIDIMessage_from_message_byte_tests(
unittest.TestCase
): # pylint: disable=invalid-name
def test_NoteOn_basic(self):
data = bytes([0x90, 0x30, 0x7F])
ichannel = 0
Expand Down Expand Up @@ -118,7 +116,7 @@ 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)
Expand Down Expand Up @@ -322,7 +320,9 @@ def test_Empty(self):
self.assertEqual(skipped, 0)


class Test_MIDIMessage_NoteOn_constructor(unittest.TestCase):
class Test_MIDIMessage_NoteOn_constructor(
unittest.TestCase
): # pylint: disable=invalid-name
def test_NoteOn_constructor_string(self):
object1 = NoteOn("C4", 0x64)
self.assertEqual(object1.note, 60)
Expand Down Expand Up @@ -362,7 +362,9 @@ def test_NoteOn_constructor_bogusstring(self):
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):
object1 = NoteOff("C4", 0x64)
Expand Down
10 changes: 4 additions & 6 deletions tests/test_MIDI_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
# SPDX-License-Identifier: MIT

import unittest
from unittest.mock import Mock, MagicMock, call
from unittest.mock import Mock, call

import random
import os

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

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

Expand All @@ -24,16 +25,13 @@
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

# Import after messages - opposite to other test file
import adafruit_midi

# pylint: enable=wrong-import-position


# For loopback/echo tests
def MIDI_mocked_both_loopback(in_c, out_c):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_note_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# SPDX-License-Identifier: MIT

import unittest
from unittest.mock import Mock, MagicMock, call

import random
import os

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

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

Expand All @@ -20,6 +19,8 @@

from adafruit_midi.midi_message import note_parser

# pylint: enable=wrong-import-position


class Test_note_parser(unittest.TestCase):
def text_int_passthru(self):
Expand Down