Selector should not receive both response and text

This commit is contained in:
Νικόλαος-Διγενής Καραγιάννης 2016-07-29 17:13:59 +03:00
parent ba6dbad1e0
commit 643dbeffcf
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):