Skip to content

Commit 9e70b8d

Browse files
committed
[test/section] Add clone keep_id test
1 parent 8fae3e3 commit 9e70b8d

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/test_section.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,30 @@ def test_clone(self):
274274
self.assertListEqual(clone_sec.sections, [])
275275
self.assertListEqual(clone_sec.properties, [])
276276

277+
def test_clone_keep_id(self):
278+
# Check id kept in clone.
279+
sec = Section(name="original")
280+
clone_sec = sec.clone(keep_id=True)
281+
self.assertEqual(sec, clone_sec)
282+
self.assertEqual(sec.id, clone_sec.id)
283+
284+
# Check cloned child Sections keep their ids.
285+
Section(name="sec_one", parent=sec)
286+
Section(name="sec_two", parent=sec)
287+
clone_sec = sec.clone(keep_id=True)
288+
self.assertListEqual(sec.sections, clone_sec.sections)
289+
self.assertEqual(sec.sections["sec_one"], clone_sec.sections["sec_one"])
290+
self.assertEqual(sec.sections["sec_one"].id, clone_sec.sections["sec_one"].id)
291+
292+
# Check cloned child Properties keep their ids.
293+
Property(name="prop_one", parent=sec)
294+
Property(name="prop_two", parent=sec)
295+
clone_sec = sec.clone(keep_id=True)
296+
self.assertListEqual(sec.properties, clone_sec.properties)
297+
self.assertEqual(sec.properties["prop_one"], clone_sec.properties["prop_one"])
298+
self.assertEqual(sec.properties["prop_one"].id,
299+
clone_sec.properties["prop_one"].id)
300+
277301
def test_reorder(self):
278302
# Test reorder of document sections
279303
doc = Document()

0 commit comments

Comments
 (0)