def test_xpath_attr(self):
    testxml = '<root>\n            <div>\n                <p x="a">Foo</p>\n            </div>\n        </root>'
    doc = compat_etree_fromstring(testxml)
    self.assertEqual(xpath_attr(doc, 'div/p', 'x'), 'a')
    self.assertEqual(xpath_attr(doc, 'div/bar', 'x'), None)
    self.assertEqual(xpath_attr(doc, 'div/p', 'y'), None)
    self.assertEqual(xpath_attr(doc, 'div/bar', 'x', default='default'), 'default')
    self.assertEqual(xpath_attr(doc, 'div/p', 'y', default='default'), 'default')
    self.assertRaises(ExtractorError, xpath_attr, doc, 'div/bar', 'x', fatal=True)
    self.assertRaises(ExtractorError, xpath_attr, doc, 'div/p', 'y', fatal=True)
def test_xpath_attr(self):
    testxml = '<root>\n            <div>\n                <p x="a">Foo</p>\n            </div>\n        </root>'
    doc = compat_etree_fromstring(testxml)
    self.assertEqual(xpath_attr(doc, 'div/p', 'x'), 'a')
    self.assertEqual(xpath_attr(doc, 'div/bar', 'x'), None)
    self.assertEqual(xpath_attr(doc, 'div/p', 'y'), None)
    self.assertEqual(xpath_attr(doc, 'div/bar', 'x', default='default'), 'default')
    self.assertEqual(xpath_attr(doc, 'div/p', 'y', default='default'), 'default')
    self.assertRaises(ExtractorError, xpath_attr, doc, 'div/bar', 'x', fatal=True)
    self.assertRaises(ExtractorError, xpath_attr, doc, 'div/p', 'y', fatal=True)