forked from trikset/trik-studio-pioneer-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kleo-53/pioneer_uploader_tool
Pioneer uploader tool
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |