remove OgnParseError

master
Konstantin Gründger 2025-05-21 15:04:40 +02:00
rodzic ef25a71a7d
commit ab45567015
7 zmienionych plików z 13 dodań i 35 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
## 2.0.0: unreleased
- parser: use rust parser as default
- parser: removed OgnParseError since only invalid APRS don't pass the parser
## 1.3.3: - 2025-05-21
- parser: use rust parser with option "use_rust_parser=True" (default for v2.0.0)

Wyświetl plik

@ -31,16 +31,14 @@ beacon = parse("FLRDDDEAD>APRS,qAS,EDER:/114500h5029.86N/00956.98E'342/049/A=005
```python
from ogn.client import AprsClient
from ogn.parser import parse, ParseError
from ogn.parser import parse, AprsParseError
def process_beacon(raw_message):
try:
beacon = parse(raw_message)
print('Received {aprs_type}: {raw_message}'.format(**beacon))
except ParseError as e:
except AprsParseError as e:
print('Error, {}'.format(e.message))
except NotImplementedError as e:
print('{}: {}'.format(e, raw_message))
client = AprsClient(aprs_user='N0CALL')
client.connect()

Wyświetl plik

@ -1,3 +1,3 @@
from ogn.parser import parse as parse_module # noqa: F40 --- only for test functions. Without this a mock of parse would mock the function instead of the module
from ogn.parser.parse import parse # noqa: F401
from ogn.parser.exceptions import ParseError, AprsParseError, OgnParseError # noqa: F401
from ogn.parser.exceptions import AprsParseError # noqa: F401

Wyświetl plik

@ -3,23 +3,9 @@ exception definitions
"""
class ParseError(Exception):
pass
class AprsParseError(ParseError):
class AprsParseError(Exception):
"""Parse error while parsing an aprs packet."""
def __init__(self, aprs_string):
self.aprs_string = aprs_string
self.message = f"This is not a valid APRS packet: {aprs_string}"
super(AprsParseError, self).__init__(self.message)
class OgnParseError(ParseError):
"""Parse error while parsing an ogn message from aprs comment."""
def __init__(self, aprs_comment):
self.aprs_comment = aprs_comment
self.message = f"This is not a valid OGN message: {aprs_comment}"
super(OgnParseError, self).__init__(self.message)

Wyświetl plik

@ -134,12 +134,8 @@ def test_50_live_messages():
global remaining_messages
if raw_message[0] == '#':
return
try:
message = parse(raw_message)
print(f"{message['aprs_type']}: {raw_message}")
except NotImplementedError as e:
print(f"{e}: {raw_message}")
return
message = parse(raw_message)
print(f"{message['aprs_type']}: {raw_message}")
if remaining_messages > 0:
remaining_messages -= 1
else:

Wyświetl plik

@ -15,13 +15,10 @@ def _parse_valid_beacon_data_file(filename, beacon_type):
if line.strip() == '':
continue
try:
message = parse(line, datetime(2015, 4, 10, 17, 0))
assert message is not None
if message['aprs_type'] == 'position' or message['aprs_type'] == 'status':
assert message['beacon_type'] == beacon_type
except NotImplementedError as e:
print(e)
message = parse(line, datetime(2015, 4, 10, 17, 0))
assert message is not None
if message['aprs_type'] == 'position' or message['aprs_type'] == 'status':
assert message['beacon_type'] == beacon_type
def test_flyxc_beacons():

Wyświetl plik

@ -4,12 +4,12 @@ import pytest
from datetime import datetime
from ogn.parser.telnet_parser import parse
from ogn.parser.exceptions import ParseError
from ogn.parser.exceptions import AprsParseError
@pytest.mark.skip("Not yet implemented")
def test_telnet_fail_corrupt():
with pytest.raises(ParseError):
with pytest.raises(AprsParseError):
parse('This is rubbish')