Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove spaces from CmdData::get_str(). Fixes #2925 #186

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/fprime_gds/common/data_types/cmd_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
66 changes: 66 additions & 0 deletions test/fprime_gds/common/data_types/test_cmd_data.py
Original file line number Diff line number Diff line change
@@ -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_NUMERICS"
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_STR"
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()
Loading