From 649cf3139084d69f8af290714670891666e81fd3 Mon Sep 17 00:00:00 2001 From: AlesKus Date: Sun, 12 Jan 2025 17:20:49 +0300 Subject: [PATCH 1/2] CmdData: remove spaces from get_str (issue #2925) --- src/fprime_gds/common/data_types/cmd_data.py | 5 +- .../common/data_types/test_cmd_data.py | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 test/fprime_gds/common/data_types/test_cmd_data.py diff --git a/src/fprime_gds/common/data_types/cmd_data.py b/src/fprime_gds/common/data_types/cmd_data.py index 5dff35f6..b12c285d 100644 --- a/src/fprime_gds/common/data_types/cmd_data.py +++ b/src/fprime_gds/common/data_types/cmd_data.py @@ -131,9 +131,8 @@ def get_str(self, time_zone=None, verbose=False, csv=False): else: # The arguments are currently serializable objects which cannot be # used to fill in a format string. Convert them to values that can be - arg_val_list = [arg_obj.val for arg_obj in self.args] - - arg_str = " ".join(str(arg_val_list)) + arg_val_list = self.get_arg_vals() + arg_str = str(arg_val_list) if verbose and csv: return f"{time_str},{raw_time_str},{name},{self.id},{arg_str}" diff --git a/test/fprime_gds/common/data_types/test_cmd_data.py b/test/fprime_gds/common/data_types/test_cmd_data.py new file mode 100644 index 00000000..e3db059b --- /dev/null +++ b/test/fprime_gds/common/data_types/test_cmd_data.py @@ -0,0 +1,66 @@ +""" +Tests Command Data + +Created on Jan 11, 2025 +@author: AlesKus +""" + +import unittest +from fprime.common.models.serialize.bool_type import BoolType +import fprime.common.models.serialize.numerical_types as numerical_types +from fprime.common.models.serialize.string_type import StringType +from fprime_gds.common.templates.cmd_template import CmdTemplate +from fprime_gds.common.data_types.cmd_data import CmdData + + +class CmdDataTest(unittest.TestCase): + def test_str_bool_command_arg(self): + """ + Tests CmdData::get_str() for a command with one bool argument + """ + opcode = 42 + mnemonic = "TEST_CMD_BOOL" + component = "PythonTests" + arguments = [("status", None, BoolType)] + command_template = CmdTemplate(opcode, mnemonic, component, arguments) + cmd_data = CmdData((True, ), command_template) + + data_str = cmd_data.get_str() + + self.assertIn("[True]", data_str) + + def test_str_numerical_command_args(self): + """ + Tests CmdData::get_str() for a command with several numerical arguments + """ + opcode = 43 + mnemonic = "TEST_CMD_NUMS" + component = "PythonTests" + arguments = [("just_int", None, numerical_types.U32Type), + ("just_float", None, numerical_types.F64Type), + ("just_byte", None, numerical_types.I8Type)] + command_template = CmdTemplate(opcode, mnemonic, component, arguments) + cmd_data = CmdData((12345, 98.765, 127), command_template) + + data_str = cmd_data.get_str() + + self.assertIn("[12345, 98.765, 127]", data_str) + + def test_str_string_command_args(self): + """ + Tests CmdData::get_str() for a command with one string argument + """ + opcode = 44 + mnemonic = "TEST_CMD_NUMS" + component = "PythonTests" + arguments = [("just_string", None, StringType.construct_type(f"String_{128}", 128))] + command_template = CmdTemplate(opcode, mnemonic, component, arguments) + cmd_data = CmdData(("Everything is good", ), command_template) + + data_str = cmd_data.get_str() + + self.assertIn("['Everything is good']", data_str) + + +if __name__ == "__main__": + unittest.main() From 2a33d1411412d99a3218360b5305b915bbba0b0e Mon Sep 17 00:00:00 2001 From: AlesKus Date: Sun, 12 Jan 2025 17:40:25 +0300 Subject: [PATCH 2/2] CmdDataTest: fix spelling --- test/fprime_gds/common/data_types/test_cmd_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fprime_gds/common/data_types/test_cmd_data.py b/test/fprime_gds/common/data_types/test_cmd_data.py index e3db059b..03184f16 100644 --- a/test/fprime_gds/common/data_types/test_cmd_data.py +++ b/test/fprime_gds/common/data_types/test_cmd_data.py @@ -34,7 +34,7 @@ def test_str_numerical_command_args(self): Tests CmdData::get_str() for a command with several numerical arguments """ opcode = 43 - mnemonic = "TEST_CMD_NUMS" + mnemonic = "TEST_CMD_NUMERICS" component = "PythonTests" arguments = [("just_int", None, numerical_types.U32Type), ("just_float", None, numerical_types.F64Type), @@ -51,7 +51,7 @@ def test_str_string_command_args(self): Tests CmdData::get_str() for a command with one string argument """ opcode = 44 - mnemonic = "TEST_CMD_NUMS" + mnemonic = "TEST_CMD_STR" component = "PythonTests" arguments = [("just_string", None, StringType.construct_type(f"String_{128}", 128))] command_template = CmdTemplate(opcode, mnemonic, component, arguments)