Merge pull request #2153 from Digenis/Selector_bad_args

[MRG+1] Selector should not receive both response and text
This commit is contained in:
Mikhail Korobov 2016-07-31 21:28:38 -04:00 committed by GitHub
commit 2c9a38d1f5
2 changed files with 8 additions and 0 deletions

View File

@ -46,6 +46,10 @@ class Selector(_ParselSelector, object_ref):
selectorlist_cls = SelectorList
def __init__(self, response=None, text=None, type=None, root=None, _root=None, **kwargs):
if not(response is None or text is None):
raise ValueError('%s.__init__() received both response and text'
% self.__class__.__name__)
st = _st(response, type or self._default_type)
if _root is not None:

View File

@ -123,6 +123,10 @@ class SelectorTestCase(unittest.TestCase):
sel.xpath('//p').extract_unquoted()
self.assertSubstring('Use .extract() instead', str(w[-1].message))
def test_selector_bad_args(self):
with self.assertRaisesRegexp(ValueError, 'received both response and text'):
Selector(TextResponse(url='http://example.com', body=b''), text=u'')
class DeprecatedXpathSelectorTest(unittest.TestCase):