def test_init(self): obj_none_text = parser.ObjectParser(self.root, 'xpath1', None) self.assertEqual('test', obj_none_text.text) obj_comment = parser.ObjectParser(self.comment, 'xpath2', 'foobar') self.assertEqual('comment', obj_comment.text) obj_text = parser.ObjectParser(self.root, 'xpath3', 'foobar') self.assertEqual('foobar', obj_text.text) obj_text = parser.ObjectParser(None, 'xpath3', None) self.assertEqual('', obj_text.text)
def test_get_parent_obj_parser(self): node = parser.ObjectParser(self.doc.find('child'), 'fake_xpath/@1', 'fake_txt') res = Parser.getParent(node) self.assertIsInstance(res, parser.ObjectParser) self.assertEqual('fake_xpath', res.xpath) self.assertEqual('sib test foo', res.text)
def test_get_text_with_decorator(self): node = parser.ObjectParser(self.doc, 'fake_xpath', 'fake_txt') res = Parser.getText(node) self.assertEqual('sib test foo', res)
def test_insert(self): obj_text = parser.ObjectParser(self.root, 'xpath3', 'foobar') obj_text.insert(1, self.comment)
def test_clear(self): obj_text = parser.ObjectParser(self.root, 'xpath3', 'foobar') obj_text.clear() self.assertIsNone(obj_text.text) self.assertIsNone(obj_text.xpath) self.assertEqual({}, obj_text.ele.attrib)