Skip to content

Commit

Permalink
added github workflow (#29)
Browse files Browse the repository at this point in the history
* init commit

* added print messages in run func

* fixed location and waypoint retrieval

* init commit

* added print messages in run func

* fixed location and waypoint retrieval

* misc changes for merge

* reverted prev change for merge

* added new function under modules

* fixed description

* fixed spacing

* fixed waypoint_tracking

* fixed styling

* fixed function descriptions

* modified return status

* added print messages for location

* modified dronekit connection

* changed method of counting in waypoint_trakcing

* added github workflow

* added workflow fix

* removed skipped pytests

* Update run-tests.yml

* add zbar library to fix build error

* updated tests to remove ci errors

* remove zbar installation

* revert changes

* adjusted comments on tests

* comment adjustment
  • Loading branch information
roskzhu authored Nov 23, 2023
1 parent dd329f1 commit 2b44439
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will install Python dependencies and run tests with PyTest using Python 3.8
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v3

# Set Python version
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

# Set up submodules and submodule dependencies
- name: Set up submodule and submodule dependencies
run: |
git submodule update --init --recursive --remote
pip install -r ./modules/common/requirements.txt
# Install pathing dependencies
- name: Install project dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Install zbar library to resolve pyzbar import error
- name: Install zbar library
run: sudo apt-get install libzbar0

# Run tests with PyTest
- name: Run tests
run: pytest -vv
24 changes: 7 additions & 17 deletions tests/test_qr_input.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
"""
Test process.
Tests functionality for qr_input.
"""

import pytest

from modules import qr_input


CAMERA = 0


pytest.skip("Integration test", allow_module_level=True)


def test_qr_input():
"""
Tests functionality for qr_input
"""
is_qr_found, qr_string = qr_input.qr_input(CAMERA)
if __name__ == '__main__':

if is_qr_found:
print(f"Decoded QR code with string value: {qr_string}")
else:
print("Exited early before a QR code was read")
result, qr_string = qr_input.qr_input(CAMERA)
assert result
assert qr_string is not None

print(f"Decoded QR code with string value: {qr_string}")

if __name__ == '__main__':
test_qr_input()
print("Done!")
18 changes: 7 additions & 11 deletions tests/test_upload_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
import math

import dronekit
import pytest

from modules import upload_commands


# This file does not contain unit tests
pytest.skip("Integration test", allow_module_level=True)


ALTITUDE = 40

MAVLINK_FRAME = dronekit.mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
Expand All @@ -38,8 +33,8 @@ def retrieve_commands(drone: dronekit.Vehicle) -> dronekit.CommandSequence:
return command_sequence


def test_upload_command_list(drone: dronekit.Vehicle,
commands: "list[dronekit.Command]") -> None:
def upload_and_check_command_list(drone: dronekit.Vehicle,
commands: "list[dronekit.Command]"):
"""
Test the case of a list of waypoint commands.
"""
Expand All @@ -59,7 +54,7 @@ def test_upload_command_list(drone: dronekit.Vehicle,
assert math.isclose(command.z, commands[i].z, abs_tol = TOLERANCE)


def test_upload_empty_command_list(drone: dronekit.Vehicle) -> None:
def upload_and_check_empty_command_list(drone: dronekit.Vehicle):
"""
Test the case of an empty command list.
"""
Expand Down Expand Up @@ -89,7 +84,8 @@ def test_upload_empty_command_list(drone: dronekit.Vehicle) -> None:

if __name__ == "__main__":
# Drone setup
dronekit_vehicle = dronekit.connect(CONNECTION_ADDRESS, wait_ready=True)
# Wait ready is false as the drone may be on the ground
dronekit_vehicle = dronekit.connect(CONNECTION_ADDRESS, wait_ready=False)

# Example waypoints list, converted to waypoint commands
waypoints_input = [(39.140, 22.23), (25.123, -76.324)]
Expand Down Expand Up @@ -172,9 +168,9 @@ def test_upload_empty_command_list(drone: dronekit.Vehicle) -> None:
commands_input.append(loiter_command)

# Test with the command sequence
test_upload_command_list(dronekit_vehicle, commands_input)
upload_and_check_command_list(dronekit_vehicle, commands_input)

# Test with empty command sequence
test_upload_empty_command_list(dronekit_vehicle)
upload_and_check_empty_command_list(dronekit_vehicle)

print("Done!")

0 comments on commit 2b44439

Please sign in to comment.