mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2026-01-03 07:10:16 +01:00
python3 compatible
This commit is contained in:
parent
dd6784ae09
commit
023880ff34
9
.cache/v/cache/lastfailed
vendored
Normal file
9
.cache/v/cache/lastfailed
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"test/test_callinfo.py::Test_callinfo_methods::()::test_get_all[clublogapi]": true,
|
||||
"test/test_callinfo.py::Test_callinfo_methods::()::test_get_lat_long[clublogapi]": true,
|
||||
"test/test_callinfo.py::Test_callinfo_methods::()::test_lookup_callsign[clublogapi]": true,
|
||||
"test/test_clublog.py::Test_clublog_methods": true,
|
||||
"test/test_eqsl.py::Test_eqsl_methods": true,
|
||||
"test/test_lookuplib_redis.py::TestStoreDataInRedis": true,
|
||||
"test/test_lotw.py::Test_lotw_methods": true
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ master_doc = 'index'
|
|||
|
||||
# General information about the project.
|
||||
project = u'pyhamtools'
|
||||
copyright = u'2016, Tobias Wellnitz, DH1TW'
|
||||
copyright = u'2018, Tobias Wellnitz, DH1TW'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
callsign_exceptions={
|
||||
'7QAA' : '7Q',
|
||||
'2SZ' : 'G0'
|
||||
'2SZ' : 'G0'
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ class LookupConventions:
|
|||
AIRCRAFT_MOBILE = u"am"
|
||||
LOCATOR = u"locator"
|
||||
BEACON = u"beacon"
|
||||
|
||||
|
||||
#CQ / DIGITAL Skimmer specific
|
||||
|
||||
SKIMMER = u"skimmer"
|
||||
|
|
@ -31,8 +31,8 @@ class LookupConventions:
|
|||
WPM = u"wpm" #words / bytes per second
|
||||
CQ = u"cq"
|
||||
NCDXF = u"ncdxf"
|
||||
|
||||
|
||||
|
||||
|
||||
# Modes
|
||||
CW = u"CW"
|
||||
USB = u"USB"
|
||||
|
|
|
|||
|
|
@ -4,4 +4,3 @@
|
|||
class APIKeyMissingError(AttributeError):
|
||||
""" API Key is Missing """
|
||||
pass
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ def import_cabrillo(filename):
|
|||
log = []
|
||||
log_import = log_import.split("\r\n")
|
||||
|
||||
for qso in log_import:
|
||||
for qso in log_import:
|
||||
|
||||
if re.match("^QSO", qso):
|
||||
freq = int(qso[4:11])
|
||||
|
|
@ -24,15 +24,15 @@ def import_cabrillo(filename):
|
|||
rcvd_exchange = qso[73:79].strip()
|
||||
station = int(qso[80])
|
||||
log.append({
|
||||
"freq": freq,
|
||||
"mode":mode,
|
||||
"time":time,
|
||||
"from": frm,
|
||||
"freq": freq,
|
||||
"mode":mode,
|
||||
"time":time,
|
||||
"from": frm,
|
||||
"sent_rst":sent_rst,
|
||||
"sent_exchange": sent_exchange,
|
||||
"qso_partner": qso_partner,
|
||||
"rcvd_rst": rcvd_rst,
|
||||
"rcvd_exchange": rcvd_exchange,
|
||||
"sent_exchange": sent_exchange,
|
||||
"qso_partner": qso_partner,
|
||||
"rcvd_rst": rcvd_rst,
|
||||
"rcvd_exchange": rcvd_exchange,
|
||||
"station": station
|
||||
})
|
||||
return log
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
import logging.config
|
||||
|
|
@ -16,9 +17,9 @@ from requests.exceptions import ConnectionError, HTTPError, Timeout
|
|||
from bs4 import BeautifulSoup
|
||||
import pytz
|
||||
|
||||
import version
|
||||
from consts import LookupConventions as const
|
||||
from exceptions import APIKeyMissingError
|
||||
from . import version
|
||||
from .consts import LookupConventions as const
|
||||
from .exceptions import APIKeyMissingError
|
||||
|
||||
UTC = pytz.UTC
|
||||
timestamp_now = datetime.utcnow().replace(tzinfo=UTC)
|
||||
|
|
@ -28,6 +29,9 @@ if sys.version_info < (2, 7,):
|
|||
def emit(self, record):
|
||||
pass
|
||||
|
||||
if sys.version_info.major == 3:
|
||||
unicode = str
|
||||
|
||||
class LookupLib(object):
|
||||
"""
|
||||
|
||||
|
|
@ -126,9 +130,12 @@ class LookupLib(object):
|
|||
"agent" : agent
|
||||
}
|
||||
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
if sys.version_info.major == 3:
|
||||
encodeurl = url + "?" + urllib.parse.urlencode(params)
|
||||
else:
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
response = requests.get(encodeurl, timeout=10)
|
||||
doc = BeautifulSoup(response.text)
|
||||
doc = BeautifulSoup(response.text, "html.parser")
|
||||
session_key = None
|
||||
if doc.session.key:
|
||||
session_key = doc.session.key.text
|
||||
|
|
@ -393,10 +400,10 @@ class LookupLib(object):
|
|||
raise KeyError ("redis_prefix is missing")
|
||||
|
||||
if r.scard(redis_prefix + index_name + str(item)) > 0:
|
||||
data_index_dict[item] = r.smembers(redis_prefix + index_name + str(item))
|
||||
data_index_dict[str(item)] = r.smembers(redis_prefix + index_name + str(item))
|
||||
|
||||
for i in data_index_dict[item]:
|
||||
json_data = r.get(redis_prefix + name + i)
|
||||
json_data = r.get(redis_prefix + name + str(int(i)))
|
||||
data_dict[i] = self._deserialize_data(json_data)
|
||||
|
||||
return (data_dict, data_index_dict)
|
||||
|
|
@ -679,7 +686,10 @@ class LookupLib(object):
|
|||
"call" : callsign
|
||||
}
|
||||
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
if sys.version_info.major == 3:
|
||||
encodeurl = url + "?" + urllib.parse.urlencode(params)
|
||||
else:
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
response = requests.get(encodeurl, timeout=5)
|
||||
|
||||
if not self._check_html_response(response):
|
||||
|
|
@ -710,7 +720,10 @@ class LookupLib(object):
|
|||
"callsign" : callsign,
|
||||
}
|
||||
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
if sys.version_info.major == 3:
|
||||
encodeurl = url + "?" + urllib.parse.urlencode(params)
|
||||
else:
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
response = requests.get(encodeurl, timeout=5)
|
||||
return response
|
||||
|
||||
|
|
@ -723,7 +736,10 @@ class LookupLib(object):
|
|||
"dxcc" : str(dxcc_or_callsign),
|
||||
}
|
||||
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
if sys.version_info.major == 3:
|
||||
encodeurl = url + "?" + urllib.parse.urlencode(params)
|
||||
else:
|
||||
encodeurl = url + "?" + urllib.urlencode(params)
|
||||
response = requests.get(encodeurl, timeout=5)
|
||||
return response
|
||||
|
||||
|
|
@ -733,7 +749,7 @@ class LookupLib(object):
|
|||
|
||||
response = self._request_dxcc_info_from_qrz(dxcc_or_callsign, apikey, apiv=apiv)
|
||||
|
||||
root = BeautifulSoup(response.text)
|
||||
root = BeautifulSoup(response.text, "html.parser")
|
||||
lookup = {}
|
||||
|
||||
if root.error: #try to get a new session key and try to request again
|
||||
|
|
@ -743,7 +759,7 @@ class LookupLib(object):
|
|||
elif re.search('Session Timeout', root.error.text, re.I): # Get new session key
|
||||
self._apikey = apikey = self._get_qrz_session_key(self._username, self._pwd)
|
||||
response = self._request_dxcc_info_from_qrz(dxcc_or_callsign, apikey)
|
||||
root = BeautifulSoup(response.text)
|
||||
root = BeautifulSoup(response.text, "html.parser")
|
||||
else:
|
||||
raise AttributeError("Session Key Missing") #most likely session key missing or invalid
|
||||
|
||||
|
|
@ -785,7 +801,7 @@ class LookupLib(object):
|
|||
|
||||
response = self._request_callsign_info_from_qrz(callsign, apikey, apiv)
|
||||
|
||||
root = BeautifulSoup(response.text)
|
||||
root = BeautifulSoup(response.text, "html.parser")
|
||||
lookup = {}
|
||||
|
||||
if root.error:
|
||||
|
|
@ -797,7 +813,7 @@ class LookupLib(object):
|
|||
elif re.search('Session Timeout', root.error.text, re.I) or re.search('Invalid session key', root.error.text, re.I):
|
||||
apikey = self._get_qrz_session_key(self._username, self._pwd)
|
||||
response = self._request_callsign_info_from_qrz(callsign, apikey, apiv)
|
||||
root = BeautifulSoup(response.text)
|
||||
root = BeautifulSoup(response.text, "html.parser")
|
||||
|
||||
#if this fails again, raise error
|
||||
if root.error:
|
||||
|
|
@ -1043,7 +1059,7 @@ class LookupLib(object):
|
|||
filename = "cty_" + self._generate_random_word(5)
|
||||
|
||||
download_file_path = os.path.join(tempfile.gettempdir(), filename)
|
||||
with open(download_file_path, "w") as download_file:
|
||||
with open(download_file_path, "wb") as download_file:
|
||||
download_file.write(response.content)
|
||||
self._logger.debug(str(download_file_path) + " successfully downloaded")
|
||||
|
||||
|
|
@ -1053,7 +1069,7 @@ class LookupLib(object):
|
|||
download_file = gzip.open(download_file_path, "r")
|
||||
try:
|
||||
cty_file_path = os.path.join(os.path.splitext(download_file_path)[0])
|
||||
with open(cty_file_path, "w") as cty_file:
|
||||
with open(cty_file_path, "wb") as cty_file:
|
||||
cty_file.write(download_file.read())
|
||||
self._logger.debug(str(cty_file_path) + " successfully extracted")
|
||||
finally:
|
||||
|
|
@ -1418,7 +1434,7 @@ class LookupLib(object):
|
|||
"""
|
||||
Generates a random word
|
||||
"""
|
||||
return ''.join(random.choice(string.lowercase) for i in xrange(length))
|
||||
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
|
||||
|
||||
def _check_html_response(self, response):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from future.utils import iteritems
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ def get_lotw_users(**kwargs):
|
|||
|
||||
Raises:
|
||||
IOError: When network is unavailable, file can't be downloaded or processed
|
||||
|
||||
|
||||
ValueError: Raised when data from file can't be read
|
||||
|
||||
Example:
|
||||
|
|
@ -29,29 +30,29 @@ def get_lotw_users(**kwargs):
|
|||
>>> mydict = get_lotw_users()
|
||||
>>> mydict['DH1TW']
|
||||
datetime.datetime(2014, 9, 7, 0, 0)
|
||||
|
||||
|
||||
.. _ARRL: http://www.arrl.org/logbook-of-the-world
|
||||
__ ARRL_
|
||||
__ ARRL_
|
||||
|
||||
"""
|
||||
|
||||
|
||||
url = ""
|
||||
|
||||
|
||||
lotw = {}
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
url = kwargs['url']
|
||||
except KeyError:
|
||||
# url = "http://wd5eae.org/LoTW_Data.txt"
|
||||
url = "https://lotw.arrl.org/lotw-user-activity.csv"
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
result = requests.get(url)
|
||||
except (ConnectionError, HTTPError, Timeout) as e:
|
||||
raise IOError(e)
|
||||
|
||||
error_count = 0
|
||||
|
||||
|
||||
if result.status_code == requests.codes.ok:
|
||||
for el in result.text.split():
|
||||
data = el.split(",")
|
||||
|
|
@ -62,7 +63,7 @@ def get_lotw_users(**kwargs):
|
|||
if error_count > 10:
|
||||
raise ValueError("more than 10 wrongly formatted datasets " + str(e))
|
||||
|
||||
else:
|
||||
else:
|
||||
raise IOError("HTTP Error: " + str(result.status_code))
|
||||
|
||||
return lotw
|
||||
|
|
@ -75,7 +76,7 @@ def get_clublog_users(**kwargs):
|
|||
|
||||
Returns:
|
||||
dict: Dictionary containing (if data available) the fields:
|
||||
firstqso, lastqso, last-lotw, lastupload (datetime),
|
||||
firstqso, lastqso, last-lotw, lastupload (datetime),
|
||||
locator (string) and oqrs (boolean)
|
||||
|
||||
Raises:
|
||||
|
|
@ -94,25 +95,25 @@ def get_clublog_users(**kwargs):
|
|||
'oqrs': True}
|
||||
|
||||
.. _CLUBLOG: https://secure.clublog.org
|
||||
__ CLUBLOG_
|
||||
__ CLUBLOG_
|
||||
|
||||
"""
|
||||
|
||||
|
||||
url = ""
|
||||
|
||||
|
||||
clublog = {}
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
url = kwargs['url']
|
||||
except KeyError:
|
||||
url = "https://secure.clublog.org/clublog-users.json.zip"
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
result = requests.get(url)
|
||||
except (ConnectionError, HTTPError, Timeout) as e:
|
||||
raise IOError(e)
|
||||
|
||||
|
||||
|
||||
if result.status_code != requests.codes.ok:
|
||||
raise IOError("HTTP Error: " + str(result.status_code))
|
||||
|
||||
|
|
@ -124,12 +125,12 @@ def get_clublog_users(**kwargs):
|
|||
|
||||
error_count = 0
|
||||
|
||||
for call, call_data in cl_data.iteritems():
|
||||
for call, call_data in iteritems(cl_data):
|
||||
try:
|
||||
data = {}
|
||||
if "firstqso" in call_data:
|
||||
if call_data["firstqso"] != None:
|
||||
data["firstqso"] = datetime.strptime(call_data["firstqso"], '%Y-%m-%d %H:%M:%S')
|
||||
data["firstqso"] = datetime.strptime(call_data["firstqso"], '%Y-%m-%d %H:%M:%S')
|
||||
if "lastqso" in call_data:
|
||||
if call_data["lastqso"] != None:
|
||||
data["lastqso"] = datetime.strptime(call_data["lastqso"], '%Y-%m-%d %H:%M:%S')
|
||||
|
|
@ -172,26 +173,26 @@ def get_eqsl_users(**kwargs):
|
|||
|
||||
>>> from pyhamtools.qsl import get_eqsl_users
|
||||
>>> mylist = get_eqsl_users()
|
||||
>>> try:
|
||||
>>> try:
|
||||
>>> mylist.index('DH1TW')
|
||||
>>> except ValueError as e:
|
||||
>>> print e
|
||||
'DH1TW' is not in list
|
||||
|
||||
|
||||
.. _here: http://www.eqsl.cc/QSLCard/DownloadedFiles/AGMemberlist.txt
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
url = ""
|
||||
|
||||
|
||||
eqsl = []
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
url = kwargs['url']
|
||||
except KeyError:
|
||||
url = "http://www.eqsl.cc/QSLCard/DownloadedFiles/AGMemberlist.txt"
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
result = requests.get(url)
|
||||
except (ConnectionError, HTTPError, Timeout) as e:
|
||||
raise IOError(e)
|
||||
|
|
@ -199,7 +200,7 @@ def get_eqsl_users(**kwargs):
|
|||
if result.status_code == requests.codes.ok:
|
||||
eqsl = re.sub("^List.+UTC", "", result.text)
|
||||
eqsl = eqsl.upper().split()
|
||||
else:
|
||||
else:
|
||||
raise IOError("HTTP Error: " + str(result.status_code))
|
||||
|
||||
return eqsl
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
sphinxcontrib-napoleon>=0.6.1
|
||||
requests>=2.18.4
|
||||
pytz>=2017.3
|
||||
pyephem>=3.7.6.0
|
||||
redis>=2.10.6
|
||||
beautifulsoup4>=4.6.0
|
||||
|
||||
2
requirements-docs.txt
Normal file
2
requirements-docs.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
sphinx>=1.6.6
|
||||
sphinxcontrib-napoleon>=0.6.1
|
||||
3
requirements-pytest.txt
Normal file
3
requirements-pytest.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pytest>=3.3.2
|
||||
pytest-blockage>=0.2.0
|
||||
pytest-localserver>=0.4.1
|
||||
15
setup.py
15
setup.py
|
|
@ -2,17 +2,11 @@
|
|||
import sys
|
||||
import os
|
||||
from distutils.core import setup
|
||||
# from pyhamtools import __version__, __release__
|
||||
|
||||
kw = {}
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
kw['use_2to3'] = True
|
||||
|
||||
exec(open(os.path.join("pyhamtools","version.py")).read())
|
||||
|
||||
# from pyhamtools import __version__, __release__
|
||||
|
||||
setup(name='pyhamtools',
|
||||
version=__release__,
|
||||
description='Collection of Tools for Amateur Radio developers',
|
||||
|
|
@ -22,10 +16,11 @@ setup(name='pyhamtools',
|
|||
package_data={'': ['countryfilemapping.json']},
|
||||
packages=['pyhamtools'],
|
||||
install_requires=[
|
||||
"pytz",
|
||||
"requests",
|
||||
"pyephem",
|
||||
"beautifulsoup4",
|
||||
"pytz>=2017.3",
|
||||
"requests>=2.18.4",
|
||||
"pyephem>=3.7.6.0",
|
||||
"beautifulsoup4>=4.6.0",
|
||||
"future>=0.16.0",
|
||||
],
|
||||
**kw
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
2
test/fixtures/lotw_fixture.py
vendored
2
test/fixtures/lotw_fixture.py
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
14
tox.ini
14
tox.ini
|
|
@ -1,14 +0,0 @@
|
|||
# Tox (http://tox.testrun.org/) is a tool for running tests
|
||||
# in multiple virtualenvs. This configuration file will run the
|
||||
# test suite on all supported python versions. To use it, "pip install tox"
|
||||
# and then run "tox" from this directory.
|
||||
|
||||
[tox]
|
||||
envlist = py26,py27,pypy
|
||||
|
||||
[testenv]
|
||||
#deps=-rtox_requirements.txt
|
||||
deps=pytest
|
||||
commands =
|
||||
py.test \
|
||||
{posargs}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
pyephem (3.7.5.3)
|
||||
Pygments (1.6)
|
||||
pytz (2014.2)
|
||||
redis (2.10.3)
|
||||
requests (2.2.1)
|
||||
Loading…
Reference in a new issue