| 42 | |
| 43 | @pytest.mark.parametrize("test_peek", [True, False]) |
| 44 | def test_one_element(self, q: queuelib.queue.BaseQueue, test_peek: bool): |
| 45 | if test_peek and not HAVE_PEEK: |
| 46 | pytest.skip("The queuelib queues do not define peek") |
| 47 | if not test_peek and HAVE_PEEK: |
| 48 | pytest.skip("The queuelib queues define peek") |
| 49 | assert len(q) == 0 |
| 50 | if test_peek: |
| 51 | assert q.peek() is None |
| 52 | assert q.pop() is None |
| 53 | req = Request("http://www.example.com") |
| 54 | q.push(req) |
| 55 | assert len(q) == 1 |
| 56 | if test_peek: |
| 57 | result = q.peek() |
| 58 | assert result is not None |
| 59 | assert result.url == req.url |
| 60 | else: |
| 61 | with pytest.raises( |
| 62 | NotImplementedError, |
| 63 | match="The underlying queue class does not implement 'peek'", |
| 64 | ): |
| 65 | q.peek() |
| 66 | result = q.pop() |
| 67 | assert result is not None |
| 68 | assert result.url == req.url |
| 69 | assert len(q) == 0 |
| 70 | if test_peek: |
| 71 | assert q.peek() is None |
| 72 | assert q.pop() is None |
| 73 | q.close() |
| 74 | |
| 75 | @pytest.mark.parametrize("test_peek", [True, False]) |
| 76 | def test_order(self, q: queuelib.queue.BaseQueue, test_peek: bool): |