Files
test/keywords/ptp/pmc/pmc_table_parser.py
abhinav_ayyapasetti 1fabfc59ee pylint fix
Description:
- Added data types to function arguments and return values.
- Added blank lines between summary and description in docstrings to match style guidelines.
- Removed extra blank lines after docstrings.
- Added a missing import for SSHConnection in sma_keywords.py.
- Capitalized the first word in each docstring to comply with style guide rules.
- Improved docstring for PTP4LStatusObject constructor with detailed attribute descriptions

Change-Id: Idada0b0b0c3f895a16f4b439beaaaf071597a16a

Change-Id: I8e7756d32eb56a2aa85b277a91b26cc6280d1c56
Signed-off-by: aabhinav <ayyapasetti.abhinav@windriver.com>
2025-07-09 19:38:14 +00:00

63 lines
2.1 KiB
Python

from framework.exceptions.keyword_exception import KeywordException
class PMCTableParser:
"""
Class for PMC table parsing
Example from get DEFAULT_DATA_SET below
sending: GET DEFAULT_DATA_SET
507c6f.fffe.0b5a4d-0 seq 0 RESPONSE MANAGEMENT DEFAULT_DATA_SET
twoStepFlag 1
slaveOnly 0
numberPorts 1
priority1 128
clockClass 248
clockAccuracy 0xfe
offsetScaledLogVariance 0xffff
priority2 128
clockIdentity 507c6f.fffe.0b5a4d
domainNumber 0.
"""
def __init__(self, pmc_output: list[str]):
"""
Constructor
Args:
pmc_output (list[str]): a list of strings representing the output of a 'pmc' command.
"""
self.pmc_output = pmc_output
def get_output_values_dict(self) -> list[dict]:
"""
Getter for output values dict
Returns:
list[dict]: the output values dict
Raises:
KeywordException: if a line with values is not in the expected format.
"""
output_values_dict = {}
output_values_dict_list = []
total_rows = len(self.pmc_output)
for row in self.pmc_output[2:total_rows]: # Ignore the first 2 rows and the last row (prompt)
if "~$" in row:
continue # this a prompt, we can ignore
if "RESPONSE MANAGEMENT" in row: # signifies the start of a different set of values of the same object type.
output_values_dict_list.append(output_values_dict)
output_values_dict = {}
continue
values = row.split(None, 1) # split once
if len(values) == 2:
key, value = values
output_values_dict[key.strip()] = value.strip()
else:
raise KeywordException(f"Line with values: {row} was not in the expected format")
output_values_dict_list.append(output_values_dict)
return output_values_dict_list