Пример #1
0
    def testKramer602Listener(self):
        port = MockSerialPort()
        port.read = MagicMock(return_value=[chr(0x28), chr(0x81)])  # Notification that input 1 sent to output 1

        k = Kramer602("Test", port)

        c = Controller()
        c.addDevice(k)
        kl = Kramer602Listener("TestListener", k.deviceID, c, machineNumber=1)

        dispatcher = NullDispatcher()
        dispatcher.updateOutputMappings = MagicMock()
        kl.registerDispatcher(dispatcher)
        kl.start()
        threading.Event().wait(0.1)
        kl.stop()

        dispatcher.updateOutputMappings.assert_called_with({'Test': {1: 1}})

        port = MockSerialPort()
        port.read = MagicMock(return_value=[chr(0x28), chr(0x8A)])  # Notification that input 5 sent to output 2

        k = Kramer602("Test", port)
        c = Controller()
        c.addDevice(k)
        kl = Kramer602Listener("TestListener", k.deviceID, c, machineNumber=1)

        dispatcher = NullDispatcher()
        dispatcher.updateOutputMappings = MagicMock()
        kl.registerDispatcher(dispatcher)
        kl.start()
        threading.Event().wait(0.1)
        kl.stop()

        dispatcher.updateOutputMappings.assert_called_with({'Test': {2: 5}})
Пример #2
0
    def testGetPosition(self):
        port = MockSerialPort()

        cam = VISCACamera("Test Camera", port, 1)

        port.setDataForRead([
            chr(0x10),
            chr(0x50),
            chr(0x01),
            chr(0x02),
            chr(0x03),
            chr(0x04),
            chr(0x0A),
            chr(0x0B),
            chr(0x0C),
            chr(0x0D),
            chr(0xFF)
        ])

        pos = cam.getPosition()

        self.assertEqual(pos.pan, 0x1234)
        self.assertEqual(pos.tilt, 0xABCD)
        self.assertEqual(
            pos.zoom, 0x1234
        )  # This is a bit of a hack since getPosition() results in two calls to port.read()
Пример #3
0
    def testSerialDevice(self):
        port = MockSerialPort()
        port.portstr = "TESTPORT"
        device = SerialDevice("Test", port)

        port.write = MagicMock(side_effect=SerialException("Test serial exception"))

        device.sendCommand("\x01")

        self.assertEqual(port.write.call_count, 2)
Пример #4
0
    def testSetAperture(self):
        port = MockSerialPort()

        cam = VISCACamera("Test Camera", port, 1)

        cam.setAperture(Aperture.F28)
        self.assertBytesEqual([0x81, 0x01, 0x04, 0x4B, 0x00, 0x00, 0x00, 0x01, 0xFF], port.bytes)

        port.clear()
        cam.setAperture(Aperture.F1_8)
        self.assertBytesEqual([0x81, 0x01, 0x04, 0x4B, 0x00, 0x00, 0x01, 0x01, 0xFF], port.bytes)
Пример #5
0
    def testSerialDevice(self):
        port = MockSerialPort()
        port.portstr = "TESTPORT"
        device = SerialDevice("Test", port)

        port.write = MagicMock(
            side_effect=SerialException("Test serial exception"))

        device.sendCommand("\x01")

        self.assertEqual(port.write.call_count, 2)
Пример #6
0
    def testGetPosition(self):
        port = MockSerialPort()

        cam = VISCACamera("Test Camera", port, 1)

        port.setDataForRead([chr(0x10), chr(0x50), chr(0x01), chr(0x02), chr(0x03), chr(0x04), chr(0x0A), chr(0x0B), chr(0x0C), chr(0x0D), chr(0xFF)])

        pos = cam.getPosition()

        self.assertEqual(pos.pan, 0x1234)
        self.assertEqual(pos.tilt, 0xABCD)
        self.assertEqual(pos.zoom, 0x1234)  # This is a bit of a hack since getPosition() results in two calls to port.read()
Пример #7
0
    def testSetAperture(self):
        port = MockSerialPort()

        cam = VISCACamera("Test Camera", port, 1)

        cam.setAperture(Aperture.F28)
        self.assertBytesEqual(
            [0x81, 0x01, 0x04, 0x4B, 0x00, 0x00, 0x00, 0x01, 0xFF], port.bytes)

        port.clear()
        cam.setAperture(Aperture.F1_8)
        self.assertBytesEqual(
            [0x81, 0x01, 0x04, 0x4B, 0x00, 0x00, 0x01, 0x01, 0xFF], port.bytes)
Пример #8
0
    def testInline3808(self):

        port = MockSerialPort()

        inline = Inline3808("Test", port)

        inline.initialise()

        self.assertEqual(list("[CNF290000]"), port.bytes)

        port.clear()

        inline.sendInputToOutput(3, 2)
        self.assertEqual(list("[PT1O02I03]"), port.bytes)
Пример #9
0
    def testInline3808(self):

        port = MockSerialPort()

        inline = Inline3808("Test", port)

        inline.initialise()

        self.assertEqual(list("[CNF290000]"), port.bytes)

        port.clear()

        inline.sendInputToOutput(3, 2)
        self.assertEqual(list("[PT1O02I03]"), port.bytes)
Пример #10
0
    def testKramerVP88(self):
        port = MockSerialPort()
        vp88 = KramerVP88("Test", port)

        vp88.initialise()
        self.assertBytesEqual([
            0x05, 0x80, 0x81, 0x81, 0x05, 0x80, 0x82, 0x81, 0x05, 0x80, 0x83,
            0x81, 0x05, 0x80, 0x84, 0x81, 0x05, 0x80, 0x85, 0x81, 0x05, 0x80,
            0x86, 0x81, 0x05, 0x80, 0x87, 0x81, 0x05, 0x80, 0x88, 0x81
        ], port.bytes)
        port.clear()

        vp88.sendInputToOutput(2, 8)
        self.assertBytesEqual([0x01, 0x82, 0x88, 0x81], port.bytes)
Пример #11
0
    def testKramer602(self):
        port = MockSerialPort()
        k602 = Kramer602("Test", port)

        k602.initialise()
        self.assertBytesEqual([0x0, 0xA1], port.bytes)
        port.clear()

        k602.sendInputToOutput(2, 1)
        self.assertBytesEqual([0x0, 0x83], port.bytes)

        port.clear()

        k602.sendInputToOutput(1, 2)
        self.assertBytesEqual([0x0, 0x82], port.bytes)
Пример #12
0
    def testKMtronicSerialRelayCard(self):
        port = MockSerialPort()
        card = KMtronicSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual([], port.bytes)

        card.on(1)
        self.assertEqual(['\xFF', '\x01', '\x01'], port.bytes)
        port.clear()

        channel = card.createDevice("channel", 2)
        channel.on()
        self.assertEqual(['\xFF', '\x02', '\x01'], port.bytes)
        port.clear()
        channel.off()
        self.assertEqual(['\xFF', '\x02', '\x00'], port.bytes)
Пример #13
0
    def testKramerVP88(self):
        port = MockSerialPort()
        vp88 = KramerVP88("Test", port)

        vp88.initialise()
        self.assertBytesEqual([0x05, 0x80, 0x81, 0x81,
                               0x05, 0x80, 0x82, 0x81,
                               0x05, 0x80, 0x83, 0x81,
                               0x05, 0x80, 0x84, 0x81,
                               0x05, 0x80, 0x85, 0x81,
                               0x05, 0x80, 0x86, 0x81,
                               0x05, 0x80, 0x87, 0x81,
                               0x05, 0x80, 0x88, 0x81], port.bytes)
        port.clear()

        vp88.sendInputToOutput(2, 8)
        self.assertBytesEqual([0x01, 0x82, 0x88, 0x81], port.bytes)
Пример #14
0
    def testKramer602(self, logging):
        port = MockSerialPort()
        k602 = Kramer602("Test", port)

        k602.initialise()
        self.assertBytesEqual([0x0, 0xA1], port.bytes)
        port.clear()

        k602.sendInputToOutput(2, 1)
        self.assertBytesEqual([0x0, 0x83], port.bytes)

        port.clear()

        k602.sendInputToOutput(1, 2)
        self.assertBytesEqual([0x0, 0x82], port.bytes)

        k602.sendInputToOutput(2, 3)
        logging.error.assert_called_once_with("Output channel 3 does not exist on switcher Test")
Пример #15
0
    def testKramerVP88Listener(self):
        port = MockSerialPort()
        port.read = MagicMock(return_value=[
            chr(0x41), chr(0x82), chr(0x83),
            chr(0x81)
        ])  # Notification that input 2 sent to output 3

        k = KramerVP88("Test", port)

        c = Controller()
        c.addDevice(k)
        kl = KramerVP88Listener("TestListener", k.deviceID, c, machineNumber=1)

        dispatcher = NullDispatcher()
        dispatcher.updateOutputMappings = MagicMock()
        kl.registerDispatcher(dispatcher)
        kl.start()
        threading.Event().wait(0.1)
        kl.stop()

        dispatcher.updateOutputMappings.assert_called_with({'Test': {3: 2}})
