コード例 #1
0
    def test_not_configured_to_read(self):
        i2c = MagicMock()

        reg = Register("NAME", 1, 2, Register.WRITE, {})
        reg.add("SEG_NAME", 0, 2, [0] * 3)

        with self.assertRaises(AttributeError):
            reg.read(i2c)
コード例 #2
0
    def test_i2c_read_fail(self):
        i2c = MagicMock()
        i2c.readBytes = MagicMock(side_effect=Exception("Exception"))

        reg = Register("NAME", 1, 2, Register.READ, {})
        reg.add("SEG_NAME", 0, 2, [0] * 3)

        with self.assertRaises(SystemError):
            reg.read(i2c)
コード例 #3
0
    def test_not_enough_bytes_read(self):
        i2c = MagicMock()
        i2c.readBytes = MagicMock(return_value=[32])

        reg = Register("NAME", 1, 2, Register.READ, {})
        reg.add("SEG_NAME", 9, 11, [0] * 3)

        with self.assertRaises(KeyError):
            reg.read(i2c)
コード例 #4
0
    def test_perfect(self):
        i2c = MagicMock()
        i2c.readBytes = MagicMock(return_value=[213, 170])

        reg = Register("NAME", 1, 2, Register.READ, {})
        reg.add("SEG_NAME", 0, 2, [0] * 3)

        reg.read(i2c)

        self.assertEqual(reg.get("SEG_NAME").bits, [1, 0, 1])