Skip to content

Commit 704feb4

Browse files
committed
Linted tests directory
1 parent 41b021b commit 704feb4

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
- id: pylint
2424
name: pylint (library code)
2525
types: [python]
26-
exclude: "^(docs/|examples/|setup.py$)"
26+
exclude: "^(docs/|tests/|examples/|setup.py$)"
2727
- repo: local
2828
hooks:
2929
- id: pylint_examples
@@ -32,3 +32,11 @@ repos:
3232
entry: /usr/bin/env bash -c
3333
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
3434
language: system
35+
- repo: local
36+
hooks:
37+
- id: pylint_tests
38+
name: pylint (tests code)
39+
description: Run pylint rules on "tests/*.py" files
40+
entry: /usr/bin/env bash -c
41+
args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)']
42+
language: system

adafruit_midi/note_off.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"
2323

2424

25-
class NoteOff(MIDIMessage):
25+
class NoteOff(MIDIMessage): # pylint: disable=duplicate-code
2626
"""Note Off Change MIDI message.
2727
2828
:param note: The note (key) number either as an ``int`` (0-127) or a
@@ -36,15 +36,19 @@ class NoteOff(MIDIMessage):
3636
LENGTH = 3
3737

3838
def __init__(self, note, velocity=0, *, channel=None):
39-
self.note = note_parser(note)
40-
self.velocity = velocity
39+
self._note = note_parser(note)
40+
self._velocity = velocity
4141
super().__init__(channel=channel)
42-
if not 0 <= self.note <= 127 or not 0 <= self.velocity <= 127:
42+
if not 0 <= self._note <= 127 or not 0 <= self._velocity <= 127:
4343
raise self._EX_VALUEERROR_OOR
4444

4545
def __bytes__(self):
4646
return bytes(
47-
[self._STATUS | (self.channel & self.CHANNELMASK), self.note, self.velocity]
47+
[
48+
self._STATUS | (self.channel & self.CHANNELMASK),
49+
self._note,
50+
self._velocity,
51+
]
4852
)
4953

5054
@classmethod

tests/test_MIDIMessage_unittests.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# SPDX-License-Identifier: MIT
44

55
import unittest
6-
from unittest.mock import Mock, MagicMock
76

87

98
import os
109

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

12+
# pylint: disable=wrong-import-position
1313
# adafruit_midi had an import usb_midi
1414
import sys
1515

@@ -22,17 +22,11 @@
2222
import adafruit_midi
2323

2424
# Full monty
25-
from adafruit_midi.channel_pressure import ChannelPressure
26-
from adafruit_midi.control_change import ControlChange
2725
from adafruit_midi.note_off import NoteOff
2826
from adafruit_midi.note_on import NoteOn
29-
from adafruit_midi.pitch_bend import PitchBend
30-
from adafruit_midi.polyphonic_key_pressure import PolyphonicKeyPressure
31-
from adafruit_midi.program_change import ProgramChange
32-
from adafruit_midi.start import Start
33-
from adafruit_midi.stop import Stop
3427
from adafruit_midi.system_exclusive import SystemExclusive
35-
from adafruit_midi.timing_clock import TimingClock
28+
29+
# pylint: enable=wrong-import-position
3630

3731

3832
class Test_MIDIMessage_from_message_byte_tests(unittest.TestCase):
@@ -118,7 +112,7 @@ def test_NoteOn_prepartialsysex(self):
118112
self.assertIsInstance(
119113
msg,
120114
NoteOn,
121-
"NoteOn is expected if SystemExclusive is loaded otherwise it would be MIDIUnknownEvent",
115+
"NoteOn is expected if SystemExclusive is loaded otherwise it'd be MIDIUnknownEvent",
122116
)
123117
self.assertEqual(msg.note, 0x30)
124118
self.assertEqual(msg.velocity, 0x32)

tests/test_MIDI_unittests.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
# SPDX-License-Identifier: MIT
44

55
import unittest
6-
from unittest.mock import Mock, MagicMock, call
6+
from unittest.mock import Mock, call
77

88
import random
99
import os
1010

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

13+
# pylint: disable=wrong-import-position
1314
# adafruit_midi had an import usb_midi
1415
import sys
1516

@@ -24,16 +25,13 @@
2425
from adafruit_midi.note_off import NoteOff
2526
from adafruit_midi.note_on import NoteOn
2627
from adafruit_midi.pitch_bend import PitchBend
27-
from adafruit_midi.polyphonic_key_pressure import PolyphonicKeyPressure
28-
from adafruit_midi.program_change import ProgramChange
29-
from adafruit_midi.start import Start
30-
from adafruit_midi.stop import Stop
3128
from adafruit_midi.system_exclusive import SystemExclusive
32-
from adafruit_midi.timing_clock import TimingClock
3329

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

33+
# pylint: enable=wrong-import-position
34+
3735

3836
# For loopback/echo tests
3937
def MIDI_mocked_both_loopback(in_c, out_c):

tests/test_note_parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
# SPDX-License-Identifier: MIT
44

55
import unittest
6-
from unittest.mock import Mock, MagicMock, call
76

8-
import random
97
import os
108

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

11+
# pylint: disable=wrong-import-position
1312
# adafruit_midi had an import usb_midi
1413
import sys
1514

@@ -20,6 +19,8 @@
2019

2120
from adafruit_midi.midi_message import note_parser
2221

22+
# pylint: enable=wrong-import-position
23+
2324

2425
class Test_note_parser(unittest.TestCase):
2526
def text_int_passthru(self):

0 commit comments

Comments
 (0)