MCPcopy
hub / github.com/scrapy/scrapy / test_pop_order

Function test_pop_order

tests/test_pqueues.py:225–261  ·  view source on GitHub ↗
(input_, output)

Source from the content-addressed store, hash-verified

223 ],
224)
225def test_pop_order(input_, output):
226 def make_url(index):
227 return f"https://toscrape.com/{index}"
228
229 def make_request(index, data):
230 meta = {}
231 if data.get("start", False):
232 meta["is_start_request"] = True
233 return Request(
234 url=make_url(index),
235 priority=data.get("priority", 0),
236 meta=meta,
237 )
238
239 input_requests = [
240 make_request(index, data) for index, data in enumerate(input_, start=1)
241 ]
242 expected_output_urls = [make_url(index) for index in output]
243
244 crawler = get_crawler(Spider)
245 settings = crawler.settings
246 queue = build_from_crawler(
247 ScrapyPriorityQueue,
248 crawler,
249 downstream_queue_cls=load_object(settings["SCHEDULER_MEMORY_QUEUE"]),
250 key="",
251 start_queue_cls=load_object(settings["SCHEDULER_START_MEMORY_QUEUE"]),
252 )
253
254 for request in input_requests:
255 queue.push(request)
256
257 actual_output_urls = []
258 while request := queue.pop():
259 actual_output_urls.append(request.url)
260
261 assert actual_output_urls == expected_output_urls

Callers

nothing calls this directly

Calls 7

get_crawlerFunction · 0.90
build_from_crawlerFunction · 0.90
load_objectFunction · 0.90
make_urlFunction · 0.85
make_requestFunction · 0.70
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…