Cleanups and assert updates

This commit is contained in:
Ken Roberts 2017-12-25 20:14:39 -08:00
parent 598a373929
commit 33da95371f
4 changed files with 50 additions and 55 deletions

View File

@ -557,7 +557,3 @@ for source in PJLINK_DEFAULT_SOURCES:
label = "{source}{item}".format(source=source, item=item) label = "{source}{item}".format(source=source, item=item)
PJLINK_DEFAULT_CODES[label] = "{source} {item}".format(source=PJLINK_DEFAULT_SOURCES[source], PJLINK_DEFAULT_CODES[label] = "{source} {item}".format(source=PJLINK_DEFAULT_SOURCES[source],
item=PJLINK_DEFAULT_ITEMS[item]) item=PJLINK_DEFAULT_ITEMS[item])
# Remove temp variables so they don't become part of the module dict
del(source)
del(item)
del(label)

View File

@ -801,7 +801,7 @@ class PJLink(QtNetwork.QTcpSocket, PJLinkCommands):
data = decode(read, 'utf-8') data = decode(read, 'utf-8')
# Possibility of extraneous data on input when reading. # Possibility of extraneous data on input when reading.
# Clean out extraneous characters in buffer. # Clean out extraneous characters in buffer.
self.read(2048) self.read(1024)
log.debug('({ip}) check_login() read "{data}"'.format(ip=self.ip, data=data.strip())) log.debug('({ip}) check_login() read "{data}"'.format(ip=self.ip, data=data.strip()))
# At this point, we should only have the initial login prompt with # At this point, we should only have the initial login prompt with
# possible authentication # possible authentication

View File

@ -60,8 +60,8 @@ class TestPJLinkRouting(TestCase):
# THEN: Appropriate log entries should have been made and methods called/not called # THEN: Appropriate log entries should have been made and methods called/not called
mock_log.debug.assert_has_calls(log_debug_text) mock_log.debug.assert_has_calls(log_debug_text)
mock_log.warning.assert_has_calls(log_warning_text) mock_log.warning.assert_has_calls(log_warning_text)
self.assertFalse(pjlink.pjlink_functions.called, 'Should not have accessed pjlink_functions') assert pjlink.pjlink_functions.called is False, 'Should not have accessed pjlink_functions'
self.assertTrue(mock_buffer.called, 'Should have called _trash_buffer') assert mock_buffer.called is True, 'Should have called _trash_buffer'
def test_process_command_call_clss(self): def test_process_command_call_clss(self):
""" """
@ -103,9 +103,9 @@ class TestPJLinkRouting(TestCase):
pjlink.process_command(cmd='PJLINK', data=PJLINK_ERRORS[E_AUTHENTICATION]) pjlink.process_command(cmd='PJLINK', data=PJLINK_ERRORS[E_AUTHENTICATION])
# THEN: Appropriate log entries should have been made and methods called/not called # THEN: Appropriate log entries should have been made and methods called/not called
assert mock_disconnect.called is True, 'disconnect_from_host should have been called'
mock_log.error.assert_has_calls(log_error_calls) mock_log.error.assert_has_calls(log_error_calls)
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
self.assertTrue(mock_disconnect.called, 'disconnect_from_host should have been called')
mock_change_status.assert_called_once_with(status=E_AUTHENTICATION) mock_change_status.assert_called_once_with(status=E_AUTHENTICATION)
mock_authentication.emit.assert_called_once_with(pjlink.name) mock_authentication.emit.assert_called_once_with(pjlink.name)
mock_process_pjlink.assert_not_called() mock_process_pjlink.assert_not_called()
@ -218,8 +218,8 @@ class TestPJLinkRouting(TestCase):
# THEN: Appropriate log entries should have been made and methods called/not called # THEN: Appropriate log entries should have been made and methods called/not called
mock_log.debug.assert_has_calls(log_debug_text) mock_log.debug.assert_has_calls(log_debug_text)
mock_log.warning.assert_has_calls(log_warning_text) mock_log.warning.assert_has_calls(log_warning_text)
self.assertFalse(pjlink.pjlink_functions.called, 'Should not have accessed pjlink_functions') assert pjlink.pjlink_functions.called is False, 'Should not have accessed pjlink_functions'
self.assertFalse(mock_process_clss.called, 'Should not have called process_clss') assert mock_process_clss.called is False, 'Should not have called process_clss'
def test_process_command_ok(self): def test_process_command_ok(self):
""" """

