Files
test/keywords/ptp/pmc/pmc_table_parser.py
jpike f71d720996 Adding support for multiple port data settings
Updating the pmc parser to allow for multiple setting values. This
meant a refactor of other classes using this table. For now only
the port data seems to have multiple so other formats will fail if
more than one is found.

Also added some new unit tests for formats not covered previously
and fixed a couple of other tests.

Change-Id: I401ae0327399e23bcf2d899f048fe28228246f42
2025-04-24 09:06:31 -04:00

59 lines
1.9 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
"""
output_values_dict = {}
output_values_dict_list = []
total_rows = len(self.pmc_output)
for row in self.pmc_output[2 : total_rows - 1]: # Ignore the first 2 rows and the last row (prompt)
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