1- from pytest import mark
1+ import pytest
22from twisted .trial import unittest
33
4+ from scrapy .exceptions import ScrapyDeprecationWarning
45from scrapy .http import Response , TextResponse , XmlResponse
56from scrapy .utils .iterators import _body_or_str , csviter , xmliter , xmliter_lxml
67from tests import get_testdata
78
89
9- class XmliterTestCase (unittest .TestCase ):
10- xmliter = staticmethod (xmliter )
11-
10+ class XmliterBaseTestCase :
11+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
1212 def test_xmliter (self ):
1313 body = b"""
1414 <?xml version="1.0" encoding="UTF-8"?>
@@ -40,6 +40,7 @@ def test_xmliter(self):
4040 attrs , [("001" , ["Name 1" ], ["Type 1" ]), ("002" , ["Name 2" ], ["Type 2" ])]
4141 )
4242
43+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
4344 def test_xmliter_unusual_node (self ):
4445 body = b"""<?xml version="1.0" encoding="UTF-8"?>
4546 <root>
@@ -53,6 +54,7 @@ def test_xmliter_unusual_node(self):
5354 ]
5455 self .assertEqual (nodenames , [["matchme..." ]])
5556
57+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
5658 def test_xmliter_unicode (self ):
5759 # example taken from https://github.com/scrapy/scrapy/issues/1665
5860 body = """<?xml version="1.0" encoding="UTF-8"?>
@@ -112,6 +114,7 @@ def test_xmliter_unicode(self):
112114 [("26" , ["-" ], ["80" ]), ("21" , ["Ab" ], ["76" ]), ("27" , ["A" ], ["27" ])],
113115 )
114116
117+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
115118 def test_xmliter_text (self ):
116119 body = (
117120 '<?xml version="1.0" encoding="UTF-8"?>'
@@ -123,6 +126,7 @@ def test_xmliter_text(self):
123126 [["one" ], ["two" ]],
124127 )
125128
129+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
126130 def test_xmliter_namespaces (self ):
127131 body = b"""
128132 <?xml version="1.0" encoding="UTF-8"?>
@@ -162,6 +166,7 @@ def test_xmliter_namespaces(self):
162166 self .assertEqual (node .xpath ("id/text()" ).getall (), [])
163167 self .assertEqual (node .xpath ("price/text()" ).getall (), [])
164168
169+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
165170 def test_xmliter_namespaced_nodename (self ):
166171 body = b"""
167172 <?xml version="1.0" encoding="UTF-8"?>
@@ -190,6 +195,7 @@ def test_xmliter_namespaced_nodename(self):
190195 ["http://www.mydummycompany.com/images/item1.jpg" ],
191196 )
192197
198+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
193199 def test_xmliter_namespaced_nodename_missing (self ):
194200 body = b"""
195201 <?xml version="1.0" encoding="UTF-8"?>
@@ -214,6 +220,7 @@ def test_xmliter_namespaced_nodename_missing(self):
214220 with self .assertRaises (StopIteration ):
215221 next (my_iter )
216222
223+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
217224 def test_xmliter_exception (self ):
218225 body = (
219226 '<?xml version="1.0" encoding="UTF-8"?>'
@@ -226,10 +233,12 @@ def test_xmliter_exception(self):
226233
227234 self .assertRaises (StopIteration , next , iter )
228235
236+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
229237 def test_xmliter_objtype_exception (self ):
230238 i = self .xmliter (42 , "product" )
231239 self .assertRaises (TypeError , next , i )
232240
241+ @pytest .mark .filterwarnings ("ignore::scrapy.exceptions.ScrapyDeprecationWarning" )
233242 def test_xmliter_encoding (self ):
234243 body = (
235244 b'<?xml version="1.0" encoding="ISO-8859-9"?>\n '
@@ -244,12 +253,25 @@ def test_xmliter_encoding(self):
244253 )
245254
246255
247- class LxmlXmliterTestCase ( XmliterTestCase ):
248- xmliter = staticmethod (xmliter_lxml )
256+ class XmliterTestCase ( XmliterBaseTestCase , unittest . TestCase ):
257+ xmliter = staticmethod (xmliter )
249258
250- @mark .xfail (reason = "known bug of the current implementation" )
251- def test_xmliter_namespaced_nodename (self ):
252- super ().test_xmliter_namespaced_nodename ()
259+ def test_deprecation (self ):
260+ body = b"""
261+ <?xml version="1.0" encoding="UTF-8"?>
262+ <products>
263+ <product></product>
264+ </products>
265+ """
266+ with pytest .warns (
267+ ScrapyDeprecationWarning ,
268+ match = "xmliter" ,
269+ ):
270+ next (self .xmliter (body , "product" ))
271+
272+
273+ class LxmlXmliterTestCase (XmliterBaseTestCase , unittest .TestCase ):
274+ xmliter = staticmethod (xmliter_lxml )
253275
254276 def test_xmliter_iterate_namespace (self ):
255277 body = b"""
0 commit comments