Fix for fortyfour #44

pull/45/head
Konstantin Gründger 2017-12-13 19:08:57 +01:00
rodzic 7d738931e2
commit c2b82817c7
3 zmienionych plików z 31 dodań i 0 usunięć

Wyświetl plik

@ -1,5 +1,8 @@
# CHANGELOG
## Unreleased
- client: Ignore messages other than UTF-8
## 0.8.0 - 2017-10-02
- parser: Merged function 'parse_aprs' and 'parse_ogn_beacon' to 'parse'
- parser: Added support for OGNSDR (receiver), OGNTRK (ogn tracker), OGNFLR (flarm) and OGNAV (Naviter) beacons

Wyświetl plik

@ -76,6 +76,8 @@ class AprsClient:
self.logger.error('BrokenPipeError', exc_info=True)
except socket.error:
self.logger.error('socket.error', exc_info=True)
except UnicodeDecodeError:
self.logger.error('UnicodeDecodeError', exc_info=True)
if autoreconnect and not self._kill:
self.connect()

Wyświetl plik

@ -44,6 +44,32 @@ class AprsClientTest(unittest.TestCase):
client.sock.close.assert_called_once_with()
self.assertTrue(client._kill)
@mock.patch('ogn.client.client.socket')
def test_run(self, mock_socket):
import socket
mock_socket.error = socket.error
client = AprsClient(aprs_user='testuser', aprs_filter='')
client.connect()
client.sock_file.readline = mock.MagicMock()
client.sock_file.readline.side_effect = ['Normal text blabla',
'my weird character ¥',
UnicodeDecodeError('funnycodec', b'\x00\x00', 1, 2, 'This is just a fake reason!'),
'... show must go on',
BrokenPipeError(),
'... and on',
socket.error(),
'... and on',
KeyboardInterrupt()]
try:
client.run(callback=lambda msg: print("got: {}".format(msg)), autoreconnect=True)
except KeyboardInterrupt:
pass
finally:
client.disconnect()
def test_reset_kill_reconnect(self):
client = AprsClient(aprs_user='testuser', aprs_filter='')
client.connect()