-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
do Carmo Lucas
committed
Jun 19, 2024
1 parent
e79c7c9
commit a56275f
Showing
10 changed files
with
277 additions
and
33 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
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
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,65 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator | ||
SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <[email protected]> | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
''' | ||
|
||
import unittest | ||
from math import nan | ||
|
||
from MethodicConfigurator.battery_cell_voltages import battery_cell_voltages | ||
from MethodicConfigurator.battery_cell_voltages import BatteryCell | ||
|
||
|
||
class TestBatteryCell(unittest.TestCase): # pylint: disable=missing-class-docstring | ||
|
||
def test_chemistries(self): | ||
expected_chemistries = ['LiIon', 'LiIonSS', 'LiIonSSHV', 'Lipo', 'LipoHV', 'LipoHVSS'] | ||
chemistries = BatteryCell.chemistries() | ||
self.assertEqual(chemistries, expected_chemistries) | ||
|
||
def test_limit_max_voltage(self): | ||
self.assertEqual(BatteryCell.limit_max_voltage('LiIon'), 4.1) | ||
self.assertEqual(BatteryCell.limit_max_voltage('LipoHV'), 4.35) | ||
self.assertEqual(BatteryCell.limit_max_voltage('NonExistentChemistry'), 4.45) | ||
|
||
def test_limit_min_voltage(self): | ||
self.assertEqual(BatteryCell.limit_min_voltage('LiIon'), 2.5) | ||
self.assertEqual(BatteryCell.limit_min_voltage('LipoHV'), 3.0) | ||
self.assertEqual(BatteryCell.limit_min_voltage('NonExistentChemistry'), 2.4) | ||
|
||
def test_recommended_max_voltage(self): | ||
self.assertEqual(BatteryCell.recommended_max_voltage('LiIon'), 4.1) | ||
self.assertIs(BatteryCell.recommended_max_voltage('NonExistentChemistry'), nan) | ||
|
||
def test_recommended_low_voltage(self): | ||
self.assertEqual(BatteryCell.recommended_low_voltage('LiIon'), 3.1) | ||
self.assertIs(BatteryCell.recommended_low_voltage('NonExistentChemistry'), nan) | ||
|
||
def test_recommended_crit_voltage(self): | ||
self.assertEqual(BatteryCell.recommended_crit_voltage('LiIon'), 2.8) | ||
self.assertIs(BatteryCell.recommended_crit_voltage('NonExistentChemistry'), nan) | ||
|
||
def test_voltage_monoticity(self): | ||
for chemistry in BatteryCell.chemistries(): | ||
with self.subTest(chemistry=chemistry): | ||
self.assertEqual(BatteryCell.limit_max_voltage(chemistry), | ||
battery_cell_voltages[chemistry].get('absolute_max')) | ||
self.assertEqual(BatteryCell.limit_min_voltage(chemistry), | ||
battery_cell_voltages[chemistry].get('absolute_min')) | ||
self.assertGreaterEqual(BatteryCell.limit_max_voltage(chemistry), | ||
BatteryCell.recommended_max_voltage(chemistry)) | ||
self.assertGreaterEqual(BatteryCell.recommended_max_voltage(chemistry), | ||
BatteryCell.recommended_low_voltage(chemistry)) | ||
self.assertGreaterEqual(BatteryCell.recommended_low_voltage(chemistry), | ||
BatteryCell.recommended_crit_voltage(chemistry)) | ||
self.assertGreaterEqual(BatteryCell.recommended_crit_voltage(chemistry), | ||
BatteryCell.limit_min_voltage(chemistry)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator | ||
SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <[email protected]> | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
''' | ||
|
||
import unittest | ||
from unittest.mock import MagicMock | ||
from argparse import ArgumentParser | ||
|
||
from MethodicConfigurator import common_arguments | ||
|
||
|
||
class TestCommonArguments(unittest.TestCase): # pylint: disable=missing-class-docstring | ||
|
||
def test_add_common_arguments_and_parse_loglevel(self): | ||
# Test that loglevel choices are added correctly | ||
parser = ArgumentParser() | ||
parser.parse_args = MagicMock(return_value=MagicMock(loglevel='INFO')) | ||
|
||
updated_parser = common_arguments.add_common_arguments_and_parse(parser) | ||
|
||
# This will raise an error if loglevel is not an argument | ||
# or if the choices are not set up correctly. | ||
updated_parser.parse_args(['--loglevel', 'INFO']) | ||
updated_parser.parse_args.assert_called_with(['--loglevel', 'INFO']) | ||
|
||
def test_version_argument(self): | ||
# Test that version argument displays correct version | ||
parser = ArgumentParser() | ||
# Mock the parse_args to just print the version string | ||
parser.parse_args = MagicMock() | ||
common_arguments.VERSION = "1.0.0" | ||
updated_parser = common_arguments.add_common_arguments_and_parse(parser) | ||
|
||
# We assume the call to parse_args with --version should print the version | ||
# Since we cannot capture stdout here easily, we'll just confirm the method was called with --version | ||
updated_parser.parse_args(['--version']) | ||
updated_parser.parse_args.assert_called_with(['--version']) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 |
---|---|---|
|
@@ -2,8 +2,23 @@ | |
# | ||
# SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <[email protected]> | ||
# | ||
#SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
PYTHONPATH=../MethodicConfigurator python3 -m coverage run -m unittest extract_param_defaults_test.py | ||
python3 -m coverage html | ||
REQUIRED_PKGS=("coverage" "mock") | ||
|
||
is_installed() { | ||
pip show "$1" > /dev/null 2>&1 | ||
} | ||
|
||
for pkg in "${REQUIRED_PKGS[@]}"; do | ||
if ! is_installed "$pkg"; then | ||
echo "Installing $pkg..." | ||
pip install "$pkg" | ||
else | ||
echo "$pkg is already installed." | ||
fi | ||
done | ||
|
||
PYTHONPATH=../MethodicConfigurator python -m coverage run -m unittest extract_param_defaults_test.py | ||
python -m coverage html | ||
firefox htmlcov/extract_param_defaults_py.html |
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
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,83 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator | ||
SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <[email protected]> | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
''' | ||
|
||
import unittest | ||
from MethodicConfigurator.middleware_template_overview import TemplateOverview | ||
|
||
|
||
class TestTemplateOverview(unittest.TestCase): # pylint: disable=missing-class-docstring | ||
|
||
def setUp(self): | ||
# Define sample data to be used in tests | ||
self.sample_data = { | ||
'Flight Controller': { | ||
'Product': { | ||
'Manufacturer': 'ArduPilot', | ||
'Model': 'Pixhawk4' | ||
} | ||
}, | ||
'Frame': { | ||
'Specifications': { | ||
'TOW max Kg': '5' | ||
} | ||
}, | ||
# ... add other components as per your structure | ||
} | ||
|
||
def test_template_overview_initialization(self): | ||
# Initialize the TemplateOverview with sample data | ||
template_overview = TemplateOverview(self.sample_data) | ||
|
||
# Check if attributes are set correctly | ||
self.assertEqual(template_overview.fc_manufacturer, 'ArduPilot') | ||
self.assertEqual(template_overview.fc_model, 'Pixhawk4') | ||
self.assertEqual(template_overview.tow_max_kg, '5') | ||
# .. similarly test other attributes | ||
|
||
def test_template_overview_column_labels(self): | ||
# Check if the column labels match the required order | ||
# pylint: disable=duplicate-code | ||
expected_columns = ( | ||
"FC\nManufacturer", | ||
"FC\nModel", | ||
"TOW Max\n[KG]", | ||
"Prop Diameter\n[inches]", | ||
"RC\nProtocol", | ||
"Telemetry\nModel", | ||
"ESC\nProtocol", | ||
"GNSS\nModel", | ||
"GNSS\nConnection", | ||
) | ||
# pylint: enable=duplicate-code | ||
self.assertEqual(TemplateOverview.columns(), expected_columns) | ||
|
||
def test_template_overview_attributes_method(self): | ||
# Initialize the TemplateOverview with the sample data | ||
template_overview = TemplateOverview(self.sample_data) | ||
|
||
# Fetch the instance attribute keys | ||
attribute_keys = template_overview.attributes() | ||
|
||
# Check if the attribute keys match the expected set of attributes | ||
expected_attributes = { | ||
'fc_manufacturer', | ||
'fc_model', | ||
'tow_max_kg', | ||
'prop_diameter_inches', | ||
'rc_protocol', | ||
'telemetry_model', | ||
'esc_protocol', | ||
'gnss_model', | ||
'gnss_connection', | ||
} | ||
self.assertEqual(expected_attributes, set(attribute_keys)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
Oops, something went wrong.