Fixes of additional flake8 errors

rotencoder
Martin Felis 2021-03-13 20:40:43 +01:00
parent b3778d8cd2
commit 5c97976f15
1 changed files with 11 additions and 13 deletions

View File

@ -1,34 +1,32 @@
import sys
import pytest
import unittest
from unittest.mock import patch
from mopidy_raspberry_gpio import RotEncoder
from unittest.mock import patch, MagicMock
class RotEncoderTests(unittest.TestCase):
def test_rotenc_init(self):
rot_enc = RotEncoder("vol")
self.assertTrue (rot_enc.id == "vol")
self.assertTrue (((False,False), (False, True)) in rot_enc.state_map)
self.assertTrue(rot_enc.id == "vol")
self.assertTrue(((False, False), (False, True)) in rot_enc.state_map)
def test_get_direction(self):
rot_enc = RotEncoder("vol")
rot_enc.add_pin(123, "vol_up")
rot_enc.add_pin(124, "vol_down")
dir_down = rot_enc.get_direction ((False, False), (False, True))
dir_up = rot_enc.get_direction ((False, False), (True, False))
dir_down = rot_enc.get_direction((False, False), (False, True))
dir_up = rot_enc.get_direction((False, False), (True, False))
self.assertEqual (dir_up, 1)
self.assertEqual (dir_down, 0)
self.assertEqual(dir_up, 1)
self.assertEqual(dir_down, 0)
def test_add_pin_invalid(self):
rot_enc = RotEncoder("vol")
rot_enc.add_pin(123, "vol_up")
rot_enc.add_pin(124, "vol_down")
with self.assertRaises(RuntimeError) as cm:
with self.assertRaises(RuntimeError):
rot_enc.add_pin(124, "vol_down")
@patch("RPi.GPIO.input")
@ -37,8 +35,8 @@ class RotEncoderTests(unittest.TestCase):
patched_input.return_value = False
rot_enc = RotEncoder("vol")
rot_enc.add_pin(123, "vol_down") # dir 0 => vol_down
rot_enc.add_pin(124, "vol_up") # dir 1 => vol_up
rot_enc.add_pin(123, "vol_down") # dir 0 => vol_down
rot_enc.add_pin(124, "vol_up") # dir 1 => vol_up
# from False,True to False,False => dir 1
rot_enc.state = (False, True)