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

Method test_simple_selection

tests/test_selector.py:15–40  ·  tests/test_selector.py::TestSelector.test_simple_selection

Simple selector tests

(self)

Source from the content-addressed store, hash-verified

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