From d944d9b045968a402190640ee03e1009472f4451 Mon Sep 17 00:00:00 2001 From: Dawid SQ6EMM Date: Mon, 5 May 2025 10:19:53 +0200 Subject: [PATCH] Add tests Signed-off-by: Dawid SQ6EMM --- pyhamtools/locator.py | 20 ++++++++++---------- requirements-pytest.txt | 6 +++++- test.py | 14 ++++++++++++++ test/test_locator_latlong_to_locator.py | 4 ++-- 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 test.py diff --git a/pyhamtools/locator.py b/pyhamtools/locator.py index a37c7ea..467adf8 100644 --- a/pyhamtools/locator.py +++ b/pyhamtools/locator.py @@ -73,7 +73,7 @@ def locator_to_latlong (locator, center=True): """converts Maidenhead locator in the corresponding WGS84 coordinates Args: - locator (string): Locator, either 4, 6 or 8 characters + locator (string): Locator, either 4, 6, 8 or 10 characters center (bool): Center of (sub)square. By default True. If False, the south/western corner will be returned Returns: @@ -186,8 +186,8 @@ def calculate_distance(locator1, locator2): """calculates the (shortpath) distance between two Maidenhead locators Args: - locator1 (string): Locator, either 4, 6 or 8 characters - locator2 (string): Locator, either 4, 6 or 8 characters + locator1 (string): Locator, either 4, 6, 8 or 10 characters + locator2 (string): Locator, either 4, 6, 8 or 10 characters Returns: float: Distance in km @@ -231,8 +231,8 @@ def calculate_distance_longpath(locator1, locator2): """calculates the (longpath) distance between two Maidenhead locators Args: - locator1 (string): Locator, either 4, 6 or 8 characters - locator2 (string): Locator, either 4, 6 or 8 characters + locator1 (string): Locator, either 4, 6, 8 or 10 characters + locator2 (string): Locator, either 4, 6, 8 or 10 characters Returns: float: Distance in km @@ -262,8 +262,8 @@ def calculate_heading(locator1, locator2): """calculates the heading from the first to the second locator Args: - locator1 (string): Locator, either 4, 6 or 8 characters - locator2 (string): Locator, either 4, 6 or 6 characters + locator1 (string): Locator, either 4, 6, 8 or 10 characters + locator2 (string): Locator, either 4, 6, 8 or 10 characters Returns: float: Heading in deg @@ -305,8 +305,8 @@ def calculate_heading_longpath(locator1, locator2): """calculates the heading from the first to the second locator (long path) Args: - locator1 (string): Locator, either 4, 6 or 8 characters - locator2 (string): Locator, either 4, 6 or 8 characters + locator1 (string): Locator, either 4, 6, 8 or 10 characters + locator2 (string): Locator, either 4, 6, 8 or 10 characters Returns: float: Long path heading in deg @@ -337,7 +337,7 @@ def calculate_sunrise_sunset(locator, calc_date=None): """calculates the next sunset and sunrise for a Maidenhead locator at a give date & time Args: - locator1 (string): Maidenhead Locator, either 4, 6 or 8 characters + locator1 (string): Maidenhead Locator, either 4, 6, 8 or 10 characters calc_date (datetime, optional): Starting datetime for the calculations (UTC) Returns: diff --git a/requirements-pytest.txt b/requirements-pytest.txt index f0acaa0..ede0b9b 100644 --- a/requirements-pytest.txt +++ b/requirements-pytest.txt @@ -3,4 +3,8 @@ pytest==4.6.11; python_version=='3.6' pytest-blockage>=0.2.2 pytest-localserver>=0.5 pytest-cov>=2.12 -maidenhead==1.6.0 \ No newline at end of file +maidenhead==1.6.0 +requests +bs4 +redis +ephem diff --git a/test.py b/test.py new file mode 100644 index 0000000..c11b8ce --- /dev/null +++ b/test.py @@ -0,0 +1,14 @@ +from pyhamtools.locator import latlong_to_locator +from pyhamtools.locator import locator_to_latlong + +print("51.12492, 16.94183") +print(latlong_to_locator(51.124913194444446, 16.94184027777778,10)) +print(latlong_to_locator(51.12492, 16.94183,10)) + +print("JO81LC39AX") +print(locator_to_latlong("JO81LC39AX")) + +b="MN45GU30AN" +print(b) +print(locator_to_latlong(b)) +print(latlong_to_locator(45.83568,68.52518,10)) diff --git a/test/test_locator_latlong_to_locator.py b/test/test_locator_latlong_to_locator.py index a9734ef..85b357a 100644 --- a/test/test_locator_latlong_to_locator.py +++ b/test/test_locator_latlong_to_locator.py @@ -24,8 +24,8 @@ class Test_latlong_to_locator(): assert latlong_to_locator(39.222916, -86.45416, 8) == "EM69SF53" def test_latlong_to_locator_10chars_precision(self): - assert latlong_to_locator(45.83568, 68.52518, precision=10) == "MN45GU30AN" - assert latlong_to_locator(51.12492, 16.94183, 10) == "JO81LC39AX" + assert latlong_to_locator(45.835677, 68.525173, precision=10) == "MN45GU30AN" + assert latlong_to_locator(51.124913, 16.941840, 10) == "JO81LC39AX" def test_latlong_to_locator_invalid_characters(self):