Skip to content

Commit fce604a

Browse files
committed
fix(export): address review - widen mavproxy column, add round-trip test
- Update MAVProxy width specifier from 8 to 14 to accommodate .10f values - Add found-flags to ensure all small values are present in formatted output - Add true export→reimport round-trip test verifying numeric values survive Signed-off-by: Yash Goel <yashgoel249@gmail.com>
1 parent 72c6087 commit fce604a

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

ardupilot_methodic_configurator/data_model_par_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ def _format_params(self, file_format: str = "missionplanner") -> list[str]:
271271
sorted_dict = ParDict(dict(sorted(self.items())))
272272
formatted_params = [
273273
(
274-
f"{key:<16} {parameter.value:<8.10f} # {parameter.comment}"
274+
f"{key:<16} {parameter.value:<14.10f} # {parameter.comment}"
275275
if isinstance(parameter, Par) and parameter.comment
276-
else f"{key:<16} {parameter.value if isinstance(parameter, Par) else parameter:<8.10f}"
276+
else f"{key:<16} {parameter.value if isinstance(parameter, Par) else parameter:<14.10f}"
277277
)
278278
for key, parameter in sorted_dict.items()
279279
]

tests/test_data_model_par_dict.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ def test_user_can_export_parameters_to_mavproxy_format(self, parameter_dict) ->
569569
content = f.read()
570570

571571
# MAVProxy format uses fixed-width columns
572-
assert "ACRO_YAW_P 4.5000000000 # Yaw P gain" in content
573-
assert "GPS_TYPE 1.0000000000" in content
572+
assert "ACRO_YAW_P 4.5000000000 # Yaw P gain" in content
573+
assert "GPS_TYPE 1.0000000000 " in content
574574
finally:
575575
os.unlink(output_file)
576576

@@ -949,7 +949,7 @@ def test_user_can_format_parameters_for_mavproxy(self, parameter_dict) -> None:
949949

950950
# Assert: Correct MAVProxy format (space-separated, fixed width)
951951
yaw_line = next((line for line in formatted if "ACRO_YAW_P" in line), "")
952-
assert yaw_line == "ACRO_YAW_P 4.5000000000 # Yaw P gain"
952+
assert yaw_line == "ACRO_YAW_P 4.5000000000 # Yaw P gain"
953953

954954
def test_user_receives_error_for_unsupported_format(self, parameter_dict) -> None:
955955
"""
@@ -970,8 +970,8 @@ def test_user_preserves_small_parameter_values_on_export(self) -> None:
970970
User preserves parameter values smaller than 1e-6 during export.
971971
972972
GIVEN: A user has parameters with very small but nonzero values
973-
WHEN: They export and reimport using MissionPlanner or MAVProxy format
974-
THEN: The values should survive the round-trip without silent data loss
973+
WHEN: They format using MissionPlanner or MAVProxy format
974+
THEN: The formatted strings should retain the small values
975975
"""
976976
# Arrange: Parameters with values that would be truncated by .6f formatting
977977
small_value_params = ParDict(
@@ -986,14 +986,56 @@ def test_user_preserves_small_parameter_values_on_export(self) -> None:
986986
for file_format in ("missionplanner", "mavproxy"):
987987
formatted = small_value_params._format_params(file_format) # pylint: disable=protected-access
988988

989-
# Extract the numeric value strings from the formatted output
989+
tiny_found = False
990+
micro_found = False
991+
boundary_found = False
990992
for line in formatted:
991993
if "TINY_VAL" in line:
992994
assert "0.0000001" in line, f"Value 1e-7 lost in {file_format} format: {line}"
995+
tiny_found = True
993996
if "MICRO_VAL" in line:
994997
assert "0.0000005" in line, f"Value 5e-7 lost in {file_format} format: {line}"
998+
micro_found = True
995999
if "BOUNDARY_VAL" in line:
9961000
assert "0.000001" in line, f"Value 1e-6 lost in {file_format} format: {line}"
1001+
boundary_found = True
1002+
1003+
assert tiny_found, f"TINY_VAL not found in {file_format} formatted output"
1004+
assert micro_found, f"MICRO_VAL not found in {file_format} formatted output"
1005+
assert boundary_found, f"BOUNDARY_VAL not found in {file_format} formatted output"
1006+
1007+
def test_user_preserves_small_values_on_export_reimport_round_trip(self) -> None:
1008+
"""
1009+
User preserves small parameter values through a full export→reimport round-trip.
1010+
1011+
GIVEN: A user has parameters with very small but nonzero values
1012+
WHEN: They export to a file and reimport it
1013+
THEN: The numeric values should match within float32 tolerance
1014+
"""
1015+
small_value_params = ParDict(
1016+
{
1017+
"TINY_VAL": Par(0.0000001, "Very small value"),
1018+
"BOUNDARY_VAL": Par(0.000001, "Boundary value"),
1019+
"NORMAL_VAL": Par(1.5, "Normal value"),
1020+
}
1021+
)
1022+
1023+
for file_format in ("missionplanner", "mavproxy"):
1024+
with tempfile.NamedTemporaryFile(mode="w", suffix=".param", delete=False) as f:
1025+
output_file = f.name
1026+
1027+
try:
1028+
small_value_params.export_to_param(output_file, file_format)
1029+
reloaded = ParDict.load_param_file_into_dict(output_file)
1030+
1031+
for key, original in small_value_params.items():
1032+
original_val = original.value if isinstance(original, Par) else original
1033+
reloaded_val = reloaded[key].value if isinstance(reloaded[key], Par) else reloaded[key]
1034+
assert abs(reloaded_val - original_val) < 1e-10, (
1035+
f"{key}: value {original_val} became {reloaded_val} after {file_format} round-trip"
1036+
)
1037+
finally:
1038+
os.unlink(output_file)
9971039

9981040
def test_user_can_annotate_parameters_with_comments(self, parameter_dict) -> None:
9991041
"""

0 commit comments

Comments
 (0)