Beispiel #1
0
    def _write_test(self, item):
        # check writes call appropriate libftdi function
        self.assertCalls(lambda: setattr(self.sd, item, 1), 'ftdi_set' + item)
        # check reads don't call anything
        self.assertCallsExact(lambda: getattr(self.sd, item), [])

    def test_cts(self):
        """check setting and getting cts"""
        self._read_test('cts')

    def test_dsr(self):
        """check setting and getting dsr"""
        self._read_test('dsr')

    def test_ri(self):
        """check setting and getting ri"""
        self._read_test('ri')

    def test_dtr(self):
        """check setting and getting dtr"""
        self._write_test('dtr')

    def test_rts(self):
        """check setting and getting rts"""
        self._write_test('rts')


if __name__ == "__main__":
    unittest.main()
Beispiel #2
0
            self.device = TestBus.MockDevice()

    def test_bus_write(self):
        test_bus = TestBus.Bus1()
        # test writing to the bus
        self.assertEqual(test_bus.device.port, 0)
        test_bus.a = 3
        test_bus.b = 1
        test_bus.c = 31
        self.assertEqual(test_bus.device.port, 255)
        test_bus.b = 0
        self.assertEqual(test_bus.device.port, 251)
        test_bus.c = 16
        self.assertEqual(test_bus.device.port, 131)

    def test_bus_read(self):
        test_bus = TestBus.Bus1()
        # test reading from the bus
        test_bus.device.port = 0x55
        assert test_bus.a == 1
        assert test_bus.b == 1
        assert test_bus.c == 10
        test_bus.device.port = 0xAA
        assert test_bus.a == 2
        assert test_bus.b == 0
        assert test_bus.c == 21


if __name__ == "__main__":
    unittest.main()