Skip to content

Commit

Permalink
Merge pull request #1 from kleo-53/pioneer_uploader_tool
Browse files Browse the repository at this point in the history
Pioneer uploader tool
  • Loading branch information
kleo-53 authored Sep 13, 2023
2 parents b2056a7 + 6d5ce3b commit f424a03
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Test

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.12

- name: Install dependencies
run: pip install -r requirements.txt

- name: Format code with Black
run: black pioneer-uploader.py

- name: Build with PyInstaller
run: pyinstaller --onefile pioneer-uploader.py

- name: Publish artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v2
with:
name: publish-artifact
path: dist

- name: Run tests
run: pytest
39 changes: 39 additions & 0 deletions pioneer_uploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Upload generated program to drone
"""
import os
import sys
import time
from pioneer_sdk import Pioneer
import logging


def main():
try:
file_path, ip, port, mode = sys.argv[1:5]
except ValueError:
logging.error("Invalid arguments")
return

if not os.path.exists(file_path):
logging.error("Can not find program file")
return

drone = Pioneer(
ip=ip,
mavlink_port=port,
connection_method="udpout" if mode == "wifi" else "serial",
logger=True,
)

try:
drone.lua_script_upload(file_path)
time.sleep(2)
drone.close_connection()
except Exception as e:
logging.error(e)
return


if __name__ == "__main__":
main()
Binary file added requirements.txt
Binary file not shown.
Empty file added test/test_file.lua
Empty file.
38 changes: 38 additions & 0 deletions test/test_uploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import pytest
import pioneer_uploader
from unittest.mock import patch


@patch("logging.error")
def test_without_file(mock_logging_error):
test_args = ["parameter", "invalid_file_path", "invalid_ip", "invalid_port", "invalid_mode"]
with patch('sys.argv', test_args):
pioneer_uploader.main()
mock_logging_error.assert_called_once_with("Can not find program file")


@patch("logging.error")
def test_few_arguments(mock_logging_error):
test_args = ["less then", "five", "arguments"]
with patch('sys.argv', test_args):
pioneer_uploader.main()
mock_logging_error.assert_called_once_with("Invalid arguments")


@patch("logging.error")
def test_correct_arguments(mock_logging_error):
current_file = Path(__file__).resolve()
file = current_file.parent/'test_file.lua'
print(file)
test_args = ["parameter", file, "127.0.0.1", "8888", "wifi"]
with patch('sys.argv', test_args):
with pytest.raises(ConnectionResetError):
pioneer_uploader.main()
# mock_logging_error.assert_called_once_with(ConnectionResetError(10054,
# 'An existing connection was forcibly closed by the remote host', None, 10054, None))


if __name__ == "__main__":
pytest.main()

0 comments on commit f424a03

Please sign in to comment.