def test_projector_reset_information(self):
        """
        Test reset_information() resets all information and stops timers
        """
        # GIVEN: Test object
        with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
            pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
            log_debug_calls = [call('({ip}): Calling poll_timer.stop()'.format(ip=pjlink.name)),
                               call('({ip}): Calling socket_timer.stop()'.format(ip=pjlink.name))]
            # timer and socket_timer not available until instantiation, so mock here
            with patch.object(pjlink, 'socket_timer') as mock_socket_timer, \
                    patch.object(pjlink, 'poll_timer') as mock_timer:

                pjlink.power = S_ON
                pjlink.pjlink_name = 'OPENLPTEST'
                pjlink.manufacturer = 'PJLINK'
                pjlink.model = '1'
                pjlink.shutter = True
                pjlink.mute = True
                pjlink.lamp = True
                pjlink.fan = True
                pjlink.source_available = True
                pjlink.other_info = 'ANOTHER TEST'
                pjlink.send_queue = True
                pjlink.send_busy = True

                # WHEN: reset_information() is called
                pjlink.reset_information()

                # THEN: All information should be reset and timers stopped
                assert pjlink.power == S_OFF, 'Projector power should be OFF'
                assert pjlink.pjlink_name is None, 'Projector pjlink_name should be None'
                assert pjlink.manufacturer is None, 'Projector manufacturer should be None'
                assert pjlink.model is None, 'Projector model should be None'
                assert pjlink.shutter is None, 'Projector shutter should be None'
                assert pjlink.mute is None, 'Projector shuttter should be None'
                assert pjlink.lamp is None, 'Projector lamp should be None'
                assert pjlink.fan is None, 'Projector fan should be None'
                assert pjlink.source_available is None, 'Projector source_available should be None'
                assert pjlink.source is None, 'Projector source should be None'
                assert pjlink.other_info is None, 'Projector other_info should be None'
                assert pjlink.send_queue == [], 'Projector send_queue should be an empty list'
                assert pjlink.send_busy is False, 'Projector send_busy should be False'
                assert mock_timer.stop.called is True, 'Projector timer.stop()  should have been called'
                assert mock_socket_timer.stop.called is True, 'Projector socket_timer.stop() should have been called'
                mock_log.debug.assert_has_calls(log_debug_calls)
예제 #2
0
    def test_poll_loop_set_interval(self):
        """
        Test PJLink.poll_loop makes correct calls
        """
        # GIVEN: Mocks and test data
        with patch('openlp.core.projectors.pjlink.PJLink.send_command') as mock_send_command:

            pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
            pjlink.state = MagicMock()
            pjlink.state.return_value = QSOCKET_STATE[S_CONNECTED]
            pjlink.poll_timer = MagicMock()
            pjlink.poll_timer.interval.return_value = 10

            pjlink.poll_time = 20
            pjlink.power = S_ON
            pjlink.source_available = None
            pjlink.other_info = None
            pjlink.manufacturer = None
            pjlink.model = None
            pjlink.pjlink_name = None
            call_list = [
                call('POWR'),
                call('ERST'),
                call('LAMP'),
                call('AVMT'),
                call('INPT'),
                call('INST'),
                call('INFO'),
                call('INF1'),
                call('INF2'),
                call('NAME'),
            ]

            # WHEN: PJLink.poll_loop is called
            pjlink.poll_loop()

            # THEN: proper calls were made to retrieve projector data
            # First, call to update the timer with the next interval
            assert pjlink.poll_timer.setInterval.called is True, 'Timer update interval should have been called'
            # Finally, should have called send_command with a list of projetctor status checks
            mock_send_command.assert_has_calls(call_list, 'Should have queued projector queries')