Scrapy, a fast high-level web crawling & scraping framework for Python.
using bytes for response body in tests
Elias Dorneles8ef5aa2ffce4
diff --git a/tests/test_selector.py b/tests/test_selector.pyindex 4806bb90b..2d6d8c439 100644--- a/tests/test_selector.py+++ b/tests/test_selector.py@@ -1,9 +1,6 @@-import reimport warningsimport weakref-import sixfrom twisted.trial import unittest-from scrapy.exceptions import ScrapyDeprecationWarningfrom scrapy.http import TextResponse, HtmlResponse, XmlResponsefrom scrapy.selector import Selectorfrom scrapy.selector.lxmlsel import XmlXPathSelector, HtmlXPathSelector, XPathSelector@@ -14,7 +11,7 @@ class SelectorTestCase(unittest.TestCase):def test_simple_selection(self):"""Simple selector tests"""- body = u"<p><input name='a'value='1'/><input name='b'value='2'/></p>"+ body = b"<p><input name='a'value='1'/><input name='b'value='2'/></p>"response = TextResponse(url="http://example.com", body=body, encoding='utf-8')sel = Selector(response)@@ -53,7 +50,7 @@ class SelectorTestCase(unittest.TestCase):self.assertIn('Ignoring deprecated `_root` argument', str(w[-1].message))def test_flavor_detection(self):- text = u'<div><img src="a.jpg"><p>Hello</div>'+ text = b'<div><img src="a.jpg"><p>Hello</div>'sel = Selector(XmlResponse('http://example.com', body=text, encoding='utf-8'))self.assertEqual(sel.type, 'xml')self.assertEqual(sel.xpath("//div").extract(),@@ -86,7 +83,7 @@ class SelectorTestCase(unittest.TestCase):def test_badly_encoded_body(self):# \xe9 alone isn't valid utf8 sequencer1 = TextResponse('http://www.example.com', \- body=u'<html><p>an Jos\xe9 de</p><html>', \+ body=b'<html><p>an Jos\xe9 de</p><html>', \encoding='utf-8')Selector(r1).xpath('//text()').extract()@@ -100,7 +97,7 @@ class SelectorTestCase(unittest.TestCase):class DeprecatedXpathSelectorTest(unittest.TestCase):- text = u'<div><img src="a.jpg"><p>Hello</div>'+ text = '<div><img src="a.jpg"><p>Hello</div>'def test_warnings_xpathselector(self):cls = XPathSelector@@ -178,4 +175,4 @@ class DeprecatedXpathSelectorTest(unittest.TestCase):self.assertTrue(isinstance(sel, Selector))self.assertTrue(isinstance(usel, Selector))self.assertTrue(isinstance(sel, XPathSelector))- self.assertTrue(isinstance(usel, XPathSelector))\ No newline at end of file+ self.assertTrue(isinstance(usel, XPathSelector))