Scrapy, a fast high-level web crawling & scraping framework for Python.
added tests for ResponseSoup and ResponseLibxml2 extensions
Pablo Hoffmand26a54f54113
diff --git a/scrapy/trunk/scrapy/tests/test_contrib_response_soup.py b/scrapy/trunk/scrapy/tests/test_contrib_response_soup.pynew file mode 100644index 000000000..fee8e77e7--- /dev/null+++ b/scrapy/trunk/scrapy/tests/test_contrib_response_soup.py@@ -0,0 +1,32 @@+import unittest++from BeautifulSoup import BeautifulSoup++from scrapy.http import Response+from scrapy.contrib.response.soup import ResponseSoup++class ResponseSoupTest(unittest.TestCase):++ def setUp(self):+ ResponseSoup()++ def test_response_soup(self):+ r1 = Response('example.com', 'http://www.example.com', body='')++ soup1 = r1.getsoup()+ soup2 = r1.getsoup()++ assert isinstance(r1.soup, BeautifulSoup)+ assert isinstance(soup2, BeautifulSoup)+ # make sure it's cached+ assert soup1 is soup2++ def test_response_soup_caching(self):+ r1 = Response('example.com', 'http://www.example.com', body='')+ soup1 = r1.getsoup()+ r2 = r1.copy()+ soup2 = r1.getsoup()+ soup3 = r2.getsoup()++ assert soup1 is soup2+ assert soup1 is not soup3diff --git a/scrapy/trunk/scrapy/tests/test_xpath_extension.py b/scrapy/trunk/scrapy/tests/test_xpath_extension.pynew file mode 100644index 000000000..b0abcb4c0--- /dev/null+++ b/scrapy/trunk/scrapy/tests/test_xpath_extension.py@@ -0,0 +1,25 @@+import unittest++from scrapy.http import Response+from scrapy.xpath.extension import ResponseLibxml2++class ResponseLibxml2Test(unittest.TestCase):++ def setUp(self):+ ResponseLibxml2()++ def test_response_libxml2_caching(self):+ r1 = Response('example.com', 'http://www.example.com', body='<html><head></head><body></body></html>')+ r2 = r1.copy()++ doc1 = r1.getlibxml2doc()+ doc2 = r1.getlibxml2doc()+ doc3 = r2.getlibxml2doc()++ # make sure it's cached+ assert doc1 is doc2+ assert doc1 is not doc3++ # don't leave libxml2 documents in memory to avoid wrong libxml2 leaks reports+ del doc1, doc2, doc3+