Skip to content

Commit

Permalink
review comment - find cluster then find children
Browse files Browse the repository at this point in the history
  • Loading branch information
rerpha committed Sep 27, 2024
1 parent 7b0bbfb commit b148e2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/ibex_bluesky_core/devices/dae/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def convert_xml_to_names_and_values(xml: Element) -> Dict[str, str]:

def get_all_elements_in_xml_with_child_called_name(xml: Element) -> List[Element]:
"""Find all elements with a "name" element, but ignore the first one as it's the root."""
elements = xml.findall(".//Name/..")[1:]
cluster = xml.find(".")
elements = cluster.findall("*/Name/..") # pyright: ignore [reportOptionalMemberAccess]
return elements


Expand Down
18 changes: 6 additions & 12 deletions tests/devices/test_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,13 @@ def test_get_names_and_values_from_xml():

def test_get_names_and_values_without_name_does_not_get_parsed():
test_xml = """
<element>
<child>
<Name>Cluster</Name>
<Val>2</Val>
</child>
<Cluster>
<Name>Cluster</Name>
<child>
<Name/>
<Val/>
</child>
</element>
</Cluster>
"""
root = ET.fromstring(test_xml)
ret = convert_xml_to_names_and_values(root)
Expand All @@ -194,16 +191,13 @@ def test_get_names_and_values_without_name_does_not_get_parsed():

def test_get_names_and_values_without_value_does_not_get_parsed():
test_xml = """
<element>
<child>
<Name>Cluster</Name>
<Val>2</Val>
</child>
<Cluster>
<Name>Some cluster name</Name>
<child>
<Name>test</Name>
<Val/>
</child>
</element>
</Cluster>
"""
root = ET.fromstring(test_xml)
ret = convert_xml_to_names_and_values(root)
Expand Down

0 comments on commit b148e2b

Please sign in to comment.