Skip to content

Commit 4c59580

Browse files
committed
address review comments
1 parent aa348dc commit 4c59580

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/python_testing/TestSpecParsingSupport.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,19 @@ def test_write_optional(self):
223223

224224
def test_derived_clusters(self):
225225
clusters: dict[int, XmlCluster] = {}
226-
derived_clusters: dict[str, XmlCluster] = {}
226+
pure_base_clusters: dict[str, XmlCluster] = {}
227227
ids_by_name: dict[str, int] = {}
228228
problems: list[ProblemNotice] = []
229229
base_cluster_xml = ElementTree.fromstring(BASE_CLUSTER_XML_STR)
230230
derived_cluster_xml = ElementTree.fromstring(DERIVED_CLUSTER_XML_STR)
231231
expected_global_attrs = [GlobalAttributeIds.FEATURE_MAP_ID, GlobalAttributeIds.ATTRIBUTE_LIST_ID,
232232
GlobalAttributeIds.ACCEPTED_COMMAND_LIST_ID, GlobalAttributeIds.GENERATED_COMMAND_LIST_ID, GlobalAttributeIds.CLUSTER_REVISION_ID]
233233

234-
add_cluster_data_from_xml(base_cluster_xml, clusters, derived_clusters, ids_by_name, problems)
235-
add_cluster_data_from_xml(derived_cluster_xml, clusters, derived_clusters, ids_by_name, problems)
234+
add_cluster_data_from_xml(base_cluster_xml, clusters, pure_base_clusters, ids_by_name, problems)
235+
add_cluster_data_from_xml(derived_cluster_xml, clusters, pure_base_clusters, ids_by_name, problems)
236236

237237
asserts.assert_equal(len(clusters), 1, "Unexpected number of clusters")
238-
asserts.assert_equal(len(derived_clusters), 1, "Unexpected number of derived clusters")
238+
asserts.assert_equal(len(pure_base_clusters), 1, "Unexpected number of derived clusters")
239239
asserts.assert_equal(len(ids_by_name), 1, "Unexpected number of IDs per name")
240240
asserts.assert_equal(len(problems), 0, "Unexpected number of problems")
241241
asserts.assert_equal(ids_by_name["Test Derived"], 0xFFFF, "Test derived name not added to IDs")
@@ -246,22 +246,23 @@ def test_derived_clusters(self):
246246
asserts.assert_equal(set(clusters[0xFFFF].accepted_commands.keys()), set([]), "Unexpected accepted commands")
247247
asserts.assert_equal(set(clusters[0xFFFF].generated_commands.keys()), set([]), "Unexpected generated commands")
248248

249-
asserts.assert_true("Test Base" in derived_clusters, "Base ID not found in derived clusters")
250-
asserts.assert_equal(set(derived_clusters["Test Base"].attributes.keys()), set(
249+
asserts.assert_true("Test Base" in pure_base_clusters, "Base ID not found in derived clusters")
250+
asserts.assert_equal(set(pure_base_clusters["Test Base"].attributes.keys()), set(
251251
[0, 1, 2, 3] + expected_global_attrs), "Unexpected attribute list")
252-
asserts.assert_equal(set(derived_clusters["Test Base"].accepted_commands.keys()), set([0]), "Unexpected accepted commands")
253-
asserts.assert_equal(set(derived_clusters["Test Base"].generated_commands.keys()),
252+
asserts.assert_equal(set(pure_base_clusters["Test Base"].accepted_commands.keys()),
253+
set([0]), "Unexpected accepted commands")
254+
asserts.assert_equal(set(pure_base_clusters["Test Base"].generated_commands.keys()),
254255
set([1]), "Unexpected generated commands")
255-
asserts.assert_equal(str(derived_clusters["Test Base"].accepted_commands[0].conformance),
256+
asserts.assert_equal(str(pure_base_clusters["Test Base"].accepted_commands[0].conformance),
256257
"M", "Unexpected conformance on base accepted command")
257-
asserts.assert_equal(str(derived_clusters["Test Base"].generated_commands[1].conformance),
258+
asserts.assert_equal(str(pure_base_clusters["Test Base"].generated_commands[1].conformance),
258259
"M", "Unexpected conformance on base generated command")
259260

260-
asserts.assert_equal(len(derived_clusters["Test Base"].unknown_commands),
261+
asserts.assert_equal(len(pure_base_clusters["Test Base"].unknown_commands),
261262
0, "Unexpected number of unknown commands in base")
262263
asserts.assert_equal(len(clusters[0xFFFF].unknown_commands), 2, "Unexpected number of unknown commands in derived cluster")
263264

264-
combine_derived_clusters_with_base(clusters, derived_clusters, ids_by_name)
265+
combine_derived_clusters_with_base(clusters, pure_base_clusters, ids_by_name)
265266
# Ensure the base-only attribute (1) was added to the derived cluster
266267
asserts.assert_equal(set(clusters[0xFFFF].attributes.keys()), set(
267268
[0, 1, 2, 3] + expected_global_attrs), "Unexpected attribute list")
@@ -284,12 +285,12 @@ def test_derived_clusters(self):
284285

285286
def test_missing_command_direction(self):
286287
clusters: dict[int, XmlCluster] = {}
287-
derived_clusters: dict[str, XmlCluster] = {}
288+
pure_base_clusters: dict[str, XmlCluster] = {}
288289
ids_by_name: dict[str, int] = {}
289290
problems: list[ProblemNotice] = []
290291
cluster_xml = ElementTree.fromstring(CLUSTER_WITH_UNKNOWN_COMMAND)
291292

292-
add_cluster_data_from_xml(cluster_xml, clusters, derived_clusters, ids_by_name, problems)
293+
add_cluster_data_from_xml(cluster_xml, clusters, pure_base_clusters, ids_by_name, problems)
293294
check_clusters_for_unknown_commands(clusters, problems)
294295
asserts.assert_equal(len(problems), 1, "Unexpected number of problems found")
295296
asserts.assert_equal(problems[0].location.cluster_id, 0xFFFE, "Unexpected problem location (cluster id)")

src/python_testing/spec_parsing_support.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def parse_attributes(self) -> dict[uint, XmlAttribute]:
348348
), read_access=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView, write_access=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kUnknownEnumValue, write_optional=False)
349349
return attributes
350350

351-
def get_command_direction(self, element: ElementTree.Element) -> CommandType:
351+
def get_command_type(self, element: ElementTree.Element) -> CommandType:
352352
try:
353353
if element.attrib['direction'].lower() == 'responsefromserver':
354354
return CommandType.GENERATED
@@ -360,7 +360,7 @@ def get_command_direction(self, element: ElementTree.Element) -> CommandType:
360360
def parse_unknown_commands(self) -> list[XmlCommand]:
361361
commands = []
362362
for element, conformance_xml, access_xml in self.command_elements:
363-
if self.get_command_direction(element) != CommandType.UNKNOWN:
363+
if self.get_command_type(element) != CommandType.UNKNOWN:
364364
continue
365365
code = int(element.attrib['id'], 0)
366366
conformance = self.parse_conformance(conformance_xml)
@@ -370,7 +370,7 @@ def parse_unknown_commands(self) -> list[XmlCommand]:
370370
def parse_commands(self, command_type: CommandType) -> dict[uint, XmlCommand]:
371371
commands = {}
372372
for element, conformance_xml, access_xml in self.command_elements:
373-
if self.get_command_direction(element) != command_type:
373+
if self.get_command_type(element) != command_type:
374374
continue
375375
code = int(element.attrib['id'], 0)
376376
conformance = self.parse_conformance(conformance_xml)
@@ -412,7 +412,16 @@ def get_problems(self) -> list[ProblemNotice]:
412412
return self._problems
413413

414414

415-
def add_cluster_data_from_xml(xml: ElementTree.Element, clusters: dict[int, XmlCluster], derived_clusters: dict[str, XmlCluster], ids_by_name: dict[str, int], problems: list[ProblemNotice]) -> None:
415+
def add_cluster_data_from_xml(xml: ElementTree.Element, clusters: dict[int, XmlCluster], pure_base_clusters: dict[str, XmlCluster], ids_by_name: dict[str, int], problems: list[ProblemNotice]) -> None:
416+
''' Adds cluster data to the supplied dicts as appropriate
417+
418+
xml: XML element read from from the XML cluster file
419+
clusters: dict of id -> XmlCluster. This function will append new clusters as appropriate to this dict.
420+
pure_base_clusters: dict of base name -> XmlCluster. This data structure is used to hold pure base clusters that don't have
421+
an ID. This function will append new pure base clusters as approrpriate to this dict.
422+
ids_by_name: dict of cluster name -> ID. This function will append new IDs as appropriate to this dict.
423+
problems: list of any problems encountered during spec parsing. This function will append problems as appropriate to this list.
424+
'''
416425
cluster = xml.iter('cluster')
417426
for c in cluster:
418427
name = c.attrib['name']
@@ -433,7 +442,7 @@ def add_cluster_data_from_xml(xml: ElementTree.Element, clusters: dict[int, XmlC
433442
if cluster_id:
434443
clusters[cluster_id] = new
435444
else:
436-
derived_clusters[name] = new
445+
pure_base_clusters[name] = new
437446

438447

439448
def check_clusters_for_unknown_commands(clusters: dict[int, XmlCluster], problems: list[ProblemNotice]):
@@ -446,14 +455,14 @@ def check_clusters_for_unknown_commands(clusters: dict[int, XmlCluster], problem
446455
def build_xml_clusters() -> tuple[list[XmlCluster], list[ProblemNotice]]:
447456
dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'data_model', 'clusters')
448457
clusters: dict[int, XmlCluster] = {}
449-
derived_clusters: dict[str, XmlCluster] = {}
458+
pure_base_clusters: dict[str, XmlCluster] = {}
450459
ids_by_name: dict[str, int] = {}
451460
problems: list[ProblemNotice] = []
452461
for xml in glob.glob(f"{dir}/*.xml"):
453462
logging.info(f'Parsing file {xml}')
454463
tree = ElementTree.parse(f'{xml}')
455464
root = tree.getroot()
456-
add_cluster_data_from_xml(root, clusters, derived_clusters, ids_by_name, problems)
465+
add_cluster_data_from_xml(root, clusters, pure_base_clusters, ids_by_name, problems)
457466

458467
# There are a few clusters where the conformance columns are listed as desc. These clusters need specific, targeted tests
459468
# to properly assess conformance. Here, we list them as Optional to allow these for the general test. Targeted tests are described below.
@@ -475,11 +484,11 @@ def remove_problem(location: typing.Union[CommandPathLocation, FeaturePathLocati
475484
clusters[action_id].accepted_commands[c].conformance = optional()
476485
remove_problem(CommandPathLocation(endpoint_id=0, cluster_id=action_id, command_id=c))
477486

478-
combine_derived_clusters_with_base(clusters, derived_clusters, ids_by_name)
487+
combine_derived_clusters_with_base(clusters, pure_base_clusters, ids_by_name)
479488

480489
for alias_base_name, aliased_clusters in CLUSTER_ALIASES.items():
481490
for id, (alias_name, pics) in aliased_clusters.items():
482-
base = derived_clusters[alias_base_name]
491+
base = pure_base_clusters[alias_base_name]
483492
new = deepcopy(base)
484493
new.derived = alias_base_name
485494
new.name = alias_name
@@ -514,7 +523,7 @@ def remove_problem(location: typing.Union[CommandPathLocation, FeaturePathLocati
514523
return clusters, problems
515524

516525

517-
def combine_derived_clusters_with_base(xml_clusters: dict[int, XmlCluster], derived_clusters: dict[str, XmlCluster], ids_by_name: dict[str, int]) -> None:
526+
def combine_derived_clusters_with_base(xml_clusters: dict[int, XmlCluster], pure_base_clusters: dict[str, XmlCluster], ids_by_name: dict[str, int]) -> None:
518527
''' Overrides base elements with the derived cluster values for derived clusters. '''
519528

520529
def combine_attributes(base: dict[uint, XmlAttribute], derived: dict[uint, XmlAttribute], cluster_id: uint) -> dict[uint, XmlAttribute]:
@@ -547,7 +556,7 @@ def combine_attributes(base: dict[uint, XmlAttribute], derived: dict[uint, XmlAt
547556
if base_name in ids_by_name:
548557
base = xml_clusters[ids_by_name[c.derived]]
549558
else:
550-
base = derived_clusters[base_name]
559+
base = pure_base_clusters[base_name]
551560

552561
feature_map = deepcopy(base.feature_map)
553562
feature_map.update(c.feature_map)

0 commit comments

Comments
 (0)