mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2026-04-21 06:13:57 +00:00
changed to pytz to datetime.timezone
This commit is contained in:
parent
3853248056
commit
0368988366
12 changed files with 112 additions and 158 deletions
|
|
@ -1,14 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
|
||||
from pyhamtools.consts import LookupConventions as const
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
|
||||
response_prefix_DH_clublog = {
|
||||
'country': 'FEDERAL REPUBLIC OF GERMANY',
|
||||
'adif': 230,
|
||||
|
|
@ -389,7 +385,7 @@ class Test_callinfo_methods:
|
|||
if fix_callinfo._lookuplib._lookuptype == "clublogxml" or fix_callinfo._lookuplib._lookuptype == "clublogapi":
|
||||
assert fix_callinfo.get_all("DH1TW") == response_prefix_DH_clublog
|
||||
assert fix_callinfo.get_all("ci8aw") == response_zone_exception_ci8aw
|
||||
timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC)
|
||||
timestamp = datetime(year=2016, month=1, day=20, tzinfo=timezone.utc)
|
||||
assert fix_callinfo.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date
|
||||
|
||||
elif fix_callinfo._lookuplib._lookuptype == "countryfile":
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
import pytz
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from pyhamtools.consts import LookupConventions as const
|
||||
from pyhamtools.dxcluster import decode_char_spot, decode_pc11_message, decode_pc61_message
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
fix_spot1 = "DX de CT3FW: 21004.8 HC2AO 599 TKS(CW)QSL READ,QRZ.COM 2132Z"
|
||||
fix_spot1_broken_spotter_call = "DX de $QRM: 21004.8 HC2AO 599 TKS(CW)QSL READ,QRZ.COM 2132Z"
|
||||
|
||||
|
|
@ -34,7 +28,7 @@ response_spot1 = {
|
|||
const.BAND: 15,
|
||||
const.MODE: "CW",
|
||||
const.COMMENT: "599 TKS(CW)QSL READ,QRZ.COM",
|
||||
const.TIME: datetime.utcnow().replace( hour=21, minute=32, second=0, microsecond = 0, tzinfo=UTC)
|
||||
const.TIME: datetime.now(timezone.utc).replace(hour=21, minute=32, second=0, microsecond = 0)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
|
||||
from pyhamtools.locator import calculate_sunrise_sunset
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
class Test_calculate_sunrise_sunset_normal_case():
|
||||
|
||||
def test_calculate_sunrise_sunset(self):
|
||||
|
|
@ -14,11 +11,11 @@ class Test_calculate_sunrise_sunset_normal_case():
|
|||
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)
|
||||
result_JN48QM_1_1_2014_sunrise = datetime(2014, 1, 1, 7, 14, tzinfo=UTC)
|
||||
result_JN48QM_1_1_2014_sunset = datetime(2014, 1, 1, 16, 15, 23, 31016, tzinfo=UTC)
|
||||
test_time = datetime(year=2014, month=1, day=1, tzinfo=timezone.utc)
|
||||
result_JN48QM_1_1_2014_evening_dawn = datetime(2014, 1, 1, 15, 38, tzinfo=timezone.utc)
|
||||
result_JN48QM_1_1_2014_morning_dawn = datetime(2014, 1, 1, 6, 36, tzinfo=timezone.utc)
|
||||
result_JN48QM_1_1_2014_sunrise = datetime(2014, 1, 1, 7, 14, tzinfo=timezone.utc)
|
||||
result_JN48QM_1_1_2014_sunset = datetime(2014, 1, 1, 16, 15, 23, 31016, tzinfo=timezone.utc)
|
||||
|
||||
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
|
||||
|
|
@ -33,7 +30,7 @@ class Test_calculate_sunrise_sunset_normal_case():
|
|||
# The sun never rises in winter time close to the north pole (e.g. at Jan Mayen)
|
||||
# Therefore we expect no sunrise or sunset.
|
||||
|
||||
test_time = datetime(year=2021, month=12, day=15, tzinfo=UTC)
|
||||
test_time = datetime(year=2021, month=12, day=15, tzinfo=timezone.utc)
|
||||
|
||||
assert calculate_sunrise_sunset(locator, test_time)['morning_dawn'] == None
|
||||
assert calculate_sunrise_sunset(locator, test_time)['evening_dawn'] == None
|
||||
|
|
@ -48,7 +45,7 @@ class Test_calculate_sunrise_sunset_normal_case():
|
|||
# The sun never sets at the south pole during arctic summer
|
||||
# Therefore we expect no sunrise or sunset.
|
||||
|
||||
test_time = datetime(year=2014, month=1, day=1, tzinfo=UTC)
|
||||
test_time = datetime(year=2014, month=1, day=1, tzinfo=timezone.utc)
|
||||
|
||||
assert calculate_sunrise_sunset(locator, test_time)['morning_dawn'] == None
|
||||
assert calculate_sunrise_sunset(locator, test_time)['evening_dawn'] == None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class TestclublogApi_Getters:
|
|||
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=4, day=14)
|
||||
d = datetime.now(timezone.utc).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
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
from datetime import datetime, timezone
|
||||
import os
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
from pyhamtools.exceptions import APIKeyMissingError
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
|
||||
#Fixtures
|
||||
#===========================================================
|
||||
|
|
@ -142,40 +139,40 @@ class TestclublogXML_Getters:
|
|||
#===============================
|
||||
|
||||
def test_lookup_callsign_same_callsign_different_exceptions(self, fixClublogXML):
|
||||
timestamp = datetime(year=1990, month=10, day=12, tzinfo=UTC)
|
||||
timestamp = datetime(year=1990, month=10, day=12, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1990
|
||||
|
||||
timestamp = datetime(year=1992, month=3, day=8, tzinfo=UTC)
|
||||
timestamp = datetime(year=1992, month=3, day=8, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1992
|
||||
|
||||
def test_lookup_callsign_exception_only_with_start_date(self, fixClublogXML):
|
||||
#timestamp > startdate
|
||||
timestamp = datetime(year=1962, month=7, day=7, tzinfo=UTC)
|
||||
timestamp = datetime(year=1962, month=7, day=7, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_callsign("vk9xo", timestamp) == response_Exception_VK9XO_with_start_date
|
||||
assert fixClublogXML.lookup_callsign("vk9xo") == response_Exception_VK9XO_with_start_date
|
||||
|
||||
#timestamp < startdate
|
||||
timestamp = datetime(year=1962, month=7, day=5, tzinfo=UTC)
|
||||
timestamp = datetime(year=1962, month=7, day=5, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_callsign("vk9xo", timestamp)
|
||||
|
||||
def test_lookup_callsign_exception_only_with_end_date(self, fixClublogXML):
|
||||
|
||||
#timestamp < enddate
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=UTC)
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_callsign("vk9xx", timestamp) == response_Exception_VK9XX_with_end_date
|
||||
|
||||
# timestamp > enddate
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_callsign("vk9xx")
|
||||
|
||||
timestamp = datetime(year=1975, month=9, day=16, tzinfo=UTC)
|
||||
timestamp = datetime(year=1975, month=9, day=16, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_callsign("vk9xx", timestamp)
|
||||
|
||||
def test_lookup_callsign_exception_no_start_nor_end_date(self, fixClublogXML):
|
||||
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=UTC)
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_callsign("ax9nyg", timestamp) == response_Exception_AX9NYG
|
||||
assert fixClublogXML.lookup_callsign("ax9nyg" ) == response_Exception_AX9NYG
|
||||
|
||||
|
|
@ -196,29 +193,29 @@ class TestclublogXML_Getters:
|
|||
|
||||
def test_lookup_prefix_with_changing_entities(self, fixClublogXML):
|
||||
#return old entity (PAPUA TERR)
|
||||
timestamp = datetime(year=1975, month=9, day=14).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_prefix("VK9", timestamp) == response_Prefix_VK9_until_1975
|
||||
|
||||
#return empty dict - Prefix was not assigned at that time
|
||||
timestamp = datetime(year=1975, month=9, day=16).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1975, month=9, day=16, tzinfo=timezone.utc)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_prefix("VK9", timestamp)
|
||||
|
||||
#return new entity (Norfolk Island)
|
||||
timestamp = datetime.utcnow().replace(tzinfo=UTC)
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
assert fixClublogXML.lookup_prefix("VK9", timestamp ) == response_Prefix_VK9_starting_1976
|
||||
|
||||
def test_lookup_prefix_with_entities_having_start_and_stop(self, fixClublogXML):
|
||||
|
||||
timestamp_before = datetime(year=1964, month=11, day=1).replace(tzinfo=UTC)
|
||||
timestamp_before = datetime(year=1964, month=11, day=1, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_prefix("ZD5", timestamp_before)
|
||||
|
||||
timestamp_valid = datetime(year=1964, month=12, day=2).replace(tzinfo=UTC)
|
||||
timestamp_valid = datetime(year=1964, month=12, day=2, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_prefix("ZD5", timestamp_valid) == response_Prefix_ZD5_1964_to_1971
|
||||
|
||||
timestamp_after = datetime(year=1971, month=8, day=1).replace(tzinfo=UTC)
|
||||
timestamp_after = datetime(year=1971, month=8, day=1, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_prefix("ZD5", timestamp_after)
|
||||
|
||||
|
|
@ -234,8 +231,8 @@ class TestclublogXML_Getters:
|
|||
fixClublogXML.is_invalid_operation("dh1tw")
|
||||
|
||||
#Invalid Operation with start and end date
|
||||
timestamp_before = datetime(year=1993, month=12, day=30).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1994, month=12, day=30).replace(tzinfo=UTC)
|
||||
timestamp_before = datetime(year=1993, month=12, day=30, tzinfo=timezone.utc)
|
||||
timestamp = datetime(year=1994, month=12, day=30, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.is_invalid_operation("vk0mc")
|
||||
|
||||
|
|
@ -246,7 +243,7 @@ class TestclublogXML_Getters:
|
|||
|
||||
#Invalid Operation with start date
|
||||
assert fixClublogXML.is_invalid_operation("5W1CFN")
|
||||
timestamp_before = datetime(year=2012, month=1, day=31).replace(tzinfo=UTC)
|
||||
timestamp_before = datetime(year=2012, month=1, day=31, tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.is_invalid_operation("5W1CFN", timestamp_before)
|
||||
|
||||
|
|
@ -264,9 +261,9 @@ class TestclublogXML_Getters:
|
|||
assert fixClublogXML.lookup_zone_exception("dp0gvn") == 38
|
||||
|
||||
#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=3, day=1).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1992, month=10, day=2, tzinfo=timezone.utc)
|
||||
timestamp_before = datetime(year=1992, month=9, day=30, tzinfo=timezone.utc)
|
||||
timestamp_after = datetime(year=1993, month=3, day=1, tzinfo=timezone.utc)
|
||||
assert fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp) == 38
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
|
|
@ -276,6 +273,6 @@ class TestclublogXML_Getters:
|
|||
fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp_after)
|
||||
|
||||
#zone exception with start date
|
||||
timestamp_before = datetime(year=2013, month=12, day=26).replace(tzinfo=UTC)
|
||||
timestamp_before = datetime(year=2013, month=12, day=26,tzinfo=timezone.utc)
|
||||
with pytest.raises(KeyError):
|
||||
fixClublogXML.lookup_zone_exception("dh1hb/p", timestamp_before)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
from pyhamtools.exceptions import APIKeyMissingError
|
||||
from pyhamtools.consts import LookupConventions as const
|
||||
|
||||
import pytz
|
||||
UTC = pytz.UTC
|
||||
|
||||
|
||||
try:
|
||||
QRZ_USERNAME = str(os.environ['QRZ_USERNAME'])
|
||||
QRZ_PWD = str(os.environ['QRZ_PWD'])
|
||||
|
|
@ -21,10 +17,10 @@ except Exception:
|
|||
#===========================================================
|
||||
|
||||
response_1A1AB = {
|
||||
u'biodate': datetime(2018, 9, 7, 21, 17, 7, tzinfo=UTC),
|
||||
u'biodate': datetime(2018, 9, 7, 21, 17, 7, tzinfo=timezone.utc),
|
||||
u'bio': u'0',
|
||||
u'license_class': u'C',
|
||||
u'moddate': datetime(2008, 11, 2, 15, 0, 38, tzinfo=UTC),
|
||||
u'moddate': datetime(2008, 11, 2, 15, 0, 38, tzinfo=timezone.utc),
|
||||
u'locator': u'JN61fw',
|
||||
u'callsign': u'1A1AB',
|
||||
u'addr2': u'00187 Rome',
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
import pytest
|
||||
import json
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytz
|
||||
import redis
|
||||
|
||||
from pyhamtools import LookupLib, Callinfo
|
||||
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
r = redis.Redis()
|
||||
|
||||
|
||||
|
|
@ -44,7 +40,7 @@ class TestStoreDataInRedis:
|
|||
with pytest.raises(KeyError):
|
||||
fix_redis.is_invalid_operation("VK0MC")
|
||||
|
||||
timestamp = datetime(year=1994, month=12, day=30).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1994, month=12, day=30, tzinfo=timezone.utc)
|
||||
assert fix_redis.is_invalid_operation("VK0MC", timestamp)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
|
|
@ -61,7 +57,7 @@ class TestStoreDataInRedis:
|
|||
assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
|
||||
|
||||
def test_redis_lookup(self, fixClublogXML, fix_redis):
|
||||
timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC)
|
||||
timestamp = datetime(year=2016, month=1, day=20, tzinfo=timezone.utc)
|
||||
ci = Callinfo(fix_redis)
|
||||
assert ci.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date
|
||||
assert ci.get_all("tu5pct") == response_TU5PCT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue