# Path: ogn/parser/telnet_parser.py
# def parse(telnet_data):
#     reference_timestamp = datetime.utcnow()
# 
#     match = telnet_50001_pattern.match(telnet_data)
#     if match:
#         return {'pps_offset': float(match.group('pps_offset')),
#                 'frequency': float(match.group('frequency')),
#                 'aircraft_type': int(match.group('aircraft_type')),
#                 'address_type': int(match.group('address_type')),
#                 'address': match.group('address'),
#                 'timestamp': createTimestamp(match.group('timestamp') + 'h', reference_timestamp),
#                 'latitude': float(match.group('latitude')),
#                 'longitude': float(match.group('longitude')),
#                 'altitude': int(match.group('altitude')),
#                 'climb_rate': float(match.group('climb_rate')),
#                 'ground_speed': float(match.group('ground_speed')),
#                 'track': float(match.group('track')),
#                 'turn_rate': float(match.group('turn_rate')),
#                 'magic_number': int(match.group('magic_number')),
#                 'gps_status': match.group('gps_status'),
#                 'channel': int(match.group('channel')),
#                 'flarm_timeslot': match.group('flarm_timeslot') == 'f',
#                 'ogn_timeslot': match.group('ogn_timeslot') == 'o',
#                 'frequency_offset': float(match.group('frequency_offset')),
#                 'decode_quality': float(match.group('decode_quality')),
#                 'signal_quality': float(match.group('signal_quality')),
#                 'demodulator_type': int(match.group('demodulator_type')),
#                 'error_count': float(match.group('error_count')),
#                 'distance': float(match.group('distance')),
#                 'bearing': float(match.group('bearing')),
#                 'phi': float(match.group('phi')),
#                 'multichannel': match.group('multichannel') == '+'}
#     else:
#         return None
# 
# Path: ogn/parser/exceptions.py
# class ParseError(Exception):
#     pass


import unittest
import unittest.mock as mock
from datetime import datetime
from ogn.parser.telnet_parser import parse
from ogn.parser.exceptions import ParseError




class TestStringMethods(unittest.TestCase):
    @unittest.skip("Not yet implemented")
    def test_telnet_fail_corrupt(self):
        with self.assertRaises(ParseError):
            parse('This is rubbish')

    @mock.patch('ogn.parser.telnet_parser.datetime')
    def test_telnet_parse_complete(self, datetime_mock):
        # set the utcnow-mock near to the time in the test string
        datetime_mock.utcnow.return_value = datetime(2015, 1, 1, 10, 0, 55)


# Path: ogn/parser/telnet_parser.py
# def parse(telnet_data):
#     reference_timestamp = datetime.utcnow()
# 
#     match = telnet_50001_pattern.match(telnet_data)
#     if match:
#         return {'pps_offset': float(match.group('pps_offset')),
#                 'frequency': float(match.group('frequency')),
#                 'aircraft_type': int(match.group('aircraft_type')),
#                 'address_type': int(match.group('address_type')),
#                 'address': match.group('address'),
#                 'timestamp': createTimestamp(match.group('timestamp') + 'h', reference_timestamp),
#                 'latitude': float(match.group('latitude')),
#                 'longitude': float(match.group('longitude')),
#                 'altitude': int(match.group('altitude')),
#                 'climb_rate': float(match.group('climb_rate')),
#                 'ground_speed': float(match.group('ground_speed')),
#                 'track': float(match.group('track')),
#                 'turn_rate': float(match.group('turn_rate')),
#                 'magic_number': int(match.group('magic_number')),
#                 'gps_status': match.group('gps_status'),
#                 'channel': int(match.group('channel')),
#                 'flarm_timeslot': match.group('flarm_timeslot') == 'f',
#                 'ogn_timeslot': match.group('ogn_timeslot') == 'o',
#                 'frequency_offset': float(match.group('frequency_offset')),
#                 'decode_quality': float(match.group('decode_quality')),
#                 'signal_quality': float(match.group('signal_quality')),
#                 'demodulator_type': int(match.group('demodulator_type')),
#                 'error_count': float(match.group('error_count')),
#                 'distance': float(match.group('distance')),
#                 'bearing': float(match.group('bearing')),
#                 'phi': float(match.group('phi')),
#                 'multichannel': match.group('multichannel') == '+'}
#     else:
#         return None
# 
# Path: ogn/parser/exceptions.py
# class ParseError(Exception):
#     pass


# Path: tests/parser/test_parse_telnet.py
import unittest
import unittest.mock as mock
from datetime import datetime
from ogn.parser.telnet_parser import parse
from ogn.parser.exceptions import ParseError





class TestStringMethods(unittest.TestCase):
    @unittest.skip("Not yet implemented")
    def test_telnet_fail_corrupt(self):
        with self.assertRaises(ParseError):
            parse('This is rubbish')

    @mock.patch('ogn.parser.telnet_parser.datetime')
    def test_telnet_parse_complete(self, datetime_mock):
        # set the utcnow-mock near to the time in the test string
        datetime_mock.utcnow.return_value = datetime(2015, 1, 1, 10, 0, 55)


        message = parse('0.181sec:868.394MHz:   1:2:DDA411 103010: [ +50.86800, +12.15279]deg  988m  +0.1m/s  25.7m/s 085.4deg  -3.5deg/sec 5 03x04m 01f_-12.61kHz  5.8/15.5dB/2 10e   30.9km 099.5deg  +1.1deg + ?     R     B8949')