#!/usr/bin/env python
#
# Copyright 2009, 2012 by Jeffrey M. Laughlin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
import cStringIO as StringIO
from nose.tools import *
import adif
from decimal import Decimal
from datetime import datetime
TEST_ADIF = """
Exported using NA Version 10.57, conforming to ADIF specification 1.0
1.00
AB9RN14.150SSB201207141200
59 59 08
K4NNQ14.150SSB201207141206
59 59 08
KC0YSH14.150SSB201207141206
59 59 07
"""
def test_parse():
flo = StringIO.StringIO(TEST_ADIF)
reader = adif.Reader(flo)
i = reader._lex()
eq_(i.next(), adif.Field(name='call', type='', body='AB9RN'))
eq_(i.next(), adif.Field(name='freq', type='', body='14.150'))
eq_(i.next(), adif.Field(name='mode', type='', body='SSB'))
eq_(i.next(), adif.Field(name='qso_date', type='', body='20120714'))
eq_(i.next(), adif.Field(name='time_on', type='', body='1200'))
eq_(i.next(), adif.Field(name='rst_sent', type='', body='59 '))
eq_(i.next(), adif.Field(name='rst_rcvd', type='', body='59 '))
eq_(i.next(), adif.Field(name='comment', type='', body='08'))
eq_(i.next(), adif.Field(name='eor', type='', body=''))
eq_(i.next(), adif.Field(name='call', type='', body='K4NNQ'))
def test_iter_records():
flo = StringIO.StringIO(TEST_ADIF)
reader = adif.Reader(flo)
i = iter(reader)
eq_(i.next(), {'call': 'AB9RN', 'freq': '14.150', 'mode': 'SSB', 'qso_date': '20120714',
'time_on': '1200', 'rst_sent': '59 ', 'rst_rcvd': '59 ',
'comment': '08',
'app_datetime_on': datetime(2012, 07, 14, 12, 0)})
def test_version():
flo = StringIO.StringIO(TEST_ADIF)
reader = adif.Reader(flo)
eq_(reader.adif_ver, Decimal('1.00'))