Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions radio/app/controllers/flightModesController.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def setCurrentFlightMode(self, flightMode: int) -> Response:
Args:
flightmode (int): The numeric value for the current flight mode setting
Returns:
A message to show if the drone recieved the message and succesfully set the new mode
A message to show if the drone received the message and successfully set the new mode
"""
if not self.drone.reserve_message_type("COMMAND_ACK", self.controller_id):
return {
Expand Down Expand Up @@ -185,7 +185,7 @@ def setGuidedMode(self) -> Response:
"""
Set the drone's flight mode to Guided mode.
Returns:
A message to show if the drone recieved the message and succesfully set the new mode
A message to show if the drone received the message and successfully set the new mode
"""

mode = mavutil.mavlink.COPTER_MODE_GUIDED
Expand Down
4 changes: 2 additions & 2 deletions radio/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __exit__(self, type, value, traceback) -> None:
droneStatus.drone.aircraft_type = self.old_aircraftType


def send_and_recieve(endpoint: str, args: Optional[Union[dict, str]] = None) -> dict:
def send_and_receive(endpoint: str, args: Optional[Union[dict, str]] = None) -> dict:
"""Sends a request to the socketio test client and returns the response

Parameters
Expand All @@ -115,7 +115,7 @@ def send_and_recieve(endpoint: str, args: Optional[Union[dict, str]] = None) ->
Returns
-------
dict
The data recieved from the client
The data received from the client
"""
(
socketio_client.emit(endpoint, args)
Expand Down
24 changes: 12 additions & 12 deletions radio/tests/test_comPorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import socketio_client
from .conftest import setupDrone
from .helpers import send_and_recieve
from .helpers import send_and_receive

VALID_DRONE_PORT: str

Expand Down Expand Up @@ -45,7 +45,7 @@ def get_comport_name(port):
def test_getComPort() -> None:
# TODO: we should automate different OS environments for our unit tests maybe?
assert (
send_and_recieve("get_com_ports")
send_and_receive("get_com_ports")
== [
f"{get_comport_name(port)}: {port.description}"
for port in list_ports.comports()
Expand All @@ -56,28 +56,28 @@ def test_getComPort() -> None:

def test_connectToDrone_badType() -> None:
# Failure on bad connection type
assert send_and_recieve("connect_to_drone", {}) == {
assert send_and_receive("connect_to_drone", {}) == {
"message": "Connection type not specified."
}
assert send_and_recieve("connect_to_drone", {"connectionType": "testtype"}) == {
assert send_and_receive("connect_to_drone", {"connectionType": "testtype"}) == {
"message": "Connection type not specified."
}


def test_connectToDrone_badPort() -> None:
# Failure on no port specified
assert send_and_recieve("connect_to_drone", {"connectionType": "serial"}) == {
assert send_and_receive("connect_to_drone", {"connectionType": "serial"}) == {
"message": "COM port not specified."
}
assert send_and_recieve("connect_to_drone", {"connectionType": "network"}) == {
assert send_and_receive("connect_to_drone", {"connectionType": "network"}) == {
"message": "Connection address not specified."
}

# Failure on bad port specified
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone", {"connectionType": "serial", "port": "testport"}
) == {"message": "COM port not found."}
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone", {"connectionType": "serial", "port": "COM10:5761"}
) == {"message": "COM port not found."}

Expand Down Expand Up @@ -139,25 +139,25 @@ def test_connectToDrone_badBaud() -> None:
)

# Failure on invalid baud rate value
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone",
{"connectionType": connectionType, "port": VALID_DRONE_PORT, "baud": -1},
) == {
"message": f"{-1} is an invalid baudrate. Valid baud rates are {Drone.getValidBaudrates()}"
}
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone",
{"connectionType": connectionType, "port": VALID_DRONE_PORT, "baud": 110},
) == {
"message": f"{110} is an invalid baudrate. Valid baud rates are {Drone.getValidBaudrates()}"
}

# Failure on invalid baud rate types
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone",
{"connectionType": connectionType, "port": VALID_DRONE_PORT, "baud": 9600.0},
) == {"message": "Expected integer value for baud, received float."}
assert send_and_recieve(
assert send_and_receive(
"connect_to_drone",
{"connectionType": connectionType, "port": VALID_DRONE_PORT, "baud": "9600"},
) == {"message": "Expected integer value for baud, received str."}
Expand Down
24 changes: 12 additions & 12 deletions radio/tests/test_gripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pymavlink import mavutil

from . import falcon_test
from .helpers import FakeTCP, NoDrone, send_and_recieve
from .helpers import FakeTCP, NoDrone, send_and_receive


@pytest.fixture(scope="module", autouse=True)
Expand All @@ -32,56 +32,56 @@ def run_once_after_all_tests():
def test_gripperEnabled(socketio_client: SocketIOTestClient, droneStatus):
# Failure on wrong drone state
droneStatus.state = "params"
assert send_and_recieve("get_gripper_enabled") == {
assert send_and_receive("get_gripper_enabled") == {
"message": "You must be on the config screen to access the gripper."
}

# Failure with no drone connected
droneStatus.state = "config"
with NoDrone():
assert send_and_recieve("get_gripper_enabled") == {
assert send_and_receive("get_gripper_enabled") == {
"message": "You must be connected to the drone to access the gripper."
}

# Correct result on config page
assert send_and_recieve("get_gripper_enabled") is True
assert send_and_receive("get_gripper_enabled") is True


@falcon_test(pass_drone_status=True)
def test_setGripper(socketio_client: SocketIOTestClient, droneStatus):
# Failure on wrong drone state
droneStatus.state = "params"
assert send_and_recieve("set_gripper", "release") == {
assert send_and_receive("set_gripper", "release") == {
"message": "You must be on the config screen to access the gripper."
}

# Failure with no drone connected
droneStatus.state = "config"
with NoDrone():
assert send_and_recieve("set_gripper", "release") == {
assert send_and_receive("set_gripper", "release") == {
"message": "You must be connected to the drone to access the gripper."
}

# Failure on incorrect gripper value
assert send_and_recieve("set_gripper", "testgrippervalue") == {
assert send_and_receive("set_gripper", "testgrippervalue") == {
"message": 'Gripper action must be either "release" or "grab"'
}

# Success on release
assert send_and_recieve("set_gripper", "release") == {
assert send_and_receive("set_gripper", "release") == {
"success": True,
"message": "Setting gripper to release",
}

# Success on grab
assert send_and_recieve("set_gripper", "grab") == {
assert send_and_receive("set_gripper", "grab") == {
"success": True,
"message": "Setting gripper to grab",
}

# Serial exception handled correctly
with FakeTCP():
assert send_and_recieve("set_gripper", "grab") == {
assert send_and_receive("set_gripper", "grab") == {
"success": False,
"message": "Setting gripper failed, serial exception",
}
Expand All @@ -95,8 +95,8 @@ def test_gripperDisabled(socketio_client: SocketIOTestClient, droneStatus) -> No
# Allow time for gripper to be updated
time.sleep(0.5)

assert send_and_recieve("get_gripper_enabled") is False
assert send_and_recieve("set_gripper", "release") == {
assert send_and_receive("get_gripper_enabled") is False
assert send_and_receive("set_gripper", "release") == {
"success": False,
"message": "Gripper is not enabled",
}
33 changes: 21 additions & 12 deletions radio/tests/test_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,13 @@ def test_exportMissionToFile_missionExportSuccess(
"message": f"Waypoint file saved 8 points successfully to {export_file_path}",
}
assert os.path.exists(export_file_path)
with open(export_file_path, "r") as f, open(
os.path.join(MISSION_FILES_PATH, "exported_mission_check.txt"),
"r",
) as f_expected:
with (
open(export_file_path, "r") as f,
open(
os.path.join(MISSION_FILES_PATH, "exported_mission_check.txt"),
"r",
) as f_expected,
):
assert f.read() == f_expected.read()


Expand Down Expand Up @@ -581,10 +584,13 @@ def test_exportMissionToFile_fenceExportSuccess(
"message": f"Waypoint file saved 13 points successfully to {export_file_path}",
}
assert os.path.exists(export_file_path)
with open(export_file_path, "r") as f, open(
os.path.join(MISSION_FILES_PATH, "exported_fence_check.txt"),
"r",
) as f_expected:
with (
open(export_file_path, "r") as f,
open(
os.path.join(MISSION_FILES_PATH, "exported_fence_check.txt"),
"r",
) as f_expected,
):
assert f.read() == f_expected.read()


Expand Down Expand Up @@ -614,10 +620,13 @@ def test_exportMissionToFile_rallyExportSuccess(
"message": f"Waypoint file saved 2 points successfully to {export_file_path}",
}
assert os.path.exists(export_file_path)
with open(export_file_path, "r") as f, open(
os.path.join(MISSION_FILES_PATH, "exported_rally_check.txt"),
"r",
) as f_expected:
with (
open(export_file_path, "r") as f,
open(
os.path.join(MISSION_FILES_PATH, "exported_rally_check.txt"),
"r",
) as f_expected,
):
assert f.read() == f_expected.read()


Expand Down
8 changes: 4 additions & 4 deletions radio/tests/test_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def assert_motorResult(
err: Optional[str] = None,
) -> None:
"""
Takes the data recieved from the socketio test client and asserts that it matches the given
Takes the data received from the socketio test client and asserts that it matches the given
expected values

