python3 compatible

This commit is contained in:
Tobias Wellnitz, DH1TW 2018-01-27 19:52:27 +01:00
parent dd6784ae09
commit 023880ff34
29 changed files with 324 additions and 294 deletions

View file

@ -3,7 +3,7 @@ import tempfile
import os
from apikey import APIKEY, QRZ_USERNAME, QRZ_PWD
from .apikey import APIKEY, QRZ_USERNAME, QRZ_PWD
from pyhamtools import LookupLib
from pyhamtools import Callinfo
@ -82,7 +82,7 @@ def fix_callinfo(request, fixApiKey):
def fix_redis():
import redis
return LookupLib(lookuptype="redis", redis_instance=redis.Redis(), redis_prefix="clx")
@pytest.fixture(scope="module")
def fix_qrz():
return LookupLib(lookuptype="qrz", username=QRZ_USERNAME, pwd=QRZ_PWD)

File diff suppressed because one or more lines are too long

View file

@ -1,16 +1,23 @@
import os
import sys
import datetime
import pytest
from future.utils import iteritems
from pyhamtools.qsl import get_clublog_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
class Test_clublog_methods:
def test_check_content_with_mocked_http_server(self, httpserver):
httpserver.serve_content(
open('./fixtures/clublog-users.json.zip').read())
open(os.path.join(fix_dir, 'clublog-users.json.zip'), 'rb').read())
data = get_clublog_users(url=httpserver.url)
assert len(data) == 139081
@ -19,7 +26,7 @@ class Test_clublog_methods:
data = get_clublog_users()
assert isinstance(data, dict)
for key, value in data.iteritems():
for key, value in iteritems(data):
assert isinstance(key, unicode)
assert isinstance(value, dict)

View file

@ -1,17 +1,25 @@
import os
from past.builtins import execfile
import os
import sys
import datetime
import pytest
from pyhamtools.qsl import get_eqsl_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
class Test_eqsl_methods:
def test_check_content_with_mocked_http_server(self, httpserver):
httpserver.serve_content(open('./fixtures/eqsl_data.html').read(), headers={'content-type': 'text/plain; charset=ISO-8859-1'})
httpserver.serve_content(open(os.path.join(fix_dir, 'eqsl_data.html'), 'rb').read(), headers={'content-type': 'text/plain; charset=ISO-8859-1'})
exec(open(os.path.join("./fixtures/","eqsl_data.py")).read())
assert get_eqsl_users(url=httpserver.url) == eqsl_fixture
namespace = {}
execfile(os.path.join(fix_dir,"eqsl_data.py"), namespace)
assert get_eqsl_users(url=httpserver.url) == namespace['eqsl_fixture']
def test_download_lotw_list_and_check_types(self):

View file

@ -5,11 +5,11 @@ from pyhamtools.consts import LookupConventions as const
class Test_calculate_distance():
def test_calculate_distance_edge_cases(self):
assert calculate_distance("JN48QM", "JN48QM") == 0
assert calculate_distance("JN48", "JN48") == 0
assert abs(calculate_distance("AA00AA", "rr00xx") - 19009) < 1
def test_calculate_distance_normal_case(self):
assert abs(calculate_distance("JN48QM", "FN44AB") - 5965) < 1
@ -19,42 +19,41 @@ class Test_calculate_distance():
def test_calculate_distance_invalid_inputs(self):
with pytest.raises(AttributeError):
calculate_distance(5, 12)
with pytest.raises(ValueError):
calculate_distance("XX0XX", "ZZ0Z")
def test_calculate_distance_longpath_normal_case(self):
assert abs(calculate_distance_longpath("JN48QM", "FN44AB") - 34042) < 1
assert abs(calculate_distance_longpath("JN48QM", "QF67bf") - 23541) < 1
def test_calculate_distance_longpath_edge_cases(self):
assert abs(calculate_distance_longpath("JN48QM", "JN48QM") - 40008) < 1
assert abs(calculate_distance_longpath("JN48QM", "AE15UU") - 20645) < 1 #ZL7 Chatham - almost antipods
class Test_calculate_heading():
def test_calculate_heading_normal_cases(self):
assert abs(calculate_heading("JN48QM", "FN44AB") - 298) < 1
assert abs(calculate_heading("FN44AB", "JN48QM") - 54) < 1
assert abs(calculate_heading("JN48QM", "QF67bf") - 74) < 1
assert abs(calculate_heading("QF67BF", "JN48QM") - 310) < 1
def test_calculate_heading_edge_cases(self):
assert abs(calculate_heading("JN48QM", "JN48QM") - 0 ) < 1
def test_calculate_heading_longpath(self):
assert abs(calculate_heading_longpath("JN48QM", "FN44AB") - 118) < 1
assert abs(calculate_heading_longpath("FN44AB", "JN48QM") - 234) < 1
assert abs(calculate_heading_longpath("JN48QM", "QF67BF") - 254) < 1
assert abs(calculate_heading_longpath("QF67BF", "JN48QM") - 130) < 1
assert abs(calculate_heading_longpath("QF67BF", "JN48QM") - 130) < 1
def test_calculate_heading_longpath_edge_cases(self):
assert abs(calculate_heading_longpath("JN48QM", "JN48QM") - 180 ) < 1

