From 6bca1fc45599bd13d431a86cdc83ef74c62f1fc1 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 1 Apr 2016 20:04:15 -0700 Subject: [PATCH] Fix decode() string error in about text - fix qt try/except error in projector --- openlp/core/lib/projector/pjlink1.py | 18 +++++++----------- openlp/core/utils/__init__.py | 4 ++-- .../openlp_core_lib/test_projector_pjlink1.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/openlp/core/lib/projector/pjlink1.py b/openlp/core/lib/projector/pjlink1.py index c5c765d62..4cdd31269 100644 --- a/openlp/core/lib/projector/pjlink1.py +++ b/openlp/core/lib/projector/pjlink1.py @@ -513,17 +513,13 @@ class PJLink1(QTcpSocket): log.debug('(%s) _send_string(): Sending "%s"' % (self.ip, out.strip())) log.debug('(%s) _send_string(): Queue = %s' % (self.ip, self.send_queue)) self.socket_timer.start() - try: - self.projectorNetwork.emit(S_NETWORK_SENDING) - sent = self.write(out.encode('ascii')) - self.waitForBytesWritten(2000) # 2 seconds should be enough - if sent == -1: - # Network error? - self.change_status(E_NETWORK, - translate('OpenLP.PJLink1', 'Error while sending data to projector')) - except SocketError as e: - self.disconnect_from_host(abort=True) - self.changeStatus(E_NETWORK, '%s : %s' % (e.error(), e.errorString())) + self.projectorNetwork.emit(S_NETWORK_SENDING) + sent = self.write(out.encode('ascii')) + self.waitForBytesWritten(2000) # 2 seconds should be enough + if sent == -1: + # Network error? + self.change_status(E_NETWORK, + translate('OpenLP.PJLink1', 'Error while sending data to projector')) def process_command(self, cmd, data): """ diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 6829383de..8b09b18a2 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -186,9 +186,9 @@ def get_application_version(): # If they are equal, then this tree is tarball with the source for the release. We do not want the revision # number in the full version. if tree_revision == tag_revision: - full_version = tag_version.decode('utf-8') + full_version = tag_version.strip() else: - full_version = '%s-bzr%s' % (tag_version.decode('utf-8'), tree_revision.decode('utf-8')) + full_version = '%s-bzr%s' % (tag_version.strip(), tree_revision.strip()) else: # We're not running the development version, let's use the file. file_path = AppLocation.get_directory(AppLocation.VersionDir) diff --git a/tests/functional/openlp_core_lib/test_projector_pjlink1.py b/tests/functional/openlp_core_lib/test_projector_pjlink1.py index 7e19ff065..a3d99e884 100644 --- a/tests/functional/openlp_core_lib/test_projector_pjlink1.py +++ b/tests/functional/openlp_core_lib/test_projector_pjlink1.py @@ -92,3 +92,18 @@ class TestPJLink(TestCase): mock_change_status.called_with(E_PARAMETER, 'change_status should have been called with "{}"'.format( ERROR_STRING[E_PARAMETER])) + + @patch.object(pjlink_test, 'process_inpt') + def projector_return_ok_test(self, mock_process_inpt): + """ + Test projector calls process_inpt command when process_command is called with INPT option + """ + # GIVEN: Test object + pjlink = pjlink_test + + # WHEN: process_command is called with INST command and 31 input: + pjlink.process_command('INPT', '31') + + # THEN: process_inpt method should have been called with 31 + mock_process_inpt.called_with('31', + "process_inpt should have been called with 31")