diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-01-01 16:19:49 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-01-01 16:19:49 +0100 |
commit | abbf6671bf788bd73b91c93cb9b3a91442c3bf8a (patch) | |
tree | 0cc023179e2d74d12097749ee994e699164c0a4d /midi_launchpad_mini_unittest.py | |
parent | 6d2424b3c4dfb3222b964e08c9b09d7875ee146f (diff) |
Refactored launchpad tests to use fixtures
Diffstat (limited to 'midi_launchpad_mini_unittest.py')
-rw-r--r-- | midi_launchpad_mini_unittest.py | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/midi_launchpad_mini_unittest.py b/midi_launchpad_mini_unittest.py index 43fc561..4ae5480 100644 --- a/midi_launchpad_mini_unittest.py +++ b/midi_launchpad_mini_unittest.py @@ -1,3 +1,5 @@ +import pytest + from midi_controller_launchpad_mini import MidiController class MidiWrapperMock: @@ -66,23 +68,27 @@ class SoloToolMock: else: self.currentSong = max(self.currentSong - 1, 0) -def test_connect(): - expectedDevice = "Launchpad Mini MIDI 1" +@pytest.fixture +def soloToolMock(): + return SoloToolMock() + +@pytest.fixture +def midiWrapperMock(): + return MidiWrapperMock() - soloToolMock = SoloToolMock() - midiWrapperMock = MidiWrapperMock() - uut = MidiController(soloToolMock, midiWrapperMock) +@pytest.fixture +def uut(soloToolMock, midiWrapperMock): + return MidiController(soloToolMock, midiWrapperMock) + +def test_connect(uut, midiWrapperMock): + expectedDevice = "Launchpad Mini MIDI 1" uut.connect() assert midiWrapperMock.connectedDevice == expectedDevice -def test_startStopAndPauseButtons(): +def test_startStopAndPauseButtons(uut, midiWrapperMock, soloToolMock): playPauseButton = 112 stopButton = 96 - - soloToolMock = SoloToolMock() - midiWrapperMock = MidiWrapperMock() - uut = MidiController(soloToolMock, midiWrapperMock) uut.connect() assert soloToolMock.state == SoloToolMock.STOPPED @@ -104,11 +110,8 @@ def test_startStopAndPauseButtons(): midiWrapperMock.simulateInput(stopButton) assert soloToolMock.state == SoloToolMock.STOPPED -def test_jumpToAButton(): +def test_jumpToAButton(uut, midiWrapperMock, soloToolMock): ab = (0.5, 0.6) - soloToolMock = SoloToolMock() - midiWrapperMock = MidiWrapperMock() - uut = MidiController(soloToolMock, midiWrapperMock) uut.connect() soloToolMock.currentAbLimit = (ab[0], ab[1]) @@ -117,10 +120,7 @@ def test_jumpToAButton(): midiWrapperMock.simulateInput(101) assert soloToolMock.position == ab[0] -def test_previousAndNextSongButtons(): - soloToolMock = SoloToolMock() - midiWrapperMock = MidiWrapperMock() - uut = MidiController(soloToolMock, midiWrapperMock) +def test_previousAndNextSongButtons(uut, midiWrapperMock, soloToolMock): uut.connect() assert soloToolMock.currentSong == None @@ -136,11 +136,8 @@ def test_previousAndNextSongButtons(): midiWrapperMock.simulateInput(118) assert soloToolMock.currentSong == 0 -def test_unprogrammedButton(): +def test_unprogrammedButton(uut, midiWrapperMock, soloToolMock): unusedButton = 48 - soloToolMock = SoloToolMock() - midiWrapperMock = MidiWrapperMock() - uut = MidiController(soloToolMock, midiWrapperMock) uut.connect() # expect no crash |