View file

@ -15,10 +15,12 @@ class Test_latlong_to_locator():
def test_latlong_to_locator_invalid_characters(self):
with pytest.raises(ValueError):
# throws ValueError in Python2 and TypeError in Python3
with pytest.raises(Exception):
latlong_to_locator("JN48QM", "test")
with pytest.raises(ValueError):
# throws ValueError in Python2 and TypeError in Python3
with pytest.raises(Exception):
latlong_to_locator("", "")
def test_latlong_to_locator_out_of_boundry(self):

View file

@ -8,28 +8,28 @@ class Test_locator_to_latlong():
latitude, longitude = locator_to_latlong("AA00AA")
assert abs(latitude + 89.97916) < 0.00001
assert abs(longitude +179.95833) < 0.0001
latitude, longitude = locator_to_latlong("RR99XX")
assert abs(latitude - 89.97916) < 0.00001
assert abs(longitude - 179.9583) < 0.0001
def test_locator_to_latlong_normal_case(self):
latitude, longitude = locator_to_latlong("JN48QM")
assert abs(latitude - 48.52083) < 0.00001
assert abs(longitude - 9.3750000) < 0.0001
latitude, longitude = locator_to_latlong("JN48")
assert abs(latitude - 48.5) < 0.001
assert abs(longitude - 9.000) < 0.001
def test_locator_to_latlong_mixed_signs(self):
latitude, longitude = locator_to_latlong("Jn48qM")
assert abs(latitude - 48.52083) < 0.00001
assert abs(longitude - 9.3750000) < 0.0001
def test_locator_to_latlong_wrong_amount_of_characters(self):
with pytest.raises(ValueError):
@ -40,19 +40,19 @@ class Test_locator_to_latlong():
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("JN4")
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("JN8Q")
def test_locator_to_latlong_invalid_characters(self):
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("21XM99")
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("****")
def test_locator_to_latlong_out_of_boundry(self):
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("RR99XY")

View file

@ -10,10 +10,10 @@ UTC = pytz.UTC
class Test_calculate_sunrise_sunset_normal_case():
def test_calculate_sunrise_sunset(self):
time_margin = timedelta(minutes=1)
locator = "JN48QM"
test_time = datetime(year=2014, month=1, day=1, tzinfo=UTC)
result_JN48QM_1_1_2014_evening_dawn = datetime(2014, 1, 1, 15, 38, tzinfo=UTC)
result_JN48QM_1_1_2014_morning_dawn = datetime(2014, 1, 1, 6, 36, tzinfo=UTC)
@ -22,15 +22,15 @@ class Test_calculate_sunrise_sunset_normal_case():
assert calculate_sunrise_sunset(locator, test_time)['morning_dawn'] - result_JN48QM_1_1_2014_morning_dawn < time_margin
assert calculate_sunrise_sunset(locator, test_time)['evening_dawn'] - result_JN48QM_1_1_2014_evening_dawn < time_margin
assert calculate_sunrise_sunset(locator, test_time)['sunset'] - result_JN48QM_1_1_2014_sunset < time_margin
assert calculate_sunrise_sunset(locator, test_time)['sunset'] - result_JN48QM_1_1_2014_sunset < time_margin
assert calculate_sunrise_sunset(locator, test_time)['sunrise'] - result_JN48QM_1_1_2014_sunrise < time_margin
def test_calculate_distance_edge_case(self):
time_margin = timedelta(minutes=1)
locator = "AA00AA"
# no sunrise or sunset at southpol during arctic summer
test_time = datetime(year=2014, month=1, day=1, tzinfo=UTC)
result_AA00AA_1_1_2014_evening_dawn = datetime(2014, 1, 1, 15, 38, tzinfo=UTC)
result_AA00AA_1_1_2014_morning_dawn = datetime(2014, 1, 1, 6, 36, tzinfo=UTC)
@ -41,17 +41,17 @@ class Test_calculate_sunrise_sunset_normal_case():
assert calculate_sunrise_sunset(locator, test_time)['evening_dawn'] == None
assert calculate_sunrise_sunset(locator, test_time)['sunset'] == None
assert calculate_sunrise_sunset(locator, test_time)['sunrise'] == None
def test_calculate_distance_invalid_inputs(self):
with pytest.raises(ValueError):
calculate_sunrise_sunset("", "")
with pytest.raises(ValueError):
calculate_sunrise_sunset("JN48QM", "")
with pytest.raises(ValueError):
calculate_sunrise_sunset("JN48", 55)
with pytest.raises(AttributeError):
calculate_sunrise_sunset(33, datetime.now())