Пример #16
0
    def testUnisonDevice(self):
        port = MockSerialPort()
        unison = UnisonDevice("Test", port)

        activate = unison.activate("Test.Test.Preset1")
        self.assertBytesEqual([0xEE, 25, 0, 0, 0x40,
                               ord('T'), ord('e'), ord('s'), ord('t'), ord('.'),
                               ord('T'), ord('e'), ord('s'), ord('t'), ord('.'),
                               ord('P'), ord('r'), ord('e'), ord('s'), ord('e'), ord('t'), ord('1'), ord('.'),
                               ord('A'), ord('C'), ord('T'), ord('I'),
                               0, 0], port.bytes)
        self.assertEquals(29, activate)

        port.clear()

        deact = unison.deactivate("Test.Test.Preset2")
        self.assertBytesEqual([0xEE, 25, 0, 0, 0x40,
                               ord('T'), ord('e'), ord('s'), ord('t'), ord('.'),
                               ord('T'), ord('e'), ord('s'), ord('t'), ord('.'),
                               ord('P'), ord('r'), ord('e'), ord('s'), ord('e'), ord('t'), ord('2'), ord('.'),
                               ord('D'), ord('A'), ord('C'), ord('T'),
                               0, 0], port.bytes)
        self.assertEquals(29, deact)
Пример #17
0
    def testJBSerialRelayCard(self):
        port = MockSerialPort()
        card = JBSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual([], port.bytes)
        port.clear()

        card.on(1)
        self.assertEqual(['\x32'], port.bytes)
        port.clear()

        channel = card.createDevice("channel", 2)
        channel.on()
        self.assertEqual(['\x34'], port.bytes)
        port.clear()
        channel.off()
        self.assertEqual(['\x35'], port.bytes)
Пример #18
0
    def testKramerVP703(self):
        port = MockSerialPort()
        vp703 = KramerVP703("Test", port)

        vp703.initialise()
        self.assertEqual(list(b"Overscan = 1\r\n"), port.bytes)
        port.clear()

        vp703.overscanOff()
        self.assertEqual(list(b"Overscan = 0\r\n"), port.bytes)
        port.clear()

        vp703.freeze()
        self.assertEqual(list(b"Image Freeze = 1\r\n"), port.bytes)
        port.clear()

        vp703.unfreeze()
        self.assertEqual(list(b"Image Freeze = 0\r\n"), port.bytes)
Пример #19
0
    def testKramerVP703(self):
        port = MockSerialPort()
        vp703 = KramerVP703("Test", port)

        vp703.initialise()
        self.assertEqual(list(b"Overscan = 1\r\n"), port.bytes)
        port.clear()

        vp703.overscanOff()
        self.assertEqual(list(b"Overscan = 0\r\n"), port.bytes)
        port.clear()

        vp703.freeze()
        self.assertEqual(list(b"Image Freeze = 1\r\n"), port.bytes)
        port.clear()

        vp703.unfreeze()
        self.assertEqual(list(b"Image Freeze = 0\r\n"), port.bytes)
        port.clear()

        vp703.recalibrate()
        self.assertEqual(list(b"AutoTrack = 1\r\n"), port.bytes)
Пример #20
0
    def testJBSerialRelayCard(self):
        port = MockSerialPort()
        card = JBSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual([], port.bytes)
        port.clear()

        card.on(1)
        self.assertEqual(['\x32'], port.bytes)
        port.clear()

        channel = card.createDevice("channel", 2)
        channel.on()
        self.assertEqual(['\x34'], port.bytes)
        port.clear()
        channel.off()
        self.assertEqual(['\x35'], port.bytes)
Пример #21
0
    def testKramer602(self):
        port = MockSerialPort()
        k602 = Kramer602("Test", port)

        k602.initialise()
        self.assertBytesEqual([0x0, 0xA1], port.bytes)
        port.clear()

        k602.sendInputToOutput(2, 1)
        self.assertBytesEqual([0x0, 0x83], port.bytes)

        port.clear()

        k602.sendInputToOutput(1, 2)
        self.assertBytesEqual([0x0, 0x82], port.bytes)
Пример #22
0
    def testKMtronicSerialRelayCard(self):
        port = MockSerialPort()
        card = KMtronicSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual([], port.bytes)

        card.on(1)
        self.assertEqual(['\xFF', '\x01', '\x01'], port.bytes)
        port.clear()

        channel = card.createDevice("channel", 2)
        channel.on()
        self.assertEqual(['\xFF', '\x02', '\x01'], port.bytes)
        port.clear()
        channel.off()
        self.assertEqual(['\xFF', '\x02', '\x00'], port.bytes)
Пример #23
0
    def testICStationSerialRelayCard(self):
        port = MockSerialPort()
        card = ICStationSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual(['\x50', '\x51', '\xff'], port.bytes)
        port.clear()

        card.initialise()
        self.assertEqual([], port.bytes)

        card.on(1)
        self.assertEqual(['\xfe'], port.bytes)
        port.clear()

        card.on(5)
        self.assertEqual(['\xee'], port.bytes)
        port.clear()

        card.on(8)
        self.assertEqual(['\x6e'], port.bytes)
        port.clear()

        card.off(5)
        self.assertEqual(['\x7e'], port.bytes)
        port.clear()

        try:
            card.on(9)
            self.fail(
                "Didn't throw an exception when channel was out of range")
        except InvalidArgumentException:
            pass
Пример #24
0
    def testICStationSerialRelayCard(self):
        port = MockSerialPort()
        card = ICStationSerialRelayCard("Test", port)

        card.initialise()
        self.assertEqual(['\x50', '\x51', '\xff'], port.bytes)
        port.clear()

        card.initialise()
        self.assertEqual([], port.bytes)

        card.on(1)
        self.assertEqual(['\xfe'], port.bytes)
        port.clear()

        card.on(5)
        self.assertEqual(['\xee'], port.bytes)
        port.clear()

        card.on(8)
        self.assertEqual(['\x6e'], port.bytes)
        port.clear()

        card.off(5)
        self.assertEqual(['\x7e'], port.bytes)
        port.clear()

        try:
            card.on(9)
            self.fail("Didn't throw an exception when channel was out of range")
        except InvalidArgumentException:
            pass
Пример #25
0
    def testCoriogenEclipse(self):
        port = MockSerialPort()
        ce = CoriogenEclipse("Test", port)

        ce.initialise()
        self.assertEqual([], port.bytes)

        ce.fadeIn()
        self.assertEqual(list(b"Fade = 1\r\n"), port.bytes)
        port.clear()

        ce.fadeIn()
        self.assertEqual(list(b"Fade = 1\r\n"), port.bytes)
        port.clear()

        ce.fadeOut()
        self.assertEqual(list(b"Fade = 0\r\n"), port.bytes)
        port.clear()

        ce.freeze()
        self.assertEqual(list(b"Freeze = On\r\n"), port.bytes)
        port.clear()

        ce.unfreeze()
        self.assertEqual(list(b"Freeze = Off\r\n"), port.bytes)
        port.clear()

        ce.overlayOn()
        self.assertEqual(list(b"Mode = 3\r\n"), port.bytes)
        port.clear()

        ce.overlayOff()
        self.assertEqual(list(b"Mode = 0\r\n"), port.bytes)
Пример #26
0
    def testCoriogenEclipse(self):
        port = MockSerialPort()
        ce = CoriogenEclipse("Test", port)

        ce.initialise()
        self.assertEqual([], port.bytes)

        ce.fadeIn()
        self.assertEqual(list(b"Fade = 1\r\n"), port.bytes)
        port.clear()

        ce.fadeIn()
        self.assertEqual(list(b"Fade = 1\r\n"), port.bytes)
        port.clear()

        ce.fadeOut()
        self.assertEqual(list(b"Fade = 0\r\n"), port.bytes)
        port.clear()

        ce.freeze()
        self.assertEqual(list(b"Freeze = On\r\n"), port.bytes)
        port.clear()

        ce.unfreeze()
        self.assertEqual(list(b"Freeze = Off\r\n"), port.bytes)
        port.clear()

        ce.overlayOn()
        self.assertEqual(list(b"Mode = 3\r\n"), port.bytes)
        port.clear()

        ce.overlayOff()
        self.assertEqual(list(b"Mode = 0\r\n"), port.bytes)
Пример #27
0
    def testUnisonDevice(self):
        port = MockSerialPort()
        unison = UnisonDevice("Test", port)

        activate = unison.activate("Test.Test.Preset1")
        self.assertBytesEqual([
            0xEE, 25, 0, 0, 0x40,
            ord('T'),
            ord('e'),
            ord('s'),
            ord('t'),
            ord('.'),
            ord('T'),
            ord('e'),
            ord('s'),
            ord('t'),
            ord('.'),
            ord('P'),
            ord('r'),
            ord('e'),
            ord('s'),
            ord('e'),
            ord('t'),
            ord('1'),
            ord('.'),
            ord('A'),
            ord('C'),
            ord('T'),
            ord('I'), 0, 0
        ], port.bytes)
        self.assertEquals(29, activate)

        port.clear()

        deact = unison.deactivate("Test.Test.Preset2")
        self.assertBytesEqual([
            0xEE, 25, 0, 0, 0x40,
            ord('T'),
            ord('e'),
            ord('s'),
            ord('t'),
            ord('.'),
            ord('T'),
            ord('e'),
            ord('s'),
            ord('t'),
            ord('.'),
            ord('P'),
            ord('r'),
            ord('e'),
            ord('s'),
            ord('e'),
            ord('t'),
            ord('2'),
            ord('.'),
            ord('D'),
            ord('A'),
            ord('C'),
            ord('T'), 0, 0
        ], port.bytes)
        self.assertEquals(29, deact)