diff --git a/tests/test_linkextractors.py b/tests/test_linkextractors.py index d78b25f25..3e202bf02 100644 --- a/tests/test_linkextractors.py +++ b/tests/test_linkextractors.py @@ -1,5 +1,8 @@ import re import unittest + +import pytest + from scrapy.linkextractors.regex import RegexLinkExtractor from scrapy.http import HtmlResponse, XmlResponse from scrapy.link import Link @@ -9,7 +12,7 @@ from scrapy.linkextractors.lxmlhtml import LxmlLinkExtractor from tests import get_testdata -class LinkExtractorTestCase(unittest.TestCase): +class BaseSgmlLinkExtractorTestCase(unittest.TestCase): def test_basic(self): html = """
"""
response = HtmlResponse("http://example.com/index.html", body=html)
@@ -505,7 +494,7 @@ class SgmlLinkExtractorTestCase(unittest.TestCase):
])
-class LxmlLinkExtractorTestCase(SgmlLinkExtractorTestCase):
+class LxmlLinkExtractorTestCase(BaseLinkExtractorTestCase):
extractor_cls = LxmlLinkExtractor
def test_link_wrong_href(self):
@@ -521,6 +510,10 @@ class LxmlLinkExtractorTestCase(SgmlLinkExtractorTestCase):
Link(url='http://example.org/item3.html', text=u'Item 3', nofollow=False),
])
+ @pytest.mark.xfail
+ def test_restrict_xpaths_with_html_entities(self):
+ super(LxmlLinkExtractorTestCase, self).test_restrict_xpaths_with_html_entities()
+
class HtmlParserLinkExtractorTestCase(unittest.TestCase):
@@ -552,6 +545,39 @@ class HtmlParserLinkExtractorTestCase(unittest.TestCase):
])
+class SgmlLinkExtractorTestCase(BaseLinkExtractorTestCase):
+ extractor_cls = SgmlLinkExtractor
+
+ def test_deny_extensions(self):
+ html = """asd and """
+ response = HtmlResponse("http://example.org/", body=html)
+ lx = SgmlLinkExtractor(deny_extensions="jpg")
+ self.assertEqual(lx.extract_links(response), [
+ Link(url='http://example.org/page.html', text=u'asd'),
+ ])
+
+ def test_attrs_sgml(self):
+ html = """
+ sample text 2"""
+ response = HtmlResponse("http://example.com/index.html", body=html)
+ lx = SgmlLinkExtractor(attrs="href")
+ self.assertEqual(lx.extract_links(response), [
+ Link(url='http://example.com/sample1.html', text=u''),
+ ])
+
+ def test_link_nofollow(self):
+ html = """
+ Printer-friendly page
+ About us
+ """
+ response = HtmlResponse("http://example.org/page.html", body=html)
+ lx = SgmlLinkExtractor()
+ self.assertEqual([link for link in lx.extract_links(response)], [
+ Link(url='http://example.org/page.html?action=print', text=u'Printer-friendly page', nofollow=True),
+ Link(url='http://example.org/about.html', text=u'About us', nofollow=False),
+ ])
+
+
class RegexLinkExtractorTestCase(unittest.TestCase):
def setUp(self):
@@ -579,7 +605,3 @@ class RegexLinkExtractorTestCase(unittest.TestCase):
Link(url='http://example.org/item1.html', text=u'Item 1', nofollow=False),
Link(url='http://example.org/item3.html', text=u'Item 3', nofollow=False),
])
-
-
-if __name__ == "__main__":
- unittest.main()