added tests for ResponseSoup and ResponseLibxml2 extensions

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40733
This commit is contained in:
Pablo Hoffman 2009-01-15 03:06:00 +00:00
parent 604af8e74f
commit d26a54f541
2 changed files with 57 additions and 0 deletions

View File

@ -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 soup3

View File

@ -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