Skip to content

Commit

Permalink
Added detach method to branch (#702)
Browse files Browse the repository at this point in the history
* Added `detach` method to branch

* docstring
  • Loading branch information
Helveg committed Apr 4, 2023
1 parent b1a2025 commit 63f0954
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions bsb/morphologies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,13 @@ def insert_branch(self, branch, index):
second_segment.attach_child(b)
first_segment.attach_child(second_segment)

def detach(self):
"""
Detach the branch from its parent, if one exists.
"""
if self.parent:
self.parent.detach_child(self)

def detach_child(self, branch):
"""
Remove a branch as a child from this branch.
Expand Down
7 changes: 5 additions & 2 deletions tests/test_morphologies.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ def test_branch_attachment(self):
self.assertTrue(branch_C.is_terminal)
self.assertTrue(branch_D.is_terminal)
branch_A.detach_child(branch_C)
self.assertIsNone(branch_C._parent)
self.assertIsNone(branch_C.parent)
with self.assertRaises(ValueError):
branch_A.detach_child(branch_D)
self.assertEqual(branch_B, branch_D._parent)
self.assertEqual(branch_B, branch_D.parent)
branch_B.detach()
branch_B.detach()
self.assertEqual(None, branch_B.parent)

def test_properties(self):
branch = Branch(
Expand Down

0 comments on commit 63f0954

Please sign in to comment.