def test__get_type(self): streamer = TMQStream() sentence = '$GPRMC,184332.07,A,1929.459,S,02410.381,E,74.00,16.78,210410,0.0,E*46' self.assertRaises( TypeError, streamer._get_type, sentence) sentence = '$PTMQA,\x01\x02$M\x08\x05\x91\x02$M\x00*E8\r\n' sen_type = streamer._get_type(sentence) self.assertTrue(isinstance(sen_type(), MQA))
def test_read_data_obj(self): test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'test_data_small.tmq') with open(test_file, 'r') as test_file_fd: streamer = TMQStream(stream_obj=test_file_fd) nmea_objects = streamer.get_objects() expected_object_types = ['MQA', 'MQA'] self.assertEqual(expected_object_types[0], nmea_objects[0].sen_type) self.assertEqual(expected_object_types[1], nmea_objects[1].sen_type)
def test_read_data_obj_raw(self): data = """$GPRMC,184332.07,A,1929.459,S,02410.381,E,74.00,16.78,210410,0.0,E*46 $PTMQA,\x01\x02$M\x08\x05\x91\x02$M\x00*E8\r\n$GPGGA,184333.07,1929.439,S,02410.387,E,1,04,2.8,100.00,M,-33.9,M,,0000*65 $GPRMC,184444.08,A,1928.041,S,02410.809,E,74.00,16.78,210410,0.0,E*48 $GPGGA,184445.08,1928.021,S,02410.814,E,1,04,2.7,100.00,M,-33.9,M,,0000*6E $GPGLL,1928.001,S,02410.820,E,184446.08,A,A*79 $GPVTG,16.78,T,,M,74.00,N,137.05,K,A*36 $PTMQA,\x01\x02*M\x08\x05\\\x02*M\x00*76\r\n$GPRMC,184448.08,A,1927.962,S,02410.832,E,74.00,16.78,210410,0.0,E*4B $GPGGA,184449.08,1927.942,S,02410.838,E,1,04,1.7,100.00,M,-33.9,M,,0000*6C $GPGLL,1927.922,S,02410.844,E,184450.08,A,A*7B $GPVTG,16.78,T,,M,74.00,N,137.05,K,A*36""" streamer = TMQStream() nmea_objects = streamer.get_objects(data=data) expected_object_types = ['MQA', 'MQA'] self.assertEqual(expected_object_types[0], nmea_objects[0].sen_type) self.assertEqual(expected_object_types[1], nmea_objects[1].sen_type)
def test__read(self): # WARNING!: If data is supplied through file like object, the data MUST be in binary format # for TMQ style streamer to work correctly test_file = os.path.join(os.path.dirname(__file__), 'test_data', 'test_data_small.tmq') expected_result = [ '$PTMQA,\x01\x02$M\x08\x05\x91\x02$M\x00*E8', '$PTMQA,\x01\x02*M\x08\x05\\\x02*M\x00*76', ] with open(test_file, 'r') as test_file_fd: streamer = TMQStream(stream_obj=test_file_fd) next_data = streamer._read() data = [] while next_data: data += next_data next_data = streamer._read() pass self.assertEqual(data, expected_result)
def test__read_data(self): expected_result = [ '$PTMQA,\x01\x02$M\x08\x05\x91\x02$M\x00*E8', '$PTMQA,\x01\x02*M\x08\x05\\\x02*M\x00*76', ] # WARNING!: For TMQStreamer the data MUST be in binary format for streamer to work correctly input_data = """$GPRMC,184332.07,A,1929.459,S,02410.381,E,74.00,16.78,210410,0.0,E*46 $PTMQA,\x01\x02$M\x08\x05\x91\x02$M\x00*E8\r\n$GPGGA,184333.07,1929.439,S,02410.387,E,1,04,2.8,100.00,M,-33.9,M,,0000*65 $GPRMC,184444.08,A,1928.041,S,02410.809,E,74.00,16.78,210410,0.0,E*48 $GPGGA,184445.08,1928.021,S,02410.814,E,1,04,2.7,100.00,M,-33.9,M,,0000*6E $GPGLL,1928.001,S,02410.820,E,184446.08,A,A*79 $GPVTG,16.78,T,,M,74.00,N,137.05,K,A*36 $PTMQA,\x01\x02*M\x08\x05\\\x02*M\x00*76\r\n$GPRMC,184448.08,A,1927.962,S,02410.832,E,74.00,16.78,210410,0.0,E*4B $GPGGA,184449.08,1927.942,S,02410.838,E,1,04,1.7,100.00,M,-33.9,M,,0000*6C $GPGLL,1927.922,S,02410.844,E,184450.08,A,A*7B $GPVTG,16.78,T,,M,74.00,N,137.05,K,A*36""" streamer = TMQStream() data = streamer._read(data=input_data) self.assertEqual(data, expected_result)