Skip to content

Commit

Permalink
Re-add deepcopy signature and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
drodarie committed Jan 18, 2024
1 parent fa58d54 commit 478b393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bsb/config/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,11 @@ def get_tree(instance):


def make_copyable(node_cls):
def loc_copy(instance):
def loc_copy(instance, memo=None):
return type(instance)(instance.__tree__())

node_cls.__copy__ = loc_copy
node_cls.__deepcopy__ = loc_copy


def walk_node_attributes(node):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,10 @@ class Test:

class TestCopy(unittest.TestCase):
def test_copy(self):
"""
Check copy and deepcopy functions for the nodes.
"""

@config.node
class SubClass:
c = config.attr(
Expand All @@ -1306,6 +1310,12 @@ class MainClass:
instance = MainClass({"a": {"c": tab}, "b": 3.0})
copied = instance.__copy__()
self.assertTrue(id(instance.a) != id(copied.a))
# check that the c arrays elements are equals
self.assertTrue(np.all(instance.a.c == copied.a.c))
self.assertEqual(instance.b, copied.b)
copied = instance.__deepcopy__()
self.assertTrue(id(instance.a) != id(copied.a))
# check that the c arrays elements are equals
self.assertTrue(np.all(instance.a.c == copied.a.c))
self.assertEqual(instance.b, copied.b)

Expand Down

0 comments on commit 478b393

Please sign in to comment.