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
return
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
elif _data in PJLINK_ERRORS:
# Oops - projector error
@ -231,7 +231,7 @@ class PJLinkCommands(object):
# : Received: '%1CLSS=Class 1' (Optoma)
# : Received: '%1CLSS=Version1' (BenQ)
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),
# 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.
@ -261,15 +261,15 @@ class PJLinkCommands(object):
"""
if len(data) != 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,
data=data,
count=count))
log.warning("{ip}) Invalid error status response '{data}': length != {count}".format(ip=self.ip,
data=data,
count=count))
return
try:
datacheck = int(data)
except ValueError:
# 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
if datacheck == 0:
self.projector_errors = None
@ -429,9 +429,9 @@ class PJLinkCommands(object):
if self.model_filter is None:
self.model_filter = data
else:
log.warn("({ip}) Filter model already set".format(ip=self.ip))
log.warn("({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}) Filter model already set".format(ip=self.ip))
log.warning("({ip}) Saved model: '{old}'".format(ip=self.ip, old=self.model_filter))
log.warning("({ip}) New model: '{new}'".format(ip=self.ip, new=data))
def process_rlmp(self, data):
"""
@ -440,9 +440,9 @@ class PJLinkCommands(object):
if self.model_lamp is None:
self.model_lamp = data
else:
log.warn("({ip}) Lamp model already set".format(ip=self.ip))
log.warn("({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}) Lamp model already set".format(ip=self.ip))
log.warning("({ip}) Saved lamp: '{old}'".format(ip=self.ip, old=self.model_lamp))
log.warning("({ip}) New lamp: '{new}'".format(ip=self.ip, new=data))
def process_snum(self, data):
"""
@ -457,10 +457,10 @@ class PJLinkCommands(object):
else:
# Compare serial numbers and see if we got the same projector
if self.serial_no != data:
log.warn("({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.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data))
log.warn("({ip}) NOT saving serial number".format(ip=self.ip))
log.warning("({ip}) Projector serial number does not match saved serial number".format(ip=self.ip))
log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.serial_no))
log.warning("({ip}) Received: '{new}'".format(ip=self.ip, new=data))
log.warning("({ip}) NOT saving serial number".format(ip=self.ip))
self.serial_no_received = data
def process_sver(self, data):
@ -469,7 +469,7 @@ class PJLinkCommands(object):
"""
if len(data) > 32:
# Defined in specs max version is 32 characters
log.warn("Invalid software version - too long")
log.warning("Invalid software version - too long")
return
elif self.sw_version is None:
log.debug("({ip}) Setting projector software version to '{data}'".format(ip=self.ip, data=data))
@ -478,10 +478,11 @@ class PJLinkCommands(object):
else:
# Compare software version and see if we got the same projector
if self.serial_no != data:
log.warn("({ip}) Projector software version does not match saved software version".format(ip=self.ip))
log.warn("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version))
log.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data))
log.warn("({ip}) Saving new serial number as sw_version_received".format(ip=self.ip))
log.warning("({ip}) Projector software version does not match saved "
"software version".format(ip=self.ip))
log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version))
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
@ -609,7 +610,7 @@ class PJLink(PJLinkCommands, QtNetwork.QTcpSocket):
Normally called by timer().
"""
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
log.debug('({ip}) Updating projector status'.format(ip=self.ip))
# Reset timer in case we were called from a set command
@ -839,8 +840,8 @@ class PJLink(PJLinkCommands, QtNetwork.QTcpSocket):
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))
if int(self.pjlink_class) < int(version):
log.warn('({ip}) get_data(): Projector returned class reply higher '
'than projector stated class'.format(ip=self.ip))
log.warning('({ip}) get_data(): Projector returned class reply higher '
'than projector stated class'.format(ip=self.ip))
return self.process_command(cmd, data)
@QtCore.pyqtSlot(QtNetwork.QAbstractSocket.SocketError)

View File

@ -179,7 +179,7 @@ class TestPJLinkRouting(TestCase):
# THEN: Error should be logged and no command called
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(openlp.core.lib.projector.pjlink, 'log')

View File

@ -607,12 +607,12 @@ class TestPJLinkCommands(TestCase):
# WHEN: Process invalid reply
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
self.assertEqual(pjlink.pjlink_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')
def test_projector_process_clss_invalid_no_version(self, mock_log):
@ -624,12 +624,12 @@ class TestPJLinkCommands(TestCase):
# WHEN: Process invalid reply
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
self.assertEqual(pjlink.pjlink_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):
"""
@ -654,15 +654,15 @@ class TestPJLinkCommands(TestCase):
# GIVEN: Test object
pjlink = pjlink_test
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
pjlink.process_erst('11111111')
# THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
self.assertTrue(mock_log.warn.called, 'Warning should have been logged')
mock_log.warn.assert_called_once_with(log_warn_text)
self.assertTrue(mock_log.warning.called, 'Warning should have been logged')
mock_log.warning.assert_called_once_with(log_text)
@patch.object(openlp.core.lib.projector.pjlink, 'log')
def test_projector_process_erst_data_invalid_nan(self, mock_log):
@ -672,15 +672,15 @@ class TestPJLinkCommands(TestCase):
# GIVEN: Test object
pjlink = pjlink_test
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
pjlink.process_erst('1111Z1')
# THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
self.assertTrue(mock_log.warn.called, 'Warning should have been logged')
mock_log.warn.assert_called_once_with(log_warn_text)
self.assertTrue(mock_log.warning.called, 'Warning should have been logged')
mock_log.warning.assert_called_once_with(log_text)
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_received, test_data_new,
'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
mock_log.warn.assert_called_with(test_log)
mock_log.warning.assert_called_with(test_log)
@patch.object(openlp.core.lib.projector.pjlink, 'log')
def test_projector_process_sver_invalid(self, mock_log):
@ -1103,7 +1103,7 @@ class TestPJLinkCommands(TestCase):
# THEN: Version information should not change
self.assertIsNone(pjlink.sw_version, '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):
"""