From 61f3f00e79945f851e2f03908114dc089270b436 Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 14 Feb 2024 22:59:07 -0500 Subject: [PATCH] Unit tests working except one, switching back to main to investigate --- modules/common | 2 +- .../load_waypoint_name_to_coordinates_map.py | 6 +-- modules/waypoint.py | 52 ------------------- modules/waypoint_names_to_coordinates.py | 14 ++--- modules/waypoints_dict_to_list.py | 8 +-- modules/waypoints_to_commands.py | 8 +-- path_2023.py | 4 +- path_2024.py | 4 +- ...t_load_waypoint_name_to_coordinates_map.py | 6 +-- tests/test_waypoints_dict_to_list.py | 8 +-- tests/test_waypoints_names_to_coordinates.py | 22 ++++---- tests/test_waypoints_to_commands.py | 8 +-- 12 files changed, 45 insertions(+), 97 deletions(-) delete mode 100644 modules/waypoint.py diff --git a/modules/common b/modules/common index c780f36..c1f343f 160000 --- a/modules/common +++ b/modules/common @@ -1 +1 @@ -Subproject commit c780f36cd1bd6877b70d04318480deb29d4ddb6e +Subproject commit c1f343ff258d2ba493dc8bc283dc95d855dd63e7 diff --git a/modules/load_waypoint_name_to_coordinates_map.py b/modules/load_waypoint_name_to_coordinates_map.py index fe97c6f..3f93c38 100644 --- a/modules/load_waypoint_name_to_coordinates_map.py +++ b/modules/load_waypoint_name_to_coordinates_map.py @@ -3,11 +3,11 @@ """ import pathlib -from . import waypoint +from .common.kml.modules import location_ground def load_waypoint_name_to_coordinates_map(waypoint_file_path: pathlib.Path) \ - -> "tuple[bool, dict[str, waypoint.Waypoint]]": + -> "tuple[bool, dict[str, location_ground.LocationGround]]": """ Creates a name to coordinate dictionary from the CSV file. """ @@ -23,7 +23,7 @@ def load_waypoint_name_to_coordinates_map(waypoint_file_path: pathlib.Path) \ continue name, latitude, longitude = parts - name_to_coordinates_map[name] = waypoint.Waypoint(name, float(latitude), float(longitude)) + name_to_coordinates_map[name] = location_ground.LocationGround(name, float(latitude), float(longitude)) if len(name_to_coordinates_map) > 0: return True, name_to_coordinates_map diff --git a/modules/waypoint.py b/modules/waypoint.py deleted file mode 100644 index caa01a1..0000000 --- a/modules/waypoint.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Class Waypoint to use instead of tuple for coordinates. -""" - -class Waypoint: - """ - Waypoint class represents a geographical waypoint with a name, latitude, and longitude. - - Attributes: - name (str): The name or label for the waypoint. - latitude (float): The latitude coordinate of the waypoint in decimal degrees. - longitude (float): The longitude coordinate of the waypoint in decimal degrees. - - Methods: - __init__(name, latitude, longitude): Initializes a Waypoint object. - __eq__(other): Checks if two Waypoint objects are equal. - __repr__(): Returns a string representation of the Waypoint object. - """ - def __init__(self, name: str, latitude: float, longitude: float): - """ - Constructor for the Waypoint object. - - Args: - name (str): The name or label for the waypoint. - latitude (float): The latitude coordinate of the waypoint in decimal degrees. - longitude (float): The longitude coordinate of the waypoint in decimal degrees. - """ - self.name = name - self.latitude = latitude - self.longitude = longitude - - def __eq__(self, other: "Waypoint"): - """ - Checks if two Waypoint objects are equal. - - Args: - other (Waypoint): The other Waypoint object to compare to. - """ - if not isinstance(other, Waypoint): - return False - - return ( - self.name == other.name - and self.latitude == other.latitude - and self.longitude == other.longitude - ) - - def __repr__(self): - """ - Returns a string representation of the Waypoint object. - """ - return f"Waypoint: {self.name}, latitude: {self.latitude}, longitude: {self.longitude})" diff --git a/modules/waypoint_names_to_coordinates.py b/modules/waypoint_names_to_coordinates.py index d2ca824..87625d4 100644 --- a/modules/waypoint_names_to_coordinates.py +++ b/modules/waypoint_names_to_coordinates.py @@ -2,23 +2,23 @@ This file contains a function for converting waypoint names to coordinates. """ -from . import waypoint +from .common.kml.modules import location_ground def waypoint_names_to_coordinates(waypoint_names: "list[str]", - waypoint_mapping: "dict[str, waypoint.Waypoint]") \ - -> "tuple[bool, list[waypoint.Waypoint]]": + waypoint_mapping: "dict[str, location_ground.LocationGround]") \ + -> "tuple[bool, list[location_ground.LocationGround]]": """ Converts a list of waypoint names to their corresponding coordinates based on a waypoint mapping. Args: waypoint_names (list[str]): A list of waypoint names. - waypoint_mapping (dict[str, Waypoint]): A dictionary mapping waypoint names to their - corresponding Waypoint objects with coordinates. + waypoint_mapping (dict[str, LocationGround]): A dictionary mapping waypoint names to their + corresponding LocationGround objects with coordinates. Returns: - tuple[bool, list[Waypoint]]: A tuple containing a boolean indicating the success of the conversion - and a list of Waypoint objects with coordinates corresponding to the given waypoint names. + tuple[bool, list[LocationGround]]: A tuple containing a boolean indicating the success of the conversion + and a list of LocationGround objects with coordinates corresponding to the given waypoint names. """ # Handle the case when waypoint_names is empty if len(waypoint_names) == 0: diff --git a/modules/waypoints_dict_to_list.py b/modules/waypoints_dict_to_list.py index 408a9a6..73de04f 100644 --- a/modules/waypoints_dict_to_list.py +++ b/modules/waypoints_dict_to_list.py @@ -2,17 +2,17 @@ Module to convert waypoints dict to waypoints list. """ -from . import waypoint +from .common.kml.modules import location_ground -def waypoints_dict_to_list(waypoint_name_to_coordinates: "dict[str, waypoint.Waypoint]") \ - -> "tuple[bool, list[waypoint.Waypoint]]": +def waypoints_dict_to_list(waypoint_name_to_coordinates: "dict[str, location_ground.LocationGround]") \ + -> "tuple[bool, list[location_ground.LocationGround]]": """ Converts dictionary of waypoints into a list. Parameters ---------- - waypoint_name_to_coordinates: dict[str, Waypoint] + waypoint_name_to_coordinates: dict[str, LocationGround] Waypoint mapping of name to (latitude, longitude). Returns diff --git a/modules/waypoints_to_commands.py b/modules/waypoints_to_commands.py index 76514f0..6f3911a 100644 --- a/modules/waypoints_to_commands.py +++ b/modules/waypoints_to_commands.py @@ -4,7 +4,7 @@ import dronekit -from . import waypoint +from .common.kml.modules import location_ground MAVLINK_FRAME = dronekit.mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT @@ -12,15 +12,15 @@ ACCEPT_RADIUS = 10 -def waypoints_to_commands(waypoints: "list[waypoint.Waypoint]", +def waypoints_to_commands(waypoints: "list[location_ground.LocationGround]", altitude: int) -> "tuple[bool, list[dronekit.Command] | None]": """ Convert list of waypoints to dronekit commands. Parameters ---------- - waypoints: list[Waypoint] - list of Waypoint objects containing names and coordinates in decimal degrees. + waypoints: list[LocationGround] + list of locationGround objects containing names and coordinates in decimal degrees. altitude: int altitude in meters to command the drone to. diff --git a/path_2023.py b/path_2023.py index 6516f53..000ba94 100644 --- a/path_2023.py +++ b/path_2023.py @@ -15,7 +15,7 @@ from modules import waypoint_tracking from modules import waypoints_dict_to_list from modules import waypoints_to_commands -from modules.common.kml.modules import waypoints_to_kml +from modules.common.kml.modules import ground_locations_to_kml WAYPOINT_FILE_PATH = pathlib.Path("waypoints", "wrestrc_waypoints.csv") @@ -53,7 +53,7 @@ def run() -> int: # TODO: Remove tuple conversion when common repository's waypoint_to_kml() supports Waypoint class waypoints_list_tuple = [(waypoint.latitude, waypoint.longitude) for waypoint in waypoints_list] - result, _ = waypoints_to_kml.waypoints_to_kml( + result, _ = ground_locations_to_kml.ground_locations_to_kml( waypoints_list_tuple, KML_FILE_PREFIX, KML_FILE_PARENT_DIRECTORY, ) diff --git a/path_2024.py b/path_2024.py index 85349d8..fd310ac 100644 --- a/path_2024.py +++ b/path_2024.py @@ -12,7 +12,7 @@ from modules import waypoints_to_commands from modules import waypoint_tracking from modules import waypoints_dict_to_list -from modules.common.kml.modules import waypoints_to_kml +from modules.common.kml.modules import ground_locations_to_kml WAYPOINT_FILE_PATH = pathlib.Path("2024", "waypoints", "wrestrc.csv") @@ -51,7 +51,7 @@ def run() -> int: # TODO: Remove tuple conversion when common repository's waypoint_to_kml() supports Waypoint class waypoints_list_tuple = [(waypoint.latitude, waypoint.longitude) for waypoint in waypoints_list] - result, _ = waypoints_to_kml.waypoints_to_kml( + result, _ = ground_locations_to_kml.ground_locations_to_kml( waypoints_list_tuple, KML_FILE_PREFIX, KML_FILE_PARENT_DIRECTORY, ) diff --git a/tests/test_load_waypoint_name_to_coordinates_map.py b/tests/test_load_waypoint_name_to_coordinates_map.py index 99a5b88..bb1c2e9 100644 --- a/tests/test_load_waypoint_name_to_coordinates_map.py +++ b/tests/test_load_waypoint_name_to_coordinates_map.py @@ -4,7 +4,7 @@ import pathlib from modules import load_waypoint_name_to_coordinates_map -from modules import waypoint +from modules.common.kml.modules import location_ground def test_normal_file(): @@ -14,8 +14,8 @@ def test_normal_file(): # Setup normal_csv_file_path = pathlib.Path("tests", "test_csv", "test_normal_csv.csv") expected = { - "WARG": waypoint.Waypoint("WARG", 43.47323264522664, -80.54011639872981), - "University of Waterloo Station for 301 ION": waypoint.Waypoint( + "WARG": location_ground.LocationGround("WARG", 43.47323264522664, -80.54011639872981), + "University of Waterloo Station for 301 ION": location_ground.LocationGround( "University of Waterloo Station for 301 ION", 43.4735247614021, -80.54144667502672, diff --git a/tests/test_waypoints_dict_to_list.py b/tests/test_waypoints_dict_to_list.py index da90d70..95a43dd 100644 --- a/tests/test_waypoints_dict_to_list.py +++ b/tests/test_waypoints_dict_to_list.py @@ -2,17 +2,17 @@ Testing various formats of waypoints dictionary during conversion to list process. """ -from modules import waypoint from modules import waypoints_dict_to_list +from modules.common.kml.modules import location_ground def test_valid_waypoint_dict(): """ Test conversion to list for a valid dict. """ - alpha = waypoint.Waypoint("Alpha", 43.4340501,-80.5789803) - bravo = waypoint.Waypoint("Bravo", 43.4335758,-80.5775237) - charlie = waypoint.Waypoint("Charlie", 43.4336672,-80.57839) + alpha = location_ground.LocationGround("Alpha", 43.4340501,-80.5789803) + bravo = location_ground.LocationGround("Bravo", 43.4335758,-80.5775237) + charlie = location_ground.LocationGround("Charlie", 43.4336672,-80.57839) waypoint_mapping = {"Alpha": alpha, "Bravo": bravo, "Charlie": charlie} expected = [alpha, bravo, charlie] diff --git a/tests/test_waypoints_names_to_coordinates.py b/tests/test_waypoints_names_to_coordinates.py index cd5fc73..99b5510 100644 --- a/tests/test_waypoints_names_to_coordinates.py +++ b/tests/test_waypoints_names_to_coordinates.py @@ -2,18 +2,18 @@ Test waypoint names to coordinates function. """ -from modules import waypoint from modules import waypoint_names_to_coordinates +from modules.common.kml.modules import location_ground WAYPOINT_DICTIONARY = { - "Aerial": waypoint.Waypoint("Aerial", 9, 7), - "Group 15": waypoint.Waypoint("Group 15", 3, 4), - "Robotics": waypoint.Waypoint("Robotics", -1, 0), + "Aerial": location_ground.LocationGround("Aerial", 9, 7), + "Group 15": location_ground.LocationGround("Group 15", 3, 4), + "Robotics": location_ground.LocationGround("Robotics", -1, 0), "University of Waterloo Station for 301 ION": \ - waypoint.Waypoint("University of Waterloo Station for 301 ION", 6, 6), - "WARG": waypoint.Waypoint("WARG", 8, 2), - "Waterloo": waypoint.Waypoint("Waterloo", 2, -5), + location_ground.LocationGround("University of Waterloo Station for 301 ION", 6, 6), + "WARG": location_ground.LocationGround("WARG", 8, 2), + "Waterloo": location_ground.LocationGround("Waterloo", 2, -5), } @@ -24,10 +24,10 @@ def test_valid_names(): # Setup names_valid = ["Waterloo", "Aerial", "Robotics", "Group 15"] expected = [ - waypoint.Waypoint("Waterloo", 2, -5), - waypoint.Waypoint("Aerial", 9, 7), - waypoint.Waypoint("Robotics", -1, 0), - waypoint.Waypoint("Group 15", 3, 4), + location_ground.LocationGround("Waterloo", 2, -5), + location_ground.LocationGround("Aerial", 9, 7), + location_ground.LocationGround("Robotics", -1, 0), + location_ground.LocationGround("Group 15", 3, 4), ] # Run diff --git a/tests/test_waypoints_to_commands.py b/tests/test_waypoints_to_commands.py index 9eb7e56..c7cc5f1 100644 --- a/tests/test_waypoints_to_commands.py +++ b/tests/test_waypoints_to_commands.py @@ -4,8 +4,8 @@ import dronekit -from modules import waypoint from modules import waypoints_to_commands +from modules.common.kml.modules import location_ground def test_waypoints_to_commands_empty_input(): @@ -26,9 +26,9 @@ def test_waypoints_to_commands(): Tests functionality correctness of waypoints_to_commands. """ waypoints = [ - waypoint.Waypoint("Waypoint 1", 42.123, -73.456), - waypoint.Waypoint("Waypoint 2", 42.789, -73.987), - waypoint.Waypoint("Waypoint 3", 42.555, -73.321), + location_ground.LocationGround("Waypoint 1", 42.123, -73.456), + location_ground.LocationGround("Waypoint 2", 42.789, -73.987), + location_ground.LocationGround("Waypoint 3", 42.555, -73.321), ] altitude = 100