master 0.1
Jeff Laughlin 2016-10-02 09:15:18 -04:00
rodzic e9f7483fdc
commit af4ecfddf1
4 zmienionych plików z 55 dodań i 20 usunięć

Wyświetl plik

@ -56,11 +56,12 @@ class CtyDat(object):
def getwpx(self, call):
prefix = None
a,b,c = None, None, None
fields = call.split('/')
try: a,b,c = fields
a, b, c = None, None, None
fields = re.split('/+', call)
try:
a, b, c = fields
except Exception:
try: a,b = fields
try: a, b = fields
except Exception:
a = fields

6
runtests.py 100644
Wyświetl plik

@ -0,0 +1,6 @@
#!/usr/bin/env python
"""Describe file"""
import pytest
if __name__ == '__main__':
pytest.main()

Wyświetl plik

@ -17,8 +17,7 @@
#
import cStringIO as StringIO
from nose.tools import *
import adif
import hamtools.adif
from decimal import Decimal
from datetime import datetime
@ -34,32 +33,43 @@ Exported using NA Version 10.57, conforming to ADIF specification 1.0
<rst_sent:3>59 <rst_rcvd:3>59 <comment:2>07<eor>
"""
import pytest
def eq_(a, b):
__tracebackhide__ = True
assert a == b
def test_parse():
flo = StringIO.StringIO(TEST_ADIF)
reader = adif.Reader(flo)
reader = hamtools.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'))
eq_(i.next(), hamtools.adif.Field(name='call', type='', body='AB9RN'))
eq_(i.next(), hamtools.adif.Field(name='freq', type='', body='14.150'))
eq_(i.next(), hamtools.adif.Field(name='mode', type='', body='SSB'))
eq_(i.next(), hamtools.adif.Field(name='qso_date', type='', body='20120714'))
eq_(i.next(), hamtools.adif.Field(name='time_on', type='', body='1200'))
eq_(i.next(), hamtools.adif.Field(name='rst_sent', type='', body='59 '))
eq_(i.next(), hamtools.adif.Field(name='rst_rcvd', type='', body='59 '))
eq_(i.next(), hamtools.adif.Field(name='comment', type='', body='08'))
eq_(i.next(), hamtools.adif.Field(name='eor', type='', body=''))
eq_(i.next(), hamtools.adif.Field(name='call', type='', body='K4NNQ'))
def test_iter_records():
flo = StringIO.StringIO(TEST_ADIF)
reader = adif.Reader(flo)
reader = hamtools.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'))
reader = hamtools.adif.Reader(flo)
eq_(reader.adif_ver, '1.00')

Wyświetl plik

@ -0,0 +1,18 @@
#!/usr/bin/env python
"""Describe file"""
from hamtools.ctydat import CtyDat
from pkg_resources import resource_stream
import pytest
call = 'SW8/SW1KYQ//P'
@pytest.fixture('session')
def ctydat():
ctydatflo = resource_stream('hamtools', "ctydat/cty.dat")
ctydat = CtyDat(ctydatflo)
return ctydat
def test_getwpx(ctydat):
assert ctydat.getwpx(call) == 'SW8'