A little cleanup and an extra test
@@ -18,37 +18,25 @@ class TestI2C(unittest.TestCase):
def setUp(self):
self.i2cdevice = i2c.I2C(1)
- def test_handles_list_data(self):
- fake_device = 1
- fake_data = ["s"]
+ def test_filepath(self):
+ self.assertEqual("/dev/i2c-1", self.i2cdevice.filepath)
- with nested(
- mock.patch('io.open'),
- mock.patch('fcntl.ioctl'),
- ) as (mock_open, mock_ioctl):
- assert self.i2cdevice.write(fake_device, fake_data)
+ def test_handles_list_data(self):
+ with nested( mock.patch('io.open'), mock.patch('fcntl.ioctl'),):
+ assert self.i2cdevice.write(1, ["s"])
def test_sets_i2c_as_slave(self):
fake_device = 1
fake_data = "fake"
- with nested(
- mock.patch('io.open'),
- mock.patch('fcntl.ioctl'),
- ) as (mock_open, mock_ioctl):
+ with nested( mock.patch('io.open'), mock.patch('fcntl.ioctl'),) as (_, mock_ioctl):
self.i2cdevice.write(fake_device, fake_data)
mock_ioctl.assert_called_with(mock.ANY, i2c.I2C_SLAVE, fake_device)
def test_wrong_datatype_raises_type_error(self):
- fake_device = 1
- fake_data = 123 # Non-string
-
- with nested(
- mock.patch('io.open'),
- mock.patch('fcntl.ioctl'),
- ) as (mock_open, mock_ioctl):
+ with nested(mock.patch('io.open'), mock.patch('fcntl.ioctl'),):
with self.assertRaises(TypeError):
- self.i2cdevice.write(fake_device, fake_data)
+ self.i2cdevice.write(1, 123)
if __name__ == '__main__':
