def testSetter(self): text = Node(node_type=Node.TEXT_NODE, node_name='#text', owner_document=self.document, read_only=False) text.node_value = 'bar' self.assertEqual(text.node_value, 'bar')
def testSetter_ReadOnly(self): text = Node(node_type=Node.TEXT_NODE, node_name='#text', owner_document=self.document, node_value='foo', read_only=True) # Testing with self.assertRaises(DOMException) as context_manager: text.node_value = 'bar' self.assertEqual(context_manager.exception.code, DOMException.NO_MODIFICATION_ALLOWED_ERR) # `node_value` should not be modified. self.assertEqual(text.node_value, 'foo')
def testSetter_WrongTypes(self): for node_type in [-1, None, 'hi', True, Node, Node, 'DOCUMENT_NODE']: with self.subTest(node_type=node_type): with self.assertRaises((TypeError, ValueError)): Node(node_type=node_type, node_name='', owner_document=self.document)
def testConstructor(self): text = Node(node_type=Node.TEXT_NODE, node_name='#text', owner_document=self.document, node_value='foo', read_only=False) self.assertEqual(text.node_value, 'foo')
def test_Raises_NO_MODIFICATION_ALLOWED_ERR(self): # ====================================== # <document> # <parent_node readonly="true"/> # <new_child_node/> # <document> # ====================================== parent_node_readonly = Node(node_type=Node.ELEMENT_NODE, node_name='tagName', owner_document=self.document, read_only=True) new_child_node = _create_element_node(self.document) # Testing with self.assertRaises(DOMException) as context_manager: parent_node_readonly.append_child(new_child_node) self.assertEqual(context_manager.exception.code, DOMException.NO_MODIFICATION_ALLOWED_ERR)
def test_Default(self): # Creating document node. document = Node(node_type=Node.DOCUMENT_NODE, node_name='#document', owner_document=None, read_only=False) self.assertEqual(document.node_type, Node.DOCUMENT_NODE) self.assertEqual(document.node_name, '#document') self.assertEqual(document.node_value, '')
def test_Raises_NO_MODIFICATION_ALLOWED_ERR(self): # ====================================== # <document> # <parent_node read-only="true"> # <child_node/> # </parent_node> # <document> # ====================================== child_node = _create_element_node(self.document) parent_node = Node(node_type=Node.ELEMENT_NODE, node_name='tagName', owner_document=self.document, child_nodes=[child_node], read_only=True) # Testing with self.assertRaises(DOMException) as context_manager: parent_node.remove_child(child_node) self.assertEqual(context_manager.exception.code, DOMException.NO_MODIFICATION_ALLOWED_ERR)
def test_AppendDocumentFragmentNode(self): # ====================================== # <document> # <parent_node/> # # <docfrag_node> # <first_child_node/> # <second_child_node/> # </docfrag_node> # <document> # ====================================== parent_node = _create_element_node(self.document) docfrag_node = Node(node_type=Node.DOCUMENT_FRAGMENT_NODE, node_name='#document-fragment', owner_document=self.document) first_child_node = _create_element_node(self.document) second_child_node = _create_element_node(self.document) docfrag_node.append_child(first_child_node) docfrag_node.append_child(second_child_node) # Testing parent_node.append_child(docfrag_node) self.assertEqual(parent_node.child_nodes.item(0), first_child_node) self.assertEqual(parent_node.child_nodes.item(1), second_child_node) self.assertEqual(parent_node.child_nodes.length, 2)
def testSetter_CorrectTypes(self): for node_type in Node: with self.subTest(node_type=node_type): Node(node_type=node_type, node_name='', owner_document=self.document)
def testGetter(self): for node_type in Node: node = Node(node_type=node_type, node_name='', owner_document=self.document) self.assertEqual(node.node_type, node_type)
def _create_document_node(): return Node(node_type=Node.DOCUMENT_NODE, node_name='#document', owner_document=None)
def testGetter(self): text = Node(node_type=Node.TEXT_NODE, node_name='#text', owner_document=self.document, node_value='lorem ipsum') self.assertEqual(text.node_value, 'lorem ipsum')
def _create_element_node(document: Node): assert document.node_type == Node.DOCUMENT_NODE return Node(node_type=Node.ELEMENT_NODE, node_name='tagName', owner_document=document)
def testConstrutor(self): docfrag = Node(node_type=Node.DOCUMENT_FRAGMENT_NODE, node_name='#document-fragment', owner_document=self.document) self.assertIsNone(docfrag.parent_node)
def _create_text_node(document: Node): assert document.node_type == NodeType.DOCUMENT_NODE return Node(node_type=NodeType.TEXT_NODE, node_name='#text', owner_document=document)