View file

@ -1,8 +1,12 @@
from __future__ import unicode_literals
import pytest
import sys
from pyhamtools.lookuplib import LookupLib
from pyhamtools.exceptions import APIKeyMissingError
if sys.version_info.major == 3:
unicode = str
@pytest.fixture(scope="function", params=[5, -5, "", "foo bar", 11.5, {}, [], None, ("foo", "bar")])
def fixAnyValue(request):
@ -20,7 +24,7 @@ class TestlookupLib:
class TestlookupLibHelper:
# def test_checkApiKeyValidity(self, fixClublogApi, fixApiKey):
#
# with pytest.raises(AttributeError):
@ -30,13 +34,12 @@ class TestlookupLibHelper:
# fixClublogApi._checkApiKeyValidity(apikey="")
#
# assert fixClublogApi._checkApiKeyValidity(apikey=fixApiKey) is True
def test_generateRandomWord(self, fixClublogApi, fixNonUnsignedInteger):
with pytest.raises(TypeError):
fixClublogApi._generate_random_word()
assert type(fixClublogApi._generate_random_word(5)) is str
assert type(fixClublogApi._generate_random_word(5)) is unicode
assert len(fixClublogApi._generate_random_word(5)) is 5

View file

@ -8,60 +8,56 @@ from pyhamtools.exceptions import APIKeyMissingError
#Fixtures
#===========================================================
response_Exception_DH1TW = {
'adif': 230,
'country': u'FEDERAL REPUBLIC OF GERMANY',
'continent': u'EU',
'latitude': 51.0,
'longitude': -10.0,
response_Exception_DH1TW = {
'adif': 230,
'country': u'FEDERAL REPUBLIC OF GERMANY',
'continent': u'EU',
'latitude': 51.0,
'longitude': -10.0,
'cqz': 14
}
response_Exception_VU9KV = {
'adif': 324,
'country': u'INDIA',
'continent': u'AS',
'latitude': 22.0,
'longitude': -80.0,
response_Exception_VU9KV = {
'adif': 324,
'country': u'INDIA',
'continent': u'AS',
'latitude': 22.0,
'longitude': -80.0,
'cqz': 22
}
response_Exception_VU9KV_with_Date = {
'adif': 11,
'country': u'ANDAMAN & NICOBAR ISLANDS',
'continent': u'AS',
'latitude': 11.70,
'longitude': -92.80,
response_Exception_VU9KV_with_Date = {
'adif': 11,
'country': u'ANDAMAN & NICOBAR ISLANDS',
'continent': u'AS',
'latitude': 11.70,
'longitude': -92.80,
'cqz': 26
}
response_Exception_DH1TW_MM = {
'adif': 999,
'country': u'MARITIME MOBILE',
'continent': u'',
'latitude': 0.0,
'longitude': 0.0,
response_Exception_DH1TW_MM = {
'adif': 999,
'country': u'MARITIME MOBILE',
'continent': u'',
'latitude': 0.0,
'longitude': 0.0,
'cqz': 0
}
response_Exception_DH1TW_AM = {
'adif': 998,
'country': u'AIRCRAFT MOBILE',
'continent': u'',
'longitude': 0.0,
'latitude': 0.0,
response_Exception_DH1TW_AM = {
'adif': 998,
'country': u'AIRCRAFT MOBILE',
'continent': u'',
'longitude': 0.0,
'latitude': 0.0,
'cqz': 0
}
#TESTS
#===========================================================
class TestClublogApi_Constructor:
def test_with_invalid_api_key(self):
@ -73,22 +69,22 @@ class TestClublogApi_Constructor:
with pytest.raises(APIKeyMissingError):
lib = LookupLib(lookuptype="clublogapi")
lib.lookup_callsign("DH1TW")
class TestclublogApi_Getters:
#getEntity(adif)
#===============================
def test_lookup_callsign(self, fixClublogApi):
assert fixClublogApi.lookup_entity(230) is None
#lookup_callsign(callsign, [date])
#===============================
def test_lookup_callsign(self, fixClublogApi):
assert fixClublogApi.lookup_callsign("DH1TW") == response_Exception_DH1TW
assert fixClublogApi.lookup_callsign("VU9KV") == response_Exception_VU9KV
d = datetime.utcnow().replace(year=1971, month=04, day=14)
d = datetime.utcnow().replace(year=1971, month=4, day=14)
assert fixClublogApi.lookup_callsign("VU9KV", d) == response_Exception_VU9KV_with_Date
assert fixClublogApi.lookup_callsign("DH1TW/MM") == response_Exception_DH1TW_MM
assert fixClublogApi.lookup_callsign("DH1TW/AM") == response_Exception_DH1TW_AM
@ -97,23 +93,23 @@ class TestclublogApi_Getters:
fixClublogApi.lookup_callsign("QRM")
with pytest.raises(KeyError):
fixClublogApi.lookup_callsign("")
#lookup_prefix(prefix, [date])
#===============================
def test_lookup_callsign(self, fixClublogApi):
with pytest.raises(KeyError):
fixClublogApi.lookup_prefix("DH")
#is_invalid_operation(callsign, [date])
#===============================
def test_is_invalid_operation(self, fixClublogApi):
with pytest.raises(KeyError):
fixClublogApi.is_invalid_operation("5W1CFN")
#lookup_zone_exception(callsign, [date])
#====================================
#====================================
def test_lookup_zone_exception(self, fixClublogApi):
with pytest.raises(KeyError):
fixClublogApi.lookup_zone_exception("dp0gvn")

View file

@ -268,7 +268,7 @@ class TestclublogXML_Getters:
fixClublogXML.is_invalid_operation("5W1CFN", timestamp_before)
#Invalid Operation with end date
timestamp_before = datetime(year=2004, month=04, day=02).replace(tzinfo=UTC)
timestamp_before = datetime(year=2004, month=4, day=2).replace(tzinfo=UTC)
with pytest.raises(KeyError):
fixClublogXML.is_invalid_operation("T33C")
@ -291,7 +291,7 @@ class TestclublogXML_Getters:
#zone exception with start and end date
timestamp = datetime(year=1992, month=10, day=2).replace(tzinfo=UTC)
timestamp_before = datetime(year=1992, month=9, day=30).replace(tzinfo=UTC)
timestamp_after = datetime(year=1993, month=03, day=1).replace(tzinfo=UTC)
timestamp_after = datetime(year=1993, month=3, day=1).replace(tzinfo=UTC)
assert fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp) == 38
with pytest.raises(KeyError):

View file

@ -8,27 +8,27 @@ from pyhamtools.exceptions import APIKeyMissingError
#Fixtures
#===========================================================
response_Prefix_DH = {
'adif': 230,
'country': 'Fed. Rep. of Germany',
'continent': 'EU',
'latitude': 51.0,
'longitude': 10.0,
response_Prefix_DH = {
'adif': 230,
'country': 'Fed. Rep. of Germany',
'continent': 'EU',
'latitude': 51.0,
'longitude': 10.0,
'cqz': 14,
'ituz' : 28
}
response_Exception_3D2RI = {
'adif': 460,
'country': 'Rotuma Island',
'continent': 'OC',
'latitude': -12.48,
'longitude': 177.08,
response_Exception_3D2RI = {
'adif': 460,
'country': 'Rotuma Island',
'continent': 'OC',
'latitude': -12.48,
'longitude': 177.08,
'cqz': 32,
'ituz' : 56
}
@pytest.fixture(scope="function")
def fix_plist_file(request):
dir = os.path.dirname(__file__)
@ -54,14 +54,14 @@ class Test_Countryfile_Constructor:
lib.lookup_callsign("GB0BVL")
class Test_countryfile_Getter_Setter:
#lookup_entity(adif)
#===============================
def test_getException(self, fixCountryFile):
with pytest.raises(KeyError):
fixCountryFile.lookup_entity(230)
#lookup_callsign(callsign, [date])
#===============================
def test_getException(self, fixCountryFile):
@ -72,8 +72,8 @@ class Test_countryfile_Getter_Setter:
with pytest.raises(KeyError):
fixCountryFile.lookup_callsign("")
#lookup_prefix(prefix, [date])
#=========================
def test_lookup_prefix(self, fixCountryFile):
@ -92,7 +92,7 @@ class Test_countryfile_Getter_Setter:
fixCountryFile.is_invalid_operation("5W1CFN")
#lookup_zone_exception(callsign, [date])
#====================================
#====================================
def test_lookup_zone_exception(self, fixCountryFile):
with pytest.raises(KeyError):
fixCountryFile.lookup_zone_exception("dp0gvn")

View file

@ -1,6 +1,11 @@
from __future__ import unicode_literals
import pytest
import tempfile
import os
import sys
if sys.version_info.major == 3:
unicode = str
from datetime import datetime
@ -19,7 +24,7 @@ def fixExceptions(request):
@pytest.fixture(scope="function", params=["DH", "DH1TW", "", 5, 12.5, -9999, {}, []])
def fixPrefixes(request):
return request.param
@pytest.fixture(scope="function", params=["DH1TW", "JA3UB/GAZA", "", 5, 12.5, -9999, {}, []])
def fixInvalidOperations(request):
return request.param
@ -28,7 +33,7 @@ def fixInvalidOperations(request):
def fixZoneExceptions(request):
return request.param
@pytest.fixture(scope="function", params=[{"DH1TW": {'latitude': 51.0, 'country': 'FEDERAL REPUBLIC OF GERMANY',
@pytest.fixture(scope="function", params=[{"DH1TW": {'latitude': 51.0, 'country': 'FEDERAL REPUBLIC OF GERMANY',
'continent': 'EU', 'longitude': -10.0, 'cqz': 14}}, {}, "ve8ev", "", 5, 12.5, -9999])
def fixSetExceptions(request):
return request.param
@ -39,11 +44,11 @@ def fixSetExceptions(request):
#===========================================================
class Test_Getter_Setter_Api_Types_for_all_sources:
def test_lookup_entity_without_entity_nr(self, fixGeneralApi):
with pytest.raises(Exception):
fixGeneralApi.lookup_entity()
def test_lookup_entity(self, fixGeneralApi, fixEntities):
try:
entity = fixGeneralApi.lookup_entity(fixEntities)
@ -51,43 +56,43 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
assert type(entity) is dict
if len(entity) > 0:
count = 0
for attr in entity:
if attr == "country":
for attr in entity:
if attr == "country":
assert type(entity[attr] is unicode)
count +=1
if attr == "continent":
if attr == "continent":
assert type(entity[attr] is unicode)
count +=1
if attr == "prefix":
if attr == "prefix":
assert type(entity[attr] is unicode)
count +=1
if attr == "deleted":
count +=1
if attr == "deleted":
assert type(entity[attr] is bool)
count +=1
if attr == "cqz":
count +=1
if attr == "cqz":
assert type(entity[attr] is int)
count +=1
if attr == "longitude":
count +=1
if attr == "longitude":
assert type(entity[attr] is float)
count +=1
if attr == "latitude":
count +=1
if attr == "latitude":
assert type(entity[attr] is float)
count +=1
if attr == "start":
count +=1
if attr == "start":
assert type(entity[attr] is datetime)
count +=1
if attr == "end":
count +=1
if attr == "end":
assert type(entity[attr] is datetime)
count +=1
if attr == "whitelist":
count +=1
if attr == "whitelist":
assert type(entity[attr] is bool)
count +=1
if attr == "whitelist_start":
count +=1
if attr == "whitelist_start":
assert type(entity[attr] is datetime)
count +=1
if attr == "whitelist_end":
count +=1
if attr == "whitelist_end":
assert type(entity[attr] is datetime)
count +=1
count +=1
assert len(entity) == count
except KeyError:
pass
@ -95,91 +100,91 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
pass
except ValueError:
pass
def test_lookup_callsign(self, fixGeneralApi, fixExceptions):
try:
ex = fixGeneralApi.lookup_callsign(fixExceptions)
assert type(ex) is dict
count = 0
for attr in ex:
if attr == "latitude":
for attr in ex:
if attr == "latitude":
assert type(ex[attr]) is float
count +=1
elif attr == "longitude":
elif attr == "longitude":
assert type(ex[attr]) is float
count +=1
elif attr == "country":
elif attr == "country":
assert type(ex[attr]) is unicode
count +=1
elif attr == "continent":
elif attr == "continent":
assert type(ex[attr]) is unicode
count +=1
elif attr == "cqz":
elif attr == "cqz":
assert type(ex[attr]) is int
count +=1
elif attr == "ituz":
elif attr == "ituz":
assert type(ex[attr]) is int
count +=1
elif attr == "start":
elif attr == "start":
assert type(ex[attr]) is datetime
count +=1
elif attr == "end":
elif attr == "end":
assert type(ex[attr]) is datetime
count +=1
elif attr == "adif":
elif attr == "adif":
assert type(ex[attr]) is int
count +=1
#all attributes checked?
#all attributes checked?
assert len(ex) == count
except KeyError:
pass
except AttributeError:
pass
def test_lookup_prefix(self, fixGeneralApi, fixPrefixes):
try:
prefix = fixGeneralApi.lookup_prefix(fixPrefixes)
assert type(prefix) is dict
count = 0
for attr in prefix:
if attr == "country":
for attr in prefix:
if attr == "country":
assert type(prefix[attr]) is unicode
count +=1
elif attr == "adif":
elif attr == "adif":
assert type(prefix[attr]) is int
count +=1
elif attr == "cqz":
elif attr == "cqz":
assert type(prefix[attr]) is int
count +=1
elif attr == "ituz":
elif attr == "ituz":
assert type(prefix[attr]) is int
count +=1
elif attr == "continent":
elif attr == "continent":
assert type(prefix[attr]) is unicode
count +=1
elif attr == "latitude":
elif attr == "latitude":
assert type(prefix[attr]) is float
count +=1
elif attr == "longitude":
elif attr == "longitude":
assert type(prefix[attr]) is float
count +=1
elif attr == "start":
elif attr == "start":
assert type(prefix[attr]) is datetime
count +=1
elif attr == "end":
elif attr == "end":
assert type(prefix[attr]) is datetime
count +=1
#all attributes checked?
#all attributes checked?
assert len(prefix) == count
except KeyError:
pass
except AttributeError:
pass
def test_get_InvalidOperation(self, fixGeneralApi, fixInvalidOperations):
try:
invOp = fixGeneralApi.is_invalid_operation(fixInvalidOperations)

View file

@ -2,7 +2,7 @@ import pytest
from datetime import datetime
from apikey import QRZ_USERNAME, QRZ_PWD
from .apikey import QRZ_USERNAME, QRZ_PWD
from pyhamtools.lookuplib import LookupLib
from pyhamtools.exceptions import APIKeyMissingError
from pyhamtools.consts import LookupConventions as const

View file

@ -1,36 +1,45 @@
import os
import os
import sys
import datetime
from past.builtins import execfile
from future.utils import iteritems
import pytest
from pyhamtools.qsl import get_lotw_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
class Test_lotw_methods:
def test_check_content_with_mocked_http_server(self, httpserver):
httpserver.serve_content(open('./fixtures/lotw-user-activity.csv').read())
exec(open(os.path.join("./fixtures/","lotw_fixture.py")).read())
assert get_lotw_users(url=httpserver.url) == lotw_fixture
httpserver.serve_content(open(os.path.join(fix_dir, 'lotw-user-activity.csv')).read())
namespace = {}
execfile(os.path.join(fix_dir,"lotw_fixture.py"), namespace)
assert get_lotw_users(url=httpserver.url) == namespace['lotw_fixture']
def test_download_lotw_list_and_check_types(self):
data = get_lotw_users()
assert isinstance(data, dict)
for key, value in data.iteritems():
for key, value in iteritems(data):
assert isinstance(key, unicode)
assert isinstance(value, datetime.datetime )
assert len(data) > 1000
def test_with_invalid_url(self):
with pytest.raises(IOError):
get_lotw_users(url="https://lotw.arrl.org/lotw-user-activity_FAKE.csv")
def test_with_more_than_10_invalid_dates(self, httpserver):
httpserver.serve_content(open('./fixtures/lotw_data_with_errors.html').read())
httpserver.serve_content(open(os.path.join(fix_dir, 'lotw_data_with_errors.html')).read())
with pytest.raises(ValueError):
get_lotw_users(url=httpserver.url)