MCPcopy
hub / github.com/scrapy/scrapy / test_xmliter

Method test_xmliter

tests/test_utils_iterators.py:26–55  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

24 raise NotImplementedError
25
26 def test_xmliter(self):
27 body = b"""
28 <?xml version="1.0" encoding="UTF-8"?>
29 <products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30 xsi:noNamespaceSchemaLocation="someschmea.xsd">
31 <product id="001">
32 <type>Type 1</type>
33 <name>Name 1</name>
34 </product>
35 <product id="002">
36 <type>Type 2</type>
37 <name>Name 2</name>
38 </product>
39 </products>
40 """
41
42 response = XmlResponse(url="http://example.com", body=body)
43 attrs = [
44 (
45 x.attrib["id"],
46 x.xpath("name/text()").getall(),
47 x.xpath("./type/text()").getall(),
48 )
49 for x in self.xmliter(response, "product")
50 ]
51
52 assert attrs == [
53 ("001", ["Name 1"], ["Type 1"]),
54 ("002", ["Name 2"], ["Type 2"]),
55 ]
56
57 def test_xmliter_unusual_node(self):
58 body = b"""<?xml version="1.0" encoding="UTF-8"?>

Callers

nothing calls this directly

Calls 3

xmliterMethod · 0.95
XmlResponseClass · 0.90
xpathMethod · 0.45

Tested by

no test coverage detected