Skip to content

Commit c69082b

Browse files
committed
Table: single deepcopy of .attributes test
1 parent ddd7d83 commit c69082b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Orange/tests/test_table.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,24 @@ def test_attributes_copied(self):
20682068
# attributes dict of old table not be changed since new dist is a copy
20692069
self.assertDictEqual(self.table.attributes, {"A": "Test", "B": []})
20702070

2071+
def test_attributes_copied_once(self):
2072+
A = Mock()
2073+
A.__deepcopy__ = Mock()
2074+
self.table.attributes = {"A": A}
2075+
2076+
# a single direct transformation
2077+
self.table.from_table(self.table.domain, self.table)
2078+
self.assertEqual(1, A.__deepcopy__.call_count)
2079+
A.__deepcopy__.reset_mock()
2080+
2081+
# hierarchy of transformations
2082+
ndom = Domain([a.copy(compute_value=lambda x: x.transform(Domain([a])))
2083+
for a in self.table.domain.attributes])
2084+
self.table.from_table(ndom, self.table)
2085+
self.assertEqual(1, A.__deepcopy__.call_count)
2086+
# HISTORIC: before only the outermost transformation deepcopied the
2087+
# attributes, here were 23 calls to __deepcopy__ instead of 1
2088+
20712089

20722090
def isspecial(s):
20732091
return isinstance(s, slice) or s is Ellipsis

0 commit comments

Comments
 (0)