def test_dump(self): """ L{SequenceSchema.dump} creates a L{etree.Element} out of a L{SequenceItem}. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) foo = SequenceItem(schema) foo.append().bar = "egg" self.assertEqual("<foo><item><bar>egg</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_dump(self): """ L{SequenceSchema.dump} creates a L{etree.Element} out of a L{SequenceItem}. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) foo = SequenceItem(schema) foo.append().bar = "egg" self.assertEqual("<foo><item><bar>egg</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_dump_with_many_items(self): """ L{SequenceSchema.dump} supports many child items in the sequence. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) foo = SequenceItem(schema) foo.append().bar = "spam0" foo.append().bar = "spam1" self.assertEqual( "<foo>" "<item><bar>spam0</bar></item>" "<item><bar>spam1</bar></item>" "</foo>", etree.tostring(schema.dump(foo)))
def test_dump_with_many_items(self): """ L{SequenceSchema.dump} supports many child items in the sequence. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) foo = SequenceItem(schema) foo.append().bar = "spam0" foo.append().bar = "spam1" self.assertEqual("<foo>" "<item><bar>spam0</bar></item>" "<item><bar>spam1</bar></item>" "</foo>", etree.tostring(schema.dump(foo)))
def test_remove(self): """ L{SequenceItem.remove} removes the given item from the sequence. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>") foo = schema.create(root) foo.remove(foo[0]) self.assertEqual("egg1", foo[0].bar) self.assertEqual("<foo><item><bar>egg1</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_remove(self): """ L{SequenceItem.remove} removes the given item from the sequence. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>") foo = schema.create(root) foo.remove(foo[0]) self.assertEqual("egg1", foo[0].bar) self.assertEqual("<foo><item><bar>egg1</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_delitem(self): """ L{SequenceItem.__delitem__} removes from the sequence the item with the given index. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>") foo = schema.create(root) del foo[0] self.assertEqual("egg1", foo[0].bar) self.assertEqual("<foo><item><bar>egg1</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_append(self): """ L{SequenceItem.append} adds a new item to the sequence, appending it at the end. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo><item><bar>egg0</bar></item></foo>") foo = schema.create(root) foo.append().bar = "egg1" self.assertEqual("egg1", foo[1].bar) self.assertEqual( "<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>", etree.tostring(schema.dump(foo)))
def test_delitem(self): """ L{SequenceItem.__delitem__} removes from the sequence the item with the given index. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>") foo = schema.create(root) del foo[0] self.assertEqual("egg1", foo[0].bar) self.assertEqual("<foo><item><bar>egg1</bar></item></foo>", etree.tostring(schema.dump(foo)))
def test_append(self): """ L{SequenceItem.append} adds a new item to the sequence, appending it at the end. """ schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")])) root = etree.fromstring("<foo><item><bar>egg0</bar></item></foo>") foo = schema.create(root) foo.append().bar = "egg1" self.assertEqual("egg1", foo[1].bar) self.assertEqual("<foo>" "<item><bar>egg0</bar></item>" "<item><bar>egg1</bar></item>" "</foo>", etree.tostring(schema.dump(foo)))