Args:
data (dict): The data recieved using `client.get_recieved()`
data (dict): The data received using `client.get_received()`
success (bool): Whether the request should have been successful or not
motor (str, optional): Which motor the request should have tested, default `None`
err (str, optional): What the error message should have been, default `None`
Expand All @@ -42,7 +42,7 @@ def send_testOneMotor(
duration (int): The duration of the test

Returns:
dict: The data recieved from the client using `.get_recieved()`
dict: The data received from the client using `.get_received()`
"""
client.emit(
"test_one_motor",
Expand All @@ -66,7 +66,7 @@ def send_testMotors(
duration (int): The duration of the test

Returns:
dict: The data recieved from the client using `.get_recieved()`
dict: The data received from the client using `.get_received()`
"""
client.emit(
"test_all_motors" if test_all else "test_motor_sequence",
Expand Down
6 changes: 3 additions & 3 deletions radio/tests/test_states.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from flask_socketio import SocketIOTestClient

from . import falcon_test
from .helpers import NoDrone, send_and_recieve
from .helpers import NoDrone, send_and_receive


@falcon_test(pass_drone_status=True)
def test_setState(socketio_client: SocketIOTestClient, droneStatus) -> None:
# Failure on no drone connection
with NoDrone():
assert send_and_recieve("set_state", "dashboard") == {
assert send_and_receive("set_state", "dashboard") == {
"message": "Must be connected to the drone to set the drone state."
}

# Failure on no state sent
assert send_and_recieve("set_state", {}) == {
assert send_and_receive("set_state", {}) == {
"message": "Request to endpoint set_state missing value for parameter: state."
}

Expand Down
Loading