Skip to content

Commit

Permalink
fix leaf check when DA has Private child
Browse files Browse the repository at this point in the history
  • Loading branch information
vermeulenthi committed Oct 24, 2023
1 parent 5021f92 commit a9ae1af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ log_date_format = %Y-%m-%d %H:%M:%S
log_cli = 1
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
log_cli_date_format=%Y-%m-%d %H:%M:%S
pythonpath=src
16 changes: 7 additions & 9 deletions src/scl_loader/scl_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def get_name_subtree(self, fc_filter: str = None):
for level in leaf_path.split(".")[node_depth-1:]:
node = node.setdefault(level, dict())
tree_as_tuples = self._recursive_dict_to_tuple(tree)
return tree_as_tuples[0]
return tree_as_tuples[0] if len(tree_as_tuples) > 0 else []

def _recursive_dict_to_tuple(self, i_dict):
"""
Expand Down Expand Up @@ -548,24 +548,22 @@ def _create_from_etree_element(self, node_elem: etree.Element):
dt_node_elem = self._datatypes.get_type_by_id(dtype_id)
self._create_by_node_elem(dt_node_elem)

def _is_leaf(self, node) -> bool:
def _is_leaf(self) -> bool:
"""
/!\\ PRIVATE : do not use /!\\
Check if a SCDNode is leaf
Parameters
----------
`node`
The SCDNode to check
Returns
-------
`bool`
Return True if the node is leaf.
"""
# return len(node.get_children()) == 0 and isinstance(node, DA) and hasattr(node, 'parent')

return len(node.get_children()) == 0 and isinstance(node, DA) and hasattr(node, 'parent')
return isinstance(self, DA) \
and hasattr(self, 'parent') \
and len([n for n in self.get_children() if isinstance(n, DA)]) == 0

def _collect_DA_leaf_nodes(self, node, leaves: dict) -> dict:
"""
Expand All @@ -587,7 +585,7 @@ def _collect_DA_leaf_nodes(self, node, leaves: dict) -> dict:
The found leaves dictionnary.
"""
if node is not None:
if self._is_leaf(node):
if node._is_leaf():
leaves[node.get_path_from_ld()] = node

else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scd_manager.py → tests/test_scl_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def test_IED_get_lds(self):
assert len(result) == 11
assert isinstance(result[0], LD)

def test_IED_get_node_by_ref(self):
def test_IED_get_node_by_path(self):
ied = self.SCD_HANDLER.get_IED_by_name('AUT1A_SITE_1')

assert ied.get_node_by_path('LDASLD').name == 'LDASLD'
Expand Down Expand Up @@ -586,7 +586,7 @@ def test_get_name_subtree(self):
ln = ied.PROCESS_AP.Server.LDASLD.PTRC2
with pytest.raises(AssertionError):
ied.get_name_subtree()
assert(ied.PROCESS_AP.Server.LDASLD.get_name_subtree() == ('LDASLD', [('LLN0', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Health', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('InRef1', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef2', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef3', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef4', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef5', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef6', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef7', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('Mod', [('ctlModel', []), ('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('NamPlt', [('ldNs', []), ('d', []), ('paramRev', []), ('valRev', []), ('vendor', [])])]), ('RBRF2', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('RBRF1', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('PTRC2', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('PTRC1', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('RBRF3', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('LPHD0', [('NamPlt', [('configRev', []), ('d', []), ('paramRev', []), ('swRev', []), ('valRev', []), ('vendor', [])]), ('PhyHealth', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('PhyNam', [('d', []), ('hwRev', []), ('location', []), ('mRID', []), ('model', []), ('serNum', []), ('swRev', []), ('vendor', [])]), ('Proxy', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])])]), ('PTRC3', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])])]))
assert(ied.PROCESS_AP.Server.LDASLD.get_name_subtree() == ('LDASLD', [('LLN0', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Health', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('InRef1', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef2', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef3', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef4', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef5', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef6', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('InRef7', [('d', []), ('intAddr', []), ('purpose', []), ('setSrcCB', []), ('setSrcRef', []), ('setTstCB', []), ('setTstRef', []), ('tstEna', [])]), ('Mod', [('ctlModel', []), ('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('NamPlt', [('ldNs', []), ('configRev', []), ('d', []), ('paramRev', []), ('swRev', []), ('valRev', []), ('vendor', [])])]), ('RBRF2', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('RBRF1', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('PTRC2', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('PTRC1', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('RBRF3', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('OpEx', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]), ('LPHD0', [('NamPlt', [('configRev', []), ('d', []), ('paramRev', []), ('swRev', []), ('valRev', []), ('vendor', [])]), ('PhyHealth', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('PhyNam', [('d', []), ('hwRev', []), ('location', []), ('mRID', []), ('model', []), ('serNum', []), ('swRev', []), ('vendor', [])]), ('Proxy', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])])]), ('PTRC3', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])])]))
assert(ln.get_name_subtree() == ('PTRC2', [('Beh', [('blkEna', []), ('d', []), ('q', []), ('stVal', []), ('subEna', []), ('subID', []), ('subQ', []), ('subVal', []), ('t', [])]), ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])])]))
assert(ln.Tr.d.get_name_subtree() == ('d', []) )
assert(ln.Tr.get_name_subtree() == ('Tr', [('d', []), ('general', []), ('neut', []), ('phsA', []), ('phsB', []), ('phsC', []), ('q', []), ('t', []), ('originSrc', [('orCat', []), ('orIdent', [])])]))
Expand Down

0 comments on commit a9ae1af

Please sign in to comment.