69xml='<r a="1">t</r>' 70self.assertRaises(TypeError,etree.adopt_external_document,None) 71capsule=self.as_capsule(xml) 72self.assertTrue(self.capsule_is_valid(capsule,DOC_NAME)) 73self.assertEqual(DOC_NAME,self.get_capsule_name(capsule)) 74# Create an lxml tree from the capsule (this is a move not a copy) 75root=etree.adopt_external_document(capsule).getroot() 76self.assertIsNone(self.get_capsule_name(capsule)) 77self.assertEqual(root.text,'t') 78root.text='new text' 79# Now reset the capsule so we can copy it 80self.assertEqual(0,self.set_capsule_name(capsule,DOC_NAME)) 81self.assertEqual(0,self.set_capsule_context(capsule,b'invalid')) 82# Create an lxml tree from the capsule (this is a copy not a move) 83root2=etree.adopt_external_document(capsule).getroot() 84self.assertEqual(self.get_capsule_context(capsule),b'invalid') 85# Check that the modification to the tree using the transferred 86# document was successful 87self.assertEqual(root.text,root2.text) 88# Check that further modifications do not show up in the copy (they are 89# disjoint) 90root.text='other text' 91self.assertNotEqual(root.text,root2.text) 92# delete root and ensure root2 survives 93delroot 94self.assertEqual(root2.text,'new text')