MCPcopy
hub / github.com/scrapy/scrapy / test_simple_selection

Method test_simple_selection

tests/test_selector.py:15–40  ·  view source on GitHub ↗

Simple selector tests

(self)

Source from the content-addressed store, hash-verified

13
14class TestSelector:
15 def test_simple_selection(self):
16 """Simple selector tests"""
17 body = b"<p><input name='a'value='1'/><input name='b'value='2'/></p>"
18 response = TextResponse(url="http://example.com", body=body, encoding="utf-8")
19 sel = Selector(response)
20
21 xl = sel.xpath("//input")
22 assert len(xl) == 2
23 for x in xl:
24 assert isinstance(x, Selector)
25
26 assert sel.xpath("//input").getall() == [x.get() for x in sel.xpath("//input")]
27 assert [x.get() for x in sel.xpath("//input[@name='a']/@name")] == ["a"]
28 assert [
29 x.get()
30 for x in sel.xpath(
31 "number(concat(//input[@name='a']/@value, //input[@name='b']/@value))"
32 )
33 ] == ["12.0"]
34 assert sel.xpath("concat('xpath', 'rules')").getall() == ["xpathrules"]
35 assert [
36 x.get()
37 for x in sel.xpath(
38 "concat(//input[@name='a']/@value, //input[@name='b']/@value)"
39 )
40 ] == ["12"]
41
42 def test_root_base_url(self):
43 body = b'<html><form action="/path"><input name="a" /></form></html>'

Callers

nothing calls this directly

Calls 4

TextResponseClass · 0.90
SelectorClass · 0.90
xpathMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected