コード例 #1
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_reset_event_when_event_is_set_and_put_nowait_is_called(
            self):
        queue = Queue()
        queue._finished.set()
        queue.put_nowait(2)

        assert not queue._finished.is_set()
コード例 #2
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_work_when_adding_item_with_put_method(self):
        queue = Queue(size=3)
        await queue.put(2)
        await queue.put('foo')

        assert 2 == queue.length
        assert 2 == queue._tasks_in_progress
コード例 #3
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_raise_error_when_task_done_is_called_without_adding_items_in_queue(
            self):
        async with Queue(size=1) as queue:
            with pytest.raises(ValueError) as exc_info:
                queue.task_done()

            assert 'task_done method was calling too many times without adding items in queue' == str(
                exc_info.value)
コード例 #4
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_should_work_with_default_initialization(self):
     queue = Queue()
     assert 1 == queue.maxsize
     assert 0 == queue.length
     assert [] == queue._items
     assert 0 == queue._tasks_in_progress
     assert isinstance(queue._send_channel, MemoryObjectSendStream)
     assert isinstance(queue._receive_channel, MemoryObjectReceiveStream)
     assert isinstance(queue._finished, anyio.Event)
コード例 #5
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_work_when_using_context_manager(self):
        async with Queue(size=1) as queue:
            queue.put_nowait(2)

        with pytest.raises(anyio.ClosedResourceError):
            queue.put_nowait(3)

        with pytest.raises(anyio.ClosedResourceError):
            queue.get_nowait()
コード例 #6
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_work_when_calling_close_method(self):
        queue = Queue()
        await queue.close()

        with pytest.raises(anyio.ClosedResourceError):
            await queue.put(2)

        with pytest.raises(anyio.ClosedResourceError):
            await queue.get()
コード例 #7
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_raise_would_block_error_when_buffer_is_full_and_put_nowait_is_used(
            self):
        queue = Queue()
        queue.put_nowait(1)

        with pytest.raises(anyio.WouldBlock):
            queue.put_nowait(2)
コード例 #8
0
    async def test_should_follow_unprocessed_url(self, chrome_driver):
        url = 'http://foo.com'
        response = SeleniumResponse(
            driver=chrome_driver,
            handle='4',
            reachable_urls={'http://bar.com'},
            followed_urls=set(),
            queue=Queue(size=1),
        )
        await response.follow(url)

        assert {'http://bar.com'} == response._reachable_urls
        assert {url} == response._followed_urls
        assert 1 == response._queue.length
コード例 #9
0
 async def test_should_not_follow_already_processed_url(
         self, mocker, chrome_driver, reachable_urls, followed_urls):
     logger_mock = mocker.patch('logging.Logger.debug')
     url = 'http://foo.com'
     response = SeleniumResponse(
         driver=chrome_driver,
         handle='4',
         reachable_urls=reachable_urls,
         followed_urls=followed_urls,
         queue=Queue(),
     )
     await response.follow(url)
     assert mocker.call(
         'url %s has already been processed, nothing to do here',
         url) in logger_mock.call_args_list
コード例 #10
0
    async def test_should_follow_unprocessed_url(self):
        url = 'http://foo.com'
        request = httpx.Request('GET', url)
        httpx_response = httpx.Response(200, request=request)
        queue = Queue(2)
        response = StaticResponse(reachable_urls={'http://bar.com'},
                                  followed_urls=set(),
                                  queue=queue,
                                  httpx_response=httpx_response)
        await response.follow(url)
        queue_length = queue.length
        await queue.close()

        assert {'http://bar.com'} == response._reachable_urls
        assert {url} == response._followed_urls
        assert 1 == queue_length
コード例 #11
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_work_when_using_task_done_and_join_methods(self):
        async with Queue(size=1) as queue:
            await queue.put(2)
            await queue.get()
            assert 1 == queue._tasks_in_progress

            with anyio.move_on_after(1) as cancel_scope:
                await queue.join()

            assert cancel_scope.cancel_called
            queue.task_done()
            assert 0 == queue._tasks_in_progress

            with anyio.move_on_after(1) as cancel_scope:
                await queue.join()

            assert not cancel_scope.cancel_called
コード例 #12
0
    async def test_should_not_follow_already_processed_url(
            self, mocker, reachable_urls, followed_urls):
        logger_mock = mocker.patch('logging.Logger.debug')
        url = 'http://foo.com'
        request = httpx.Request('GET', url)
        httpx_response = httpx.Response(200, request=request)
        queue = Queue()
        response = StaticResponse(reachable_urls=reachable_urls,
                                  followed_urls=followed_urls,
                                  queue=queue,
                                  httpx_response=httpx_response)

        await response.follow(url)
        await queue.close()

        assert mocker.call(
            'url %s has already been processed, nothing to do here',
            url) in logger_mock.call_args_list
コード例 #13
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_work_when_using_get_nowait_method(self):
        queue = Queue(3, items=[2, 'foo'])

        assert 2 == queue.get_nowait()
        assert 'foo' == queue.get_nowait()
コード例 #14
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_should_raise_error_when_size_is_less_than_items_length(
         self):
     with pytest.raises(anyio.WouldBlock):
         Queue(size=1, items=[2, 'foo'])
コード例 #15
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_raise_would_block_error_when_using_get_nowait_on_empty_buffer(
            self):
        queue = Queue()

        with pytest.raises(anyio.WouldBlock):
            queue.get_nowait()
コード例 #16
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
    async def test_should_raise_error_when_size_is_negative(self):
        with pytest.raises(ValueError) as exc_info:
            Queue(size=-1)

        assert 'size must not be less than 1 but you provide: -1' == str(
            exc_info.value)
コード例 #17
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_should_work_when_initializing_with_size_and_items(self):
     items = [2, 'foo']
     queue = Queue(size=3, items=items)
     assert 3 == queue.maxsize
     assert 2 == queue.length
     assert items == queue._items
コード例 #18
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_length_property_works_with_infinity_size(self):
     queue = Queue(size=math.inf)
     assert 0 == queue.length
     assert queue.maxsize is math.inf
コード例 #19
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_should_work_when_initializing_items(self):
     items = [2, 'foo']
     queue = Queue(3, items=items)
     assert 3 == queue.maxsize
     assert items == queue._items
     assert len(items) == queue.length == queue._tasks_in_progress
コード例 #20
0
ファイル: test_queue.py プロジェクト: lewoudar/scalpel
 async def test_should_work_when_initializing_buffer_size(self):
     queue = Queue(size=3)
     assert 3 == queue.maxsize
     assert 0 == queue.length