diff --git a/hamtools/ctydat.py b/hamtools/ctydat.py index bcd5f1f..bccec7d 100644 --- a/hamtools/ctydat.py +++ b/hamtools/ctydat.py @@ -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 diff --git a/runtests.py b/runtests.py new file mode 100644 index 0000000..3a966db --- /dev/null +++ b/runtests.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python +"""Describe file""" +import pytest + +if __name__ == '__main__': + pytest.main() diff --git a/hamtools/test_adif.py b/tests/test_adif.py similarity index 64% rename from hamtools/test_adif.py rename to tests/test_adif.py index c612a7a..c7bf047 100644 --- a/hamtools/test_adif.py +++ b/tests/test_adif.py @@ -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 59 59 07 """ + +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') diff --git a/tests/test_ctydat.py b/tests/test_ctydat.py new file mode 100644 index 0000000..a6f6972 --- /dev/null +++ b/tests/test_ctydat.py @@ -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' +