Fix deprecated log calls

This commit is contained in:
Ken Roberts 2017-08-12 13:38:50 -07:00
parent f30d7f20d3
commit 6d353dc8e1
3 changed files with 39 additions and 38 deletions

View File

@ -159,7 +159,7 @@ class PJLinkCommands(object):
# A command returned successfully, no further processing needed # A command returned successfully, no further processing needed
return return
elif _cmd not in self.pjlink_functions: elif _cmd not in self.pjlink_functions:
log.warn("({ip}) Unable to process command='{cmd}' (Future option)".format(ip=self.ip, cmd=cmd)) log.warning("({ip}) Unable to process command='{cmd}' (Future option)".format(ip=self.ip, cmd=cmd))
return return
elif _data in PJLINK_ERRORS: elif _data in PJLINK_ERRORS:
# Oops - projector error # Oops - projector error
@ -231,7 +231,7 @@ class PJLinkCommands(object):
# : Received: '%1CLSS=Class 1' (Optoma) # : Received: '%1CLSS=Class 1' (Optoma)
# : Received: '%1CLSS=Version1' (BenQ) # : Received: '%1CLSS=Version1' (BenQ)
if len(data) > 1: if len(data) > 1:
log.warn("({ip}) Non-standard CLSS reply: '{data}'".format(ip=self.ip, data=data)) log.warning("({ip}) Non-standard CLSS reply: '{data}'".format(ip=self.ip, data=data))
# Due to stupid projectors not following standards (Optoma, BenQ comes to mind), # Due to stupid projectors not following standards (Optoma, BenQ comes to mind),
# AND the different responses that can be received, the semi-permanent way to # AND the different responses that can be received, the semi-permanent way to
# fix the class reply is to just remove all non-digit characters. # fix the class reply is to just remove all non-digit characters.
@ -261,7 +261,7 @@ class PJLinkCommands(object):
""" """
if len(data) != PJLINK_ERST_DATA['DATA_LENGTH']: if len(data) != PJLINK_ERST_DATA['DATA_LENGTH']:
count = PJLINK_ERST_DATA['DATA_LENGTH'] count = PJLINK_ERST_DATA['DATA_LENGTH']
log.warn("{ip}) Invalid error status response '{data}': length != {count}".format(ip=self.ip, log.warning("{ip}) Invalid error status response '{data}': length != {count}".format(ip=self.ip,
data=data, data=data,
count=count)) count=count))
return return
@ -269,7 +269,7 @@ class PJLinkCommands(object):
datacheck = int(data) datacheck = int(data)
except ValueError: except ValueError:
# Bad data - ignore # Bad data - ignore
log.warn("({ip}) Invalid error status response '{data}'".format(ip=self.ip, data=data)) log.warning("({ip}) Invalid error status response '{data}'".format(ip=self.ip, data=data))
return return
if datacheck == 0: if datacheck == 0:
self.projector_errors = None self.projector_errors = None
@ -429,9 +429,9 @@ class PJLinkCommands(object):
if self.model_filter is None: if self.model_filter is None:
self.model_filter = data self.model_filter = data
else: else:
log.warn("({ip}) Filter model already set".format(ip=self.ip)) log.warning("({ip}) Filter model already set".format(ip=self.ip))
log.warn("({ip}) Saved model: '{old}'".format(ip=self.ip, old=self.model_filter)) log.warning("({ip}) Saved model: '{old}'".format(ip=self.ip, old=self.model_filter))
log.warn("({ip}) New model: '{new}'".format(ip=self.ip, new=data)) log.warning("({ip}) New model: '{new}'".format(ip=self.ip, new=data))
def process_rlmp(self, data): def process_rlmp(self, data):
""" """
@ -440,9 +440,9 @@ class PJLinkCommands(object):
if self.model_lamp is None: if self.model_lamp is None:
self.model_lamp = data self.model_lamp = data
else: else:
log.warn("({ip}) Lamp model already set".format(ip=self.ip)) log.warning("({ip}) Lamp model already set".format(ip=self.ip))
log.warn("({ip}) Saved lamp: '{old}'".format(ip=self.ip, old=self.model_lamp)) log.warning("({ip}) Saved lamp: '{old}'".format(ip=self.ip, old=self.model_lamp))
log.warn("({ip}) New lamp: '{new}'".format(ip=self.ip, new=data)) log.warning("({ip}) New lamp: '{new}'".format(ip=self.ip, new=data))
def process_snum(self, data): def process_snum(self, data):
""" """
@ -457,10 +457,10 @@ class PJLinkCommands(object):
else: else:
# Compare serial numbers and see if we got the same projector # Compare serial numbers and see if we got the same projector
if self.serial_no != data: if self.serial_no != data:
log.warn("({ip}) Projector serial number does not match saved serial number".format(ip=self.ip)) log.warning("({ip}) Projector serial number does not match saved serial number".format(ip=self.ip))
log.warn("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.serial_no)) log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.serial_no))
log.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) log.warning("({ip}) Received: '{new}'".format(ip=self.ip, new=data))
log.warn("({ip}) NOT saving serial number".format(ip=self.ip)) log.warning("({ip}) NOT saving serial number".format(ip=self.ip))
self.serial_no_received = data self.serial_no_received = data
def process_sver(self, data): def process_sver(self, data):
@ -469,7 +469,7 @@ class PJLinkCommands(object):
""" """
if len(data) > 32: if len(data) > 32:
# Defined in specs max version is 32 characters # Defined in specs max version is 32 characters
log.warn("Invalid software version - too long") log.warning("Invalid software version - too long")
return return
elif self.sw_version is None: elif self.sw_version is None:
log.debug("({ip}) Setting projector software version to '{data}'".format(ip=self.ip, data=data)) log.debug("({ip}) Setting projector software version to '{data}'".format(ip=self.ip, data=data))
@ -478,10 +478,11 @@ class PJLinkCommands(object):
else: else:
# Compare software version and see if we got the same projector # Compare software version and see if we got the same projector
if self.serial_no != data: if self.serial_no != data:
log.warn("({ip}) Projector software version does not match saved software version".format(ip=self.ip)) log.warning("({ip}) Projector software version does not match saved "
log.warn("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version)) "software version".format(ip=self.ip))
log.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version))
log.warn("({ip}) Saving new serial number as sw_version_received".format(ip=self.ip)) log.warning("({ip}) Received: '{new}'".format(ip=self.ip, new=data))
log.warning("({ip}) Saving new serial number as sw_version_received".format(ip=self.ip))
self.sw_version_received = data self.sw_version_received = data
@ -609,7 +610,7 @@ class PJLink(PJLinkCommands, QtNetwork.QTcpSocket):
Normally called by timer(). Normally called by timer().
""" """
if self.state() != self.ConnectedState: if self.state() != self.ConnectedState:
log.warn("({ip}) poll_loop(): Not connected - returning".format(ip=self.ip)) log.warning("({ip}) poll_loop(): Not connected - returning".format(ip=self.ip))
return return
log.debug('({ip}) Updating projector status'.format(ip=self.ip)) log.debug('({ip}) Updating projector status'.format(ip=self.ip))
# Reset timer in case we were called from a set command # Reset timer in case we were called from a set command
@ -839,7 +840,7 @@ class PJLink(PJLinkCommands, QtNetwork.QTcpSocket):
log.warning('({ip}) get_data(): Invalid packet - unknown command "{data}"'.format(ip=self.ip, data=cmd)) log.warning('({ip}) get_data(): Invalid packet - unknown command "{data}"'.format(ip=self.ip, data=cmd))
return self._trash_buffer(msg='get_data(): Unknown command "{data}"'.format(data=cmd)) return self._trash_buffer(msg='get_data(): Unknown command "{data}"'.format(data=cmd))
if int(self.pjlink_class) < int(version): if int(self.pjlink_class) < int(version):
log.warn('({ip}) get_data(): Projector returned class reply higher ' log.warning('({ip}) get_data(): Projector returned class reply higher '
'than projector stated class'.format(ip=self.ip)) 'than projector stated class'.format(ip=self.ip))
return self.process_command(cmd, data) return self.process_command(cmd, data)

View File

@ -179,7 +179,7 @@ class TestPJLinkRouting(TestCase):
# THEN: Error should be logged and no command called # THEN: Error should be logged and no command called
self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method') self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method')
mock_log.warn.assert_called_once_with(log_text) mock_log.warning.assert_called_once_with(log_text)
@patch.object(pjlink_test, 'pjlink_functions') @patch.object(pjlink_test, 'pjlink_functions')
@patch.object(openlp.core.lib.projector.pjlink, 'log') @patch.object(openlp.core.lib.projector.pjlink, 'log')

View File

@ -607,12 +607,12 @@ class TestPJLinkCommands(TestCase):
# WHEN: Process invalid reply # WHEN: Process invalid reply
pjlink.process_clss('Z') pjlink.process_clss('Z')
log_warn_text = "(127.0.0.1) NAN clss version reply 'Z' - defaulting to class '1'" log_text = "(127.0.0.1) NAN clss version reply 'Z' - defaulting to class '1'"
# THEN: Projector class should be set with default value # THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', self.assertEqual(pjlink.pjlink_class, '1',
'Non-standard class reply should have set class=1') 'Non-standard class reply should have set class=1')
mock_log.error.assert_called_once_with(log_warn_text) mock_log.error.assert_called_once_with(log_text)
@patch.object(openlp.core.lib.projector.pjlink, 'log') @patch.object(openlp.core.lib.projector.pjlink, 'log')
def test_projector_process_clss_invalid_no_version(self, mock_log): def test_projector_process_clss_invalid_no_version(self, mock_log):
@ -624,12 +624,12 @@ class TestPJLinkCommands(TestCase):
# WHEN: Process invalid reply # WHEN: Process invalid reply
pjlink.process_clss('Invalid') pjlink.process_clss('Invalid')
log_warn_text = "(127.0.0.1) No numbers found in class version reply 'Invalid' - defaulting to class '1'" log_text = "(127.0.0.1) No numbers found in class version reply 'Invalid' - defaulting to class '1'"
# THEN: Projector class should be set with default value # THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', self.assertEqual(pjlink.pjlink_class, '1',
'Non-standard class reply should have set class=1') 'Non-standard class reply should have set class=1')
mock_log.error.assert_called_once_with(log_warn_text) mock_log.error.assert_called_once_with(log_text)
def test_projector_process_erst_all_ok(self): def test_projector_process_erst_all_ok(self):
""" """
@ -654,15 +654,15 @@ class TestPJLinkCommands(TestCase):
# GIVEN: Test object # GIVEN: Test object
pjlink = pjlink_test pjlink = pjlink_test
pjlink.projector_errors = None pjlink.projector_errors = None
log_warn_text = "127.0.0.1) Invalid error status response '11111111': length != 6" log_text = "127.0.0.1) Invalid error status response '11111111': length != 6"
# WHEN: process_erst called with invalid data (too many values # WHEN: process_erst called with invalid data (too many values
pjlink.process_erst('11111111') pjlink.process_erst('11111111')
# THEN: pjlink.projector_errors should be empty and warning logged # THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors') self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
self.assertTrue(mock_log.warn.called, 'Warning should have been logged') self.assertTrue(mock_log.warning.called, 'Warning should have been logged')
mock_log.warn.assert_called_once_with(log_warn_text) mock_log.warning.assert_called_once_with(log_text)
@patch.object(openlp.core.lib.projector.pjlink, 'log') @patch.object(openlp.core.lib.projector.pjlink, 'log')
def test_projector_process_erst_data_invalid_nan(self, mock_log): def test_projector_process_erst_data_invalid_nan(self, mock_log):
@ -672,15 +672,15 @@ class TestPJLinkCommands(TestCase):
# GIVEN: Test object # GIVEN: Test object
pjlink = pjlink_test pjlink = pjlink_test
pjlink.projector_errors = None pjlink.projector_errors = None
log_warn_text = "(127.0.0.1) Invalid error status response '1111Z1'" log_text = "(127.0.0.1) Invalid error status response '1111Z1'"
# WHEN: process_erst called with invalid data (too many values # WHEN: process_erst called with invalid data (too many values
pjlink.process_erst('1111Z1') pjlink.process_erst('1111Z1')
# THEN: pjlink.projector_errors should be empty and warning logged # THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors') self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
self.assertTrue(mock_log.warn.called, 'Warning should have been logged') self.assertTrue(mock_log.warning.called, 'Warning should have been logged')
mock_log.warn.assert_called_once_with(log_warn_text) mock_log.warning.assert_called_once_with(log_text)
def test_projector_process_erst_all_warn(self): def test_projector_process_erst_all_warn(self):
""" """
@ -1080,9 +1080,9 @@ class TestPJLinkCommands(TestCase):
self.assertEqual(pjlink.sw_version, test_data_old, 'Software version should not have been updated') self.assertEqual(pjlink.sw_version, test_data_old, 'Software version should not have been updated')
self.assertEqual(pjlink.sw_version_received, test_data_new, self.assertEqual(pjlink.sw_version_received, test_data_new,
'Received software version should have been changed') 'Received software version should have been changed')
self.assertEqual(mock_log.warn.call_count, 4, 'log.warn should have been called 4 times') self.assertEqual(mock_log.warning.call_count, 4, 'log.warn should have been called 4 times')
# There was 4 calls, but only the last one is checked with this method # There was 4 calls, but only the last one is checked with this method
mock_log.warn.assert_called_with(test_log) mock_log.warning.assert_called_with(test_log)
@patch.object(openlp.core.lib.projector.pjlink, 'log') @patch.object(openlp.core.lib.projector.pjlink, 'log')
def test_projector_process_sver_invalid(self, mock_log): def test_projector_process_sver_invalid(self, mock_log):
@ -1103,7 +1103,7 @@ class TestPJLinkCommands(TestCase):
# THEN: Version information should not change # THEN: Version information should not change
self.assertIsNone(pjlink.sw_version, 'Software version should not have changed') self.assertIsNone(pjlink.sw_version, 'Software version should not have changed')
self.assertIsNone(pjlink.sw_version_received, 'Received software version should not have changed') self.assertIsNone(pjlink.sw_version_received, 'Received software version should not have changed')
mock_log.warn.assert_called_once_with(test_log) mock_log.warning.assert_called_once_with(test_log)
def test_projector_reset_information(self): def test_projector_reset_information(self):
""" """