View File

@ -71,10 +71,9 @@ class TestPJLinkCommands(TestCase):
# THEN: Proper settings should change and signals sent # THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed') assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
self.assertEqual(pjlink.status_connect, E_NOT_CONNECTED, assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED'
'Status connect should be NOT CONNECTED') assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
self.assertTrue(mock_UpdateIcons.emit.called, 'Should have called UpdateIcons')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR, mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]) STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])
@ -110,10 +109,10 @@ class TestPJLinkCommands(TestCase):
# THEN: Proper settings should change and signals sent # THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed')
self.assertEqual(pjlink.status_connect, S_CONNECTING, 'Status connect should be CONNECTING')
self.assertTrue(mock_UpdateIcons.emit.called, 'Should have called UpdateIcons')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING]) mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])
assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
assert pjlink.status_connect == S_CONNECTING, 'Status connect should be CONNECTING'
assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
def test_projector_change_status_connection_status_connected(self): def test_projector_change_status_connection_status_connected(self):
""" """
@ -146,9 +145,9 @@ class TestPJLinkCommands(TestCase):
# THEN: Proper settings should change and signals sent # THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed')
self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected') mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')
assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
def test_projector_change_status_connection_status_with_message(self): def test_projector_change_status_connection_status_with_message(self):
""" """
@ -178,9 +177,9 @@ class TestPJLinkCommands(TestCase):
# THEN: Proper settings should change and signals sent # THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON')
self.assertEqual(pjlink.status_connect, S_OK, 'Status connect should not have changed')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message) mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
assert pjlink.projector_status == S_ON, 'Projector status should be ON'
assert pjlink.status_connect == S_OK, 'Status connect should not have changed'
def test_projector_get_av_mute_status(self): def test_projector_get_av_mute_status(self):
""" """
@ -403,8 +402,8 @@ class TestPJLinkCommands(TestCase):
code, message = pjlink._get_status(status=test_string) code, message = pjlink._get_status(status=test_string)
# THEN: Proper data should have been returned # THEN: Proper data should have been returned
self.assertEqual(code, -1, 'Should have returned -1 as a bad status check') assert code == -1, 'Should have returned -1 as a bad status check'
self.assertIsNone(message, 'Invalid code type should have returned None for message') assert message is None, 'Invalid code type should have returned None for message'
def test_projector_get_status_valid(self): def test_projector_get_status_valid(self):
""" """
@ -418,8 +417,8 @@ class TestPJLinkCommands(TestCase):
code, message = pjlink._get_status(status=S_NOT_CONNECTED) code, message = pjlink._get_status(status=S_NOT_CONNECTED)
# THEN: Proper strings should have been returned # THEN: Proper strings should have been returned
self.assertEqual(code, 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent') assert code == 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent'
self.assertEqual(message, test_message, 'Description of code should have been returned') assert message == test_message, 'Description of code should have been returned'
def test_projector_get_status_unknown(self): def test_projector_get_status_unknown(self):
""" """
@ -432,8 +431,8 @@ class TestPJLinkCommands(TestCase):
code, message = pjlink._get_status(status=9999) code, message = pjlink._get_status(status=9999)
# THEN: Proper strings should have been returned # THEN: Proper strings should have been returned
self.assertIsNone(code, 'Code returned should have been the same code that was sent') assert code is None, 'Code returned should have been the same code that was sent'
self.assertIsNone(message, 'Should have returned None as message') assert message is None, 'Should have returned None as message'
def test_projector_process_inf1(self): def test_projector_process_inf1(self):
""" """
@ -449,7 +448,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_inf1(data=test_data) pjlink.process_inf1(data=test_data)
# THEN: Data should be saved # THEN: Data should be saved
self.assertEqual(pjlink.manufacturer, test_data, 'Test data should have been saved') assert pjlink.manufacturer == test_data, 'Test data should have been saved'
def test_projector_process_inf2(self): def test_projector_process_inf2(self):
""" """
@ -465,7 +464,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_inf2(data=test_data) pjlink.process_inf2(data=test_data)
# THEN: Data should be saved # THEN: Data should be saved
self.assertEqual(pjlink.model, test_data, 'Test data should have been saved') assert pjlink.model == test_data, 'Test data should have been saved'
def test_projector_process_info(self): def test_projector_process_info(self):
""" """
@ -481,7 +480,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_info(data=test_data) pjlink.process_info(data=test_data)
# THEN: Data should be saved # THEN: Data should be saved
self.assertEqual(pjlink.other_info, test_data, 'Test data should have been saved') assert pjlink.other_info == test_data, 'Test data should have been saved'
def test_projector_process_avmt_bad_data(self): def test_projector_process_avmt_bad_data(self):
""" """
@ -497,9 +496,9 @@ class TestPJLinkCommands(TestCase):
pjlink.process_avmt('36') pjlink.process_avmt('36')
# THEN: Shutter should be closed and mute should be True # THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should changed') assert pjlink.shutter is True, 'Shutter should changed'
self.assertTrue(pjlink.mute, 'Audio should not have changed') assert pjlink.mute is True, 'Audio should not have changed'
self.assertFalse(mock_UpdateIcons.emit.called, 'Update icons should NOT have been called') assert mock_UpdateIcons.emit.called is False, 'Update icons should NOT have been called'
def test_projector_process_avmt_closed_muted(self): def test_projector_process_avmt_closed_muted(self):
""" """
@ -515,9 +514,9 @@ class TestPJLinkCommands(TestCase):
pjlink.process_avmt('31') pjlink.process_avmt('31')
# THEN: Shutter should be closed and mute should be True # THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should have been set to closed') assert pjlink.shutter is True, 'Shutter should have been set to closed'
self.assertTrue(pjlink.mute, 'Audio should be muted') assert pjlink.mute is True, 'Audio should be muted'
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called') assert mock_UpdateIcons.emit.called is True, 'Update icons should have been called'
def test_projector_process_avmt_shutter_closed(self): def test_projector_process_avmt_shutter_closed(self):
""" """
@ -533,9 +532,9 @@ class TestPJLinkCommands(TestCase):
pjlink.process_avmt('11') pjlink.process_avmt('11')
# THEN: Shutter should be True and mute should be False # THEN: Shutter should be True and mute should be False
self.assertTrue(pjlink.shutter, 'Shutter should have been set to closed') assert pjlink.shutter is True, 'Shutter should have been set to closed'
self.assertTrue(pjlink.mute, 'Audio should not have changed') assert pjlink.mute is True, 'Audio should not have changed'
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called') assert mock_UpdateIcons.emit.called is True, 'Update icons should have been called'
def test_projector_process_avmt_audio_muted(self): def test_projector_process_avmt_audio_muted(self):
""" """
@ -551,9 +550,9 @@ class TestPJLinkCommands(TestCase):
pjlink.process_avmt('21') pjlink.process_avmt('21')
# THEN: Shutter should be closed and mute should be True # THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should not have changed') assert pjlink.shutter is True, 'Shutter should not have changed'
self.assertTrue(pjlink.mute, 'Audio should be off') assert pjlink.mute is True, 'Audio should be off'
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called') assert mock_UpdateIcons.emit.called is True, 'Update icons should have been called'
def test_projector_process_avmt_open_unmuted(self): def test_projector_process_avmt_open_unmuted(self):
""" """
@ -569,9 +568,9 @@ class TestPJLinkCommands(TestCase):
pjlink.process_avmt('30') pjlink.process_avmt('30')
# THEN: Shutter should be closed and mute should be True # THEN: Shutter should be closed and mute should be True
self.assertFalse(pjlink.shutter, 'Shutter should have been set to open') assert pjlink.shutter is False, 'Shutter should have been set to open'
self.assertFalse(pjlink.mute, 'Audio should be on') assert pjlink.mute is False, 'Audio should be on'
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called') assert mock_UpdateIcons.emit.called is True, 'Update icons should have been called'
def test_projector_process_clss_one(self): def test_projector_process_clss_one(self):
""" """
@ -584,7 +583,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_clss('1') pjlink.process_clss('1')
# THEN: Projector class should be set to 1 # THEN: Projector class should be set to 1
self.assertEqual(pjlink.pjlink_class, '1', 'Projector should have set class=1') assert pjlink.pjlink_class == '1', 'Projector should have set class=1'
def test_projector_process_clss_two(self): def test_projector_process_clss_two(self):
""" """
@ -597,7 +596,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_clss('2') pjlink.process_clss('2')
# THEN: Projector class should be set to 1 # THEN: Projector class should be set to 1
self.assertEqual(pjlink.pjlink_class, '2', 'Projector should have set class=2') assert pjlink.pjlink_class == '2', 'Projector should have set class=2'
def test_projector_process_clss_invalid_nan(self): def test_projector_process_clss_invalid_nan(self):
""" """
@ -616,7 +615,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_clss('Z') pjlink.process_clss('Z')
# THEN: Projector class should be set with default value # THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', 'Invalid NaN class reply should have set class=1') assert pjlink.pjlink_class == '1', 'Invalid NaN class reply should have set class=1'
mock_log.error.assert_has_calls(log_error_calls) mock_log.error.assert_has_calls(log_error_calls)
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
@ -638,7 +637,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_clss('Invalid') pjlink.process_clss('Invalid')
# THEN: Projector class should be set with default value # THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', 'Invalid class reply should have set class=1') assert pjlink.pjlink_class == '1', 'Invalid class reply should have set class=1'
mock_log.error.assert_has_calls(log_error_calls) mock_log.error.assert_has_calls(log_error_calls)
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
@ -655,7 +654,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_erst(chk_data) pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should be None # THEN: PJLink instance errors should be None
self.assertIsNone(pjlink.projector_errors, 'projector_errors should have been set to None') assert pjlink.projector_errors is None, 'projector_errors should have been set to None'
def test_projector_process_erst_data_invalid_length(self): def test_projector_process_erst_data_invalid_length(self):
""" """
@ -676,7 +675,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_erst(chk_data) pjlink.process_erst(chk_data)
# 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') assert pjlink.projector_errors is None, 'There should be no errors'
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
mock_log.warning.assert_has_calls(log_warn_calls) mock_log.warning.assert_has_calls(log_warn_calls)
@ -698,7 +697,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_erst(chk_data) pjlink.process_erst(chk_data)
# 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') assert pjlink.projector_errors is None, 'There should be no errors'
mock_log.debug.assert_has_calls(log_debug_calls) mock_log.debug.assert_has_calls(log_debug_calls)
mock_log.warning.assert_has_calls(log_warn_calls) mock_log.warning.assert_has_calls(log_warn_calls)
@ -727,7 +726,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_erst(chk_data) pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should match chk_value # THEN: PJLink instance errors should match chk_value
self.assertEqual(pjlink.projector_errors, chk_test, 'Projector errors should be all E_WARN') assert pjlink.projector_errors == chk_test, 'Projector errors should be all E_WARN'
def test_projector_process_erst_all_error(self): def test_projector_process_erst_all_error(self):
""" """
@ -754,7 +753,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_erst(chk_data) pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should match chk_value # THEN: PJLink instance errors should match chk_value
self.assertEqual(pjlink.projector_errors, chk_test, 'Projector errors should be all E_ERROR') assert pjlink.projector_errors == chk_test, 'Projector errors should be all E_ERROR'
def test_projector_process_erst_warn_cover_only(self): def test_projector_process_erst_warn_cover_only(self):
""" """
@ -1042,7 +1041,7 @@ class TestPJLinkCommands(TestCase):
pjlink.process_rlmp(data=lamp_model) pjlink.process_rlmp(data=lamp_model)
# THEN: Filter model number should be saved # THEN: Filter model number should be saved
self.assertEqual(pjlink.model_lamp, lamp_model, 'Lamp type should have been saved') assert pjlink.model_lamp == lamp_model, 'Lamp type should have been saved'
def test_projector_process_rlmp_nosave(self): def test_projector_process_rlmp_nosave(self):
""" """