first part of tests for parsing submodule
This commit is contained in:
parent
9fa62c433a
commit
a0b59eeaf7
|
|
@ -25,7 +25,7 @@ import logging
|
|||
import sys
|
||||
|
||||
from . import __version__
|
||||
from .parse import parse
|
||||
from .parsing import parse
|
||||
from .exceptions import (
|
||||
GenericError,
|
||||
ConnectionDrop,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ __author__ = "Rossen Georgiev"
|
|||
__all__ = ['IS', 'parse', 'passcode']
|
||||
|
||||
from .exceptions import *
|
||||
from .parse import parse
|
||||
from .parsing import parse
|
||||
from .passcode import passcode
|
||||
|
||||
from .IS import IS
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ except ImportError:
|
|||
def detect(x):
|
||||
return {'confidence': 0.0, 'encoding': 'windows-1252'}
|
||||
|
||||
from .exceptions import (UnknownFormat, ParseError)
|
||||
from . import base91
|
||||
from exceptions import (UnknownFormat, ParseError)
|
||||
import base91
|
||||
|
||||
__all__ = ['parse']
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ def parse(packet):
|
|||
# typical packet format
|
||||
#
|
||||
# CALL1>CALL2,CALL3,CALL4:>longtext......
|
||||
# |--------header--------|-----body-------|
|
||||
# |--------header---------|-----body------|
|
||||
#
|
||||
try:
|
||||
(head, body) = packet.split(':', 1)
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
# encoding: utf-8
|
||||
|
||||
import unittest
|
||||
import mox
|
||||
|
||||
from aprslib.parse import parse
|
||||
from aprslib import parse
|
||||
from aprslib import parsing
|
||||
from aprslib.exceptions import ParseError, UnknownFormat
|
||||
|
||||
|
||||
class ParseTestCase(unittest.TestCase):
|
||||
|
|
@ -31,6 +34,78 @@ class ParseTestCase(unittest.TestCase):
|
|||
self.assertIsInstance(result['status'], unicode)
|
||||
self.assertEqual(result['status'], u"статус")
|
||||
|
||||
def test_empty_packet(self):
|
||||
self.assertRaises(ParseError, parse, "")
|
||||
|
||||
def test_no_body(self):
|
||||
self.assertRaises(ParseError, parse, "A>B")
|
||||
|
||||
def test_empty_body(self):
|
||||
self.assertRaises(ParseError, parse, "A>B:")
|
||||
|
||||
def test_parse_header_exception(self):
|
||||
self.assertRaises(ParseError, parse, "A:asd")
|
||||
|
||||
def test_empty_body_of_format_that_is_not_status(self):
|
||||
self.assertRaises(ParseError, parse, "A>B:!")
|
||||
|
||||
try:
|
||||
parse("A>B:>")
|
||||
except:
|
||||
self.fail("empty status packed shouldn't raise exception")
|
||||
|
||||
def test_unsupported_formats_raising(self):
|
||||
with self.assertRaises(UnknownFormat):
|
||||
for packet_type in '#$%)*,<?T[_{}':
|
||||
parse("A>B:%saaa" % packet_type)
|
||||
|
||||
|
||||
class ParseBranchesTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.m = mox.Mox()
|
||||
|
||||
def tearDown(self):
|
||||
self.m.UnsetStubs()
|
||||
|
||||
def test_status_format_branch(self):
|
||||
self.m.StubOutWithMock(parsing, "_parse_timestamp")
|
||||
parsing._parse_timestamp(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(("test", {}))
|
||||
self.m.ReplayAll()
|
||||
|
||||
expected = {
|
||||
'status': 'test',
|
||||
'raw': u'A>B:>test',
|
||||
'via': '',
|
||||
'from': u'A',
|
||||
'to': u'B',
|
||||
'path': [],
|
||||
'format': 'status'
|
||||
}
|
||||
result = parse("A>B:>test")
|
||||
|
||||
self.assertEqual(result, expected)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_mice_format_branch(self):
|
||||
self.m.StubOutWithMock(parsing, "_parse_mice")
|
||||
parsing._parse_mice("B","test").AndReturn(('', {'format':''}))
|
||||
parsing._parse_mice("D","test").AndReturn(('', {'format':''}))
|
||||
self.m.ReplayAll()
|
||||
|
||||
parse("A>B:`test")
|
||||
parse("C>D:'test")
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_message_format_branch(self):
|
||||
self.m.StubOutWithMock(parsing, "_parse_message")
|
||||
parsing._parse_message("test").AndReturn(('', {'format':''}))
|
||||
self.m.ReplayAll()
|
||||
|
||||
parse("A>B::test")
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from aprslib.parse import _parse_comment_telemetry
|
||||
from aprslib.parsing import _parse_comment_telemetry
|
||||
from aprslib import base91
|
||||
from random import randint
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import unittest
|
|||
import string
|
||||
from random import randint, randrange, sample
|
||||
|
||||
from aprslib.parse import _parse_header
|
||||
from aprslib.parse import _validate_callsign
|
||||
from aprslib.parsing import _parse_header
|
||||
from aprslib.parsing import _validate_callsign
|
||||
from aprslib.exceptions import ParseError
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue