| 1 |
|
| 2 |
"""Tests for ais.tag_block.""" |
| 3 |
|
| 4 |
import unittest |
| 5 |
|
| 6 |
from ais import tag_block |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
SINGLE_LINE_MESSAGES = r""" |
| 11 |
# pylint: disable=line-too-long |
| 12 |
\s:rORBCOMM000,q:u,c:1426032001,T:2015-03-11 00.00.01*58\!AIVDM,1,1,,B,19NWuDP0006D=1B<qOuGg6<00000,0*34 |
| 13 |
\s:rORBCOMM000,q:u,c:1426032499,T:2015-03-11 00.08.19*5c\!AIVDM,1,1,,A,232S8G0P01Q;WaHKSmBH;OvN0H9T,0*6A |
| 14 |
\s:rORBCOMM000,q:u,c:1426032001,T:2015-03-11 00.00.01*58\!AIVDM,1,1,,B,38v6Cl5000QDF;MdVMFLC9ol2Dcr,0*0A |
| 15 |
\n:3140,s:rZKYSAL1,c:1428451253*1C\!AIVDM,1,1,,A,15NNDKgP00Ic:00EB7v1JgwT0<0f,0*29 |
| 16 |
\n:486866,s:b003669710,c:1428451208*1D\!SAVDM,1,1,,A,23?v;T5000G?vCjE`Sk9>7H80<1D,0*1D |
| 17 |
\n:568297,s:b003669708,c:1428453854*10\!SAVDM,1,1,,B,23?v;T0003G?vC@E`SmMOWJD042h,0*08 |
| 18 |
\n:3909,s:r08ACERDC,c:1428451287*2D\!ANVDM,1,1,,B,35MvvTg00bqS@H4H0@p0APBl0CNu,0*29 |
| 19 |
\n:528300,s:b2003669981,c:1428451280*27\!SAVDM,1,1,,B,35NSG`gP@4qDjSlA@Lq6<Cbb013P,0*37 |
| 20 |
\n:460935,s:b003669987,c:1428451301*1A\!SAVDM,1,1,,A,4@3QiWAuu401Wo=vUTJE:KG00HGg,0*43 |
| 21 |
\n:812178,s:rB0003160047,c:1428451225*7C\!AIVDM,1,1,,A,73fD4l00h=vt,0*0F |
| 22 |
\n:532130,s:b2003669981,c:1428451453*25\!SAVDM,1,1,,A,:3TfS<1GRKkp,0*1C |
| 23 |
\n:910748,s:b003669955,c:1428453199*1A\!ABVDM,1,1,,A,;5MuRHQuu40QBIQSq6A<A>i00000,0*10 |
| 24 |
\n:14595,s:r17MANG1,c:1428452881*35\!AIVDM,1,1,,B,<kBrgmkB77?Q2?Av,0*35 |
| 25 |
\n:7263,s:r17MYAK1,c:1428452980*12\!AIVDM,1,1,,B,<=AufR?Ff=us2P,4*66 |
| 26 |
\n:14814,s:r17MANP1,c:1428453934*28\!AIVDM,1,1,,B,>UowsOwM70,4*53 |
| 27 |
\n:5412,s:r17MCRA1,c:1428453978*15\!AIVDM,1,1,,A,>vHB2oe?w3m=,0*77 |
| 28 |
\n:755467,s:b003669978,c:1428451310*15\!SAVDO,1,1,,A,?03OwnQGN=CHD00,2*7C |
| 29 |
\n:867562,s:b003669953,c:1428451312*14\!SAVDM,1,1,,A,?3S>Rb1GO4lPD00,2*1A |
| 30 |
\n:76351,s:b2003669705,c:1428451373*12\!BSVDM,1,1,,B,B5NED1P04uk3Pe6u5116KwqWkP06,0*1E |
| 31 |
\n:187203,s:b003669979,c:1428451371*1E\!SAVDM,1,1,,B,B52NRUP00>C>jc4>NkGQ3wqUoP06,0*49 |
| 32 |
\n:529629,s:b2003669981,c:1428451342*27\!SAVDM,1,1,,B,D03Ow3iehNfp00N01H0f9IH8v9H,2*1B |
| 33 |
\n:769973,s:b2003669950,c:1428451343*2C\!SAVDO,1,1,,B,D03OwPAehNfp00N01H8w6D0,2*0E |
| 34 |
\n:755872,s:b003669950,c:1428451343*11\!SAVDM,1,1,,B,D03OwPAehNfp00N01H8w6D0,2*0C |
| 35 |
\n:276125,s:b003669711,c:1428451243*14\!SAVDM,1,1,,A,ENkb9M940a24W3h97QUh61@41@@;WgTu:lmch00003vP000,2*01 |
| 36 |
\n:511516,s:b003669709,c:1428451243*1F\!SAVDM,1,1,,B,E>kb9HhaS@:9ah4W17bW2@HW@@@;VrJf:kprh00003vP100,2*7F |
| 37 |
\n:816206,s:rB0003160047,c:1428451611*71\!AIVDM,1,1,,A,F030owj2N2P6Ubib@=4q35b10000,0*58 |
| 38 |
\n:814241,s:rB0003160047,c:1428451423*73\!AIVDM,1,1,,B,Gh30ot3AVTjd6S:9U2h00000;00,2*0C |
| 39 |
\n:1723,s:rCUDJOE_01,c:1428451339*7B\!AIVDM,1,1,,A,H52OwN0HtthU<R10hD5=E8F2220,2*2A |
| 40 |
\n:186235,s:b003669979,c:1428451341*19\!SAVDM,1,1,,B,H5NIlU4U0000000G46jhpn108410,0*78 |
| 41 |
\s:rORBCOMM000,q:u,c:1426032579,T:2015-03-11 00.09.39*50\!AIVDM,1,1,,A,H3n6rc4TCBD5PRV<7@2000203330,0*18 |
| 42 |
\n:9194,s:r17MELF1,c:1428452339*03\!AIVDM,1,1,,A,Is17FMq42OpOKj0,2*05 |
| 43 |
\n:15342,s:r17MHAI1,c:1428453059*3C\!AIVDM,1,1,,B,JOisW0rQaOuVCl;OE0,4*59 |
| 44 |
\n:6000,s:r17MPIP1,c:1428453567*0A\!AIVDM,1,1,,A,JE`twenu>wrDpurS,0*6F |
| 45 |
\n:4923,s:r17MWAI1,c:1428453625*13\!AIVDM,1,1,,B,JioS<NKkB;7iw0,4*0C |
| 46 |
\n:773486,s:b2003669950,c:1428451549*2C\!SAVDM,1,1,,B,K8VSqb9LdU28WP7l,0*48 |
| 47 |
""" |
| 48 |
|
| 49 |
|
| 50 |
class TagTestCase(unittest.TestCase): |
| 51 |
|
| 52 |
def assertDictContainsSubset2(self, actual, expected): |
| 53 |
|
| 54 |
|
| 55 |
self.assertIsInstance(expected, dict) |
| 56 |
self.assertIsInstance(actual, dict) |
| 57 |
for key, value in expected.items(): |
| 58 |
self.assertEqual(actual[key], value) |
| 59 |
|
| 60 |
|
| 61 |
class TagBlockTest(TagTestCase): |
| 62 |
|
| 63 |
def testFractionalTime(self): |
| 64 |
|
| 65 |
line = '\\c:1425327399.*70\\' |
| 66 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 67 |
match['time'] = float(match['time']) |
| 68 |
match['time'] = int(match['time']) |
| 69 |
expected = {'time': 1425327399.0} |
| 70 |
self.assertDictContainsSubset2(match, expected) |
| 71 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 72 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 73 |
|
| 74 |
line = '\\c:1425327399.0*40\\' |
| 75 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 76 |
match['time'] = float(match['time']) |
| 77 |
expected = {'time': 1425327399.0} |
| 78 |
self.assertDictContainsSubset2(match, expected) |
| 79 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 80 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 81 |
|
| 82 |
def testShortSingleLine(self): |
| 83 |
line = (r'\n:121650,s:r17MHOP1,c:1425327399*1D\$' |
| 84 |
'ANZDA,201638.00,02,03,2015,00,00*77') |
| 85 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 86 |
match['line_num'] = int(match['line_num']) |
| 87 |
match['time'] = int(match['time']) |
| 88 |
expected = { |
| 89 |
'line_num': 121650, |
| 90 |
'metadata': 'n:121650,s:r17MHOP1,c:1425327399*1D', |
| 91 |
'payload': '$ANZDA,201638.00,02,03,2015,00,00*77', |
| 92 |
'rcvr': 'r17MHOP1', |
| 93 |
'tag_checksum': '1D', |
| 94 |
'time': 1425327399} |
| 95 |
self.assertDictContainsSubset2(match, expected) |
| 96 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 97 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 98 |
|
| 99 |
def testSingleLine(self): |
| 100 |
line = (r'\s:Station,d:somewhere,n:2,q:u,r:123,t:A string.,' |
| 101 |
r'c:1425168552,T:2015-03-01 00.09.12*3A\content') |
| 102 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 103 |
match['line_num'] = int(match['line_num']) |
| 104 |
match['rel_time'] = int(match['rel_time']) |
| 105 |
match['time'] = int(match['time']) |
| 106 |
expected = { |
| 107 |
'dest': 'somewhere', |
| 108 |
'group': None, |
| 109 |
'group_id': None, |
| 110 |
'line_num': 2, |
| 111 |
'payload': 'content', |
| 112 |
'quality': 'u', |
| 113 |
'rcvr': 'Station', |
| 114 |
'rel_time': 123, |
| 115 |
'sentence_num': None, |
| 116 |
'sentence_tot': None, |
| 117 |
'tag_checksum': '3A', |
| 118 |
'text': 'A string.', |
| 119 |
'text_date': '2015-03-01 00.09.12', |
| 120 |
'time': 1425168552} |
| 121 |
self.assertDictContainsSubset2(match, expected) |
| 122 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 123 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 124 |
|
| 125 |
def testFirstOfGroup(self): |
| 126 |
line = (r'\g:1-3-42349,n:111458,s:r003669945,c:1425327424*41\!' |
| 127 |
'AIVDM,2,1,5,A,ENk`sPa17ab7W@7@1T@6;Q@0h@@=MeR4<7rpH00003v,0*16') |
| 128 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 129 |
match['group_id'] = int(match['group_id']) |
| 130 |
match['line_num'] = int(match['line_num']) |
| 131 |
match['sentence_num'] = int(match['sentence_num']) |
| 132 |
match['sentence_tot'] = int(match['sentence_tot']) |
| 133 |
match['time'] = int(match['time']) |
| 134 |
expected = { |
| 135 |
'group': '1-3-42349', |
| 136 |
'group_id': 42349, |
| 137 |
'line_num': 111458, |
| 138 |
'metadata': 'g:1-3-42349,n:111458,s:r003669945,c:1425327424*41', |
| 139 |
'payload': |
| 140 |
'!AIVDM,2,1,5,A,ENk`sPa17ab7W@7@1T@6;Q@0h@@=MeR4<7rpH00003v,0*16', |
| 141 |
'rcvr': 'r003669945', |
| 142 |
'sentence_num': 1, |
| 143 |
'sentence_tot': 3, |
| 144 |
'tag_checksum': '41', |
| 145 |
'time': 1425327424} |
| 146 |
self.assertDictContainsSubset2(match, expected) |
| 147 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 148 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 149 |
|
| 150 |
def testMiddleOfGroup(self): |
| 151 |
line = (r'\g:2-3-42349,n:111459*15\!AIVDM,2,2,5,A,P000,2*71') |
| 152 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 153 |
match['group_id'] = int(match['group_id']) |
| 154 |
match['line_num'] = int(match['line_num']) |
| 155 |
match['sentence_num'] = int(match['sentence_num']) |
| 156 |
match['sentence_tot'] = int(match['sentence_tot']) |
| 157 |
expected = { |
| 158 |
'group': '2-3-42349', |
| 159 |
'group_id': 42349, |
| 160 |
'line_num': 111459, |
| 161 |
'metadata': 'g:2-3-42349,n:111459*15', |
| 162 |
'payload': '!AIVDM,2,2,5,A,P000,2*71', |
| 163 |
'sentence_num': 2, |
| 164 |
'sentence_tot': 3, |
| 165 |
'tag_checksum': '15'} |
| 166 |
self.assertDictContainsSubset2(match, expected) |
| 167 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 168 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 169 |
|
| 170 |
def testEndOfGroup(self): |
| 171 |
line = (r'\g:3-3-42349,n:111460*1E\$' |
| 172 |
'ARVSI,r003669945,5,201704.05687473,0152,-085,0*2E') |
| 173 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 174 |
match['group_id'] = int(match['group_id']) |
| 175 |
match['line_num'] = int(match['line_num']) |
| 176 |
match['sentence_num'] = int(match['sentence_num']) |
| 177 |
match['sentence_tot'] = int(match['sentence_tot']) |
| 178 |
expected = { |
| 179 |
'group': '3-3-42349', |
| 180 |
'group_id': 42349, |
| 181 |
'line_num': 111460, |
| 182 |
'metadata': 'g:3-3-42349,n:111460*1E', |
| 183 |
'payload': '$ARVSI,r003669945,5,201704.05687473,0152,-085,0*2E', |
| 184 |
'sentence_num': 3, |
| 185 |
'sentence_tot': 3, |
| 186 |
'tag_checksum': '1E'} |
| 187 |
self.assertDictContainsSubset2(match, expected) |
| 188 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 189 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 190 |
|
| 191 |
def testOrbcommFieldT(self): |
| 192 |
line = (r'\s:rORBCOMM999,q:u,c:1424995200,T:2015-02-27 00.00.00*51\!' |
| 193 |
'AIVDM,1,1,,A,14VIk0002sMM04vE>V9jGimn08RP,0*0D') |
| 194 |
match = tag_block.TAG_BLOCK_RE.match(line).groupdict() |
| 195 |
match['time'] = int(match['time']) |
| 196 |
expected = { |
| 197 |
'metadata': 's:rORBCOMM999,q:u,c:1424995200,T:2015-02-27 00.00.00*51', |
| 198 |
'payload': '!AIVDM,1,1,,A,14VIk0002sMM04vE>V9jGimn08RP,0*0D', |
| 199 |
'quality': 'u', |
| 200 |
'rcvr': 'rORBCOMM999', |
| 201 |
'tag_checksum': '51', |
| 202 |
'text_date': '2015-02-27 00.00.00', |
| 203 |
'time': 1424995200} |
| 204 |
self.assertDictContainsSubset2(match, expected) |
| 205 |
self.assertDictContainsSubset2(tag_block.Parse(match), expected) |
| 206 |
self.assertDictContainsSubset2(tag_block.Parse(line), expected) |
| 207 |
|
| 208 |
|
| 209 |
class TagQueueTestSingleLines(TagTestCase): |
| 210 |
|
| 211 |
def testNonTagBlockLines(self): |
| 212 |
queue = tag_block.TagQueue() |
| 213 |
queue.put('1') |
| 214 |
self.assertEqual(queue.qsize(), 1) |
| 215 |
queue.put('2') |
| 216 |
self.assertEqual(queue.qsize(), 2) |
| 217 |
self.assertEqual(queue.get(), { |
| 218 |
'line_nums': [1], |
| 219 |
'lines': ['1'], |
| 220 |
}) |
| 221 |
self.assertEqual(queue.qsize(), 1) |
| 222 |
self.assertEqual(queue.get(), { |
| 223 |
'line_nums': [2], |
| 224 |
'lines': ['2'], |
| 225 |
}) |
| 226 |
self.assertEqual(queue.qsize(), 0) |
| 227 |
queue.put('3') |
| 228 |
self.assertEqual(queue.get(), { |
| 229 |
'line_nums': [3], |
| 230 |
'lines': ['3'], |
| 231 |
}) |
| 232 |
|
| 233 |
def testMultipleTagLines(self): |
| 234 |
queue = tag_block.TagQueue() |
| 235 |
queue.put(r'\s:station1,c:1425344187*78\a') |
| 236 |
queue.put(r'\s:spacecraft2,c:1425344304*0E\b') |
| 237 |
queue.put(r'\c:1425344187,s:station1*78\c') |
| 238 |
|
| 239 |
self.assertEqual(queue.qsize(), 3) |
| 240 |
|
| 241 |
item = queue.get() |
| 242 |
self.assertDictContainsSubset2(item, { |
| 243 |
'line_nums': [1], |
| 244 |
'lines': ['\\s:station1,c:1425344187*78\\a'], |
| 245 |
'times': [1425344187]}) |
| 246 |
expected_match = { |
| 247 |
'group': None, |
| 248 |
'group_id': None, |
| 249 |
'metadata': 's:station1,c:1425344187*78', |
| 250 |
'payload': 'a', |
| 251 |
'rcvr': 'station1', |
| 252 |
'tag_checksum': '78', |
| 253 |
'time': 1425344187} |
| 254 |
self.assertDictContainsSubset2(item['matches'][0], expected_match) |
| 255 |
|
| 256 |
item = queue.get() |
| 257 |
self.assertDictContainsSubset2(item, { |
| 258 |
'line_nums': [2], |
| 259 |
'lines': ['\\s:spacecraft2,c:1425344304*0E\\b'], |
| 260 |
'times': [1425344304]}) |
| 261 |
expected_match = { |
| 262 |
'group': None, |
| 263 |
'group_id': None, |
| 264 |
'metadata': 's:spacecraft2,c:1425344304*0E', |
| 265 |
'payload': 'b', |
| 266 |
'rcvr': 'spacecraft2', |
| 267 |
'tag_checksum': '0E', |
| 268 |
'time': 1425344304} |
| 269 |
self.assertDictContainsSubset2(item['matches'][0], expected_match) |
| 270 |
|
| 271 |
item = queue.get() |
| 272 |
self.assertDictContainsSubset2(item, { |
| 273 |
'line_nums': [3], |
| 274 |
'lines': ['\\c:1425344187,s:station1*78\\c'], |
| 275 |
'times': [1425344187]}) |
| 276 |
expected_match = { |
| 277 |
'group': None, |
| 278 |
'group_id': None, |
| 279 |
'metadata': 'c:1425344187,s:station1*78', |
| 280 |
'rcvr': 'station1', |
| 281 |
'tag_checksum': '78', |
| 282 |
'time': 1425344187} |
| 283 |
self.assertDictContainsSubset2(item['matches'][0], expected_match) |
| 284 |
|
| 285 |
|
| 286 |
class TagQueueGroupsTest(TagTestCase): |
| 287 |
|
| 288 |
def testTwoLines(self): |
| 289 |
lines = (r'\s:rcvr42,g:1-2-13*2A\abc', r'\g:2-2-13*5F\def') |
| 290 |
queue = tag_block.TagQueue() |
| 291 |
queue.put(lines[0]) |
| 292 |
self.assertEqual(queue.qsize(), 0) |
| 293 |
|
| 294 |
queue.put(lines[1]) |
| 295 |
self.assertEqual(queue.qsize(), 1) |
| 296 |
|
| 297 |
def testMissingFirst(self): |
| 298 |
queue = tag_block.TagQueue() |
| 299 |
|
| 300 |
queue.put(r'\g:2-2-13*5F\def') |
| 301 |
self.assertEqual(queue.qsize(), 0) |
| 302 |
self.assertEqual(len(queue.groups), 0) |
| 303 |
|
| 304 |
|
| 305 |
class DecodeTagBlockTest(TagTestCase): |
| 306 |
|
| 307 |
def testSingleLineMessage(self): |
| 308 |
|
| 309 |
expected = { |
| 310 |
'decoded': { |
| 311 |
'cog': 142, |
| 312 |
'gnss': True, |
| 313 |
'id': 27, |
| 314 |
'md5': 'fb6a0946b7dc8a6a4f5d06db113793d5', |
| 315 |
'mmsi': 577305000, |
| 316 |
'nav_status': 5, |
| 317 |
'position_accuracy': 1, |
| 318 |
'raim': False, |
| 319 |
'repeat_indicator': 0, |
| 320 |
'sog': 0, |
| 321 |
'spare': 0, |
| 322 |
'x': -90.20666666666666, |
| 323 |
'y': 29.145}, |
| 324 |
'line_nums': [1], |
| 325 |
|
| 326 |
'lines': ['\\n:852057,s:b003669955,c:1428451729*1B\\!ABVDM,1,1,,A,K8VSqb9LdU28WP8p,0*49'], |
| 327 |
'matches': [{ |
| 328 |
'dest': None, |
| 329 |
'group': None, |
| 330 |
'group_id': None, |
| 331 |
'line_num': 852057, |
| 332 |
'metadata': 'n:852057,s:b003669955,c:1428451729*1B', |
| 333 |
'payload': '!ABVDM,1,1,,A,K8VSqb9LdU28WP8p,0*49', |
| 334 |
'quality': None, |
| 335 |
'rcvr': 'b003669955', |
| 336 |
'rel_time': None, |
| 337 |
'sentence_num': None, |
| 338 |
'sentence_tot': None, |
| 339 |
'tag_checksum': '1B', |
| 340 |
'text': None, |
| 341 |
'text_date': None, |
| 342 |
'time': 1428451729}], |
| 343 |
'times': [1428451729]} |
| 344 |
|
| 345 |
line = ( |
| 346 |
|
| 347 |
r'\n:852057,s:b003669955,c:1428451729*1B\!ABVDM,1,1,,A,K8VSqb9LdU28WP8p,0*49' |
| 348 |
) |
| 349 |
|
| 350 |
queue = tag_block.TagQueue() |
| 351 |
queue.put(line) |
| 352 |
self.assertEqual(queue.qsize(), 1) |
| 353 |
msg = queue.get(line) |
| 354 |
self.assertEqual(msg, expected) |
| 355 |
|
| 356 |
def testManySingleLineMessages(self): |
| 357 |
lines = [line for line in SINGLE_LINE_MESSAGES.split('\n') if 'VD' in line] |
| 358 |
queue = tag_block.TagQueue() |
| 359 |
for line in lines: |
| 360 |
queue.put(line) |
| 361 |
self.assertEqual(queue.qsize(), len(lines)) |
| 362 |
msgs = [] |
| 363 |
while not queue.empty(): |
| 364 |
msgs.append(queue.get()) |
| 365 |
self.assertEqual(len(msgs), len(lines)) |
| 366 |
for msg in msgs: |
| 367 |
self.assertIn('decoded', msg) |
| 368 |
id_list = [msg['decoded']['id'] for msg in msgs] |
| 369 |
self.assertEqual( |
| 370 |
id_list, |
| 371 |
[ |
| 372 |
1, 2, 3, 1, 2, 2, 3, 3, 4, 7, 10, 11, 12, 12, 14, 14, 15, 15, 18, |
| 373 |
18, 20, 20, 20, 21, 21, 22, 23, 24, 24, 24, 25, 26, 26, 26, 27 |
| 374 |
]) |
| 375 |
|
| 376 |
def testTwoLineGroupWithSingleLineMessage(self): |
| 377 |
|
| 378 |
lines = ( |
| 379 |
|
| 380 |
r'\g:1-2-89372,n:192113,s:r003669946,c:1428451252*41\!AIVDM,1,1,,A,181520h000JstMLHbOFc1CUd0<07,0*35', |
| 381 |
r'\g:2-2-89372,n:192114*1C\$ARVSI,r003669946,,000052.59031009,1972,-108,0*1B' |
| 382 |
) |
| 383 |
queue = tag_block.TagQueue() |
| 384 |
for line in lines: |
| 385 |
queue.put(line) |
| 386 |
self.assertEqual(queue.qsize(), 1) |
| 387 |
msg = queue.get() |
| 388 |
self.assertEqual(msg['decoded']['id'], 1) |
| 389 |
|
| 390 |
def testTwoLineGroupWithTwoLineMessage(self): |
| 391 |
lines = ( |
| 392 |
|
| 393 |
r'\g:1-2-9459,s:rORBCOMM009,c:1426032120,T:2015-03-11 00.02.00*31\!AIVDM,2,1,9,A,59NS9142>SW@7PQWR20u84pLF1=Dr2222222221SDHa?A0l;`CDhCU3lp888,0*5B', |
| 394 |
r'\g:2-2-9459,s:rORBCOMM009,c:1426032120,T:2015-03-11 00.02.00*32\!AIVDM,2,2,9,A,88888888880,2*2D', |
| 395 |
) |
| 396 |
queue = tag_block.TagQueue() |
| 397 |
for line in lines: |
| 398 |
queue.put(line) |
| 399 |
self.assertEqual(queue.qsize(), 1) |
| 400 |
msg = queue.get() |
| 401 |
self.assertEqual(msg['decoded']['id'], 5) |
| 402 |
self.assertEqual(msg['times'], [1426032120, 1426032120]) |
| 403 |
|
| 404 |
def testThreeLineGroupWithTwoLineMessage(self): |
| 405 |
lines = ( |
| 406 |
|
| 407 |
r'\g:1-3-6417,n:4504,s:D13MN-PS-MTEBS1,c:1428451206*07\!SAVDM,2,1,7,B,59NSGLD2Cn5@CDLkN21Tu8dL5@F2222222222216EHMC=4w`0L@hEPC`8888,0*1A', |
| 408 |
r'\g:2-3-6417,n:4505*24\!SAVDM,2,2,7,B,88888888880,2*3A', |
| 409 |
r'\g:3-3-6417,n:4506*26\$SAVSI,D13MN-PS-MTEBS1,7,000006.831194,256,-97,19*67', |
| 410 |
) |
| 411 |
queue = tag_block.TagQueue() |
| 412 |
for line in lines: |
| 413 |
queue.put(line) |
| 414 |
self.assertEqual(queue.qsize(), 1) |
| 415 |
msg = queue.get() |
| 416 |
self.assertEqual(msg['decoded']['id'], 5) |
| 417 |
self.assertEqual(msg['times'], [1428451206, None, None]) |
| 418 |
|
| 419 |
|
| 420 |
if __name__ == '__main__': |
| 421 |
unittest.main() |