PK!pytest_mockservers/__init__.pyPK! ܎ͩ!pytest_mockservers/http_server.pyimport contextlib import socket from typing import Type import pytest from aiohttp import web, web_urldispatcher class Server: __slots__ = "_host", "_port", "_shutdown_timeout", "_app", "_app_runner" @property def host(self): return self._host @property def port(self): return self._port @property def router(self) -> web_urldispatcher.UrlDispatcher: return self._app.router def __init__(self, *, host: str, port: int, shutdown_timeout: float = 60) -> None: self._host = host self._port = port self._shutdown_timeout = shutdown_timeout self._app = web.Application() self._app_runner: web.AppRunner = None async def __aenter__(self): await self.serve() async def __aexit__(self, exc_type, exc, tb): await self.close() async def serve(self) -> None: self._app_runner = web.AppRunner(self._app) await self._app_runner.setup() await web.TCPSite( self._app_runner, host=self._host, port=self._port, shutdown_timeout=self._shutdown_timeout, ).start() async def close(self) -> None: await self._app_runner.cleanup() def _unused_port(): with contextlib.closing( socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) ) as sock: sock.bind(("127.0.0.1", 0)) return sock.getsockname()[1] @pytest.fixture def unused_port(): _unused_port() @pytest.fixture def unused_port_factory(): produced = set() def factory(): port = _unused_port() while port in produced: port = _unused_port() produced.add(port) return port return factory @pytest.fixture def http_server(unused_port_factory) -> Server: return Server(host="0.0.0.0", port=unused_port_factory()) @pytest.fixture def http_server_factory() -> Type[Server]: return Server PK! DD pytest_mockservers/udp_server.pyimport asyncio import contextlib import socket from asyncio import AbstractEventLoop, DatagramProtocol from typing import Type import pytest class DefaultProtocol(DatagramProtocol): def datagram_received(self, data, _addr): pass class Server: __slots__ = "_host", "_port", "_loop", "_protocol", "_transport" def __init__( self, *, host: str, port: int, loop: AbstractEventLoop = None, protocol: DatagramProtocol = None, ) -> None: self._host = host self._port = port self._loop = loop or asyncio.get_event_loop() self._protocol = protocol or DefaultProtocol self._transport = None async def __aenter__(self): listen = self._loop.create_datagram_endpoint( self._protocol, local_addr=(self._host, self._port) ) self._transport, _ = await listen async def __aexit__(self, exc_type, exc, tb): self._transport.close() self._transport = None def _unused_udp_port(): with contextlib.closing(socket.socket(type=socket.SOCK_DGRAM)) as sock: sock.bind(("127.0.0.1", 0)) return sock.getsockname()[1] @pytest.fixture def unused_udp_port(): return _unused_udp_port() @pytest.fixture def unused_udp_port_factory(): produced = set() def factory(): port = _unused_udp_port() while port in produced: port = _unused_udp_port() produced.add(port) return port return factory @pytest.fixture def udp_server_factory() -> Type[Server]: return Server PK!HBR/`3pytest_mockservers-0.3.0.dist-info/entry_points.txt.,I-.14())/N-*K-'gCDJSDrqPK!=-//*pytest_mockservers-0.3.0.dist-info/LICENSEMIT License Copyright (c) 2018 Nikita Grishko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H=jTT(pytest_mockservers-0.3.0.dist-info/WHEEL 1 0 нRN&":WhAqo;VSoBtM4[`Z} Mz7M*{/ܒ?֎XPK!Hz]g. +pytest_mockservers-0.3.0.dist-info/METADATAVmo6_qC6.,i֭Y,H} gdIʎ(;NbCOs A& ޥB64&_xtK8=Jm c3CkCgZtү66+KX`}6*T,M3/F{"9S9jO:v+ ΕC[C;lm1d q\ 8嫅Yl3(ݡd FcWˎT_?D\K\!^Y^±%;K,Ln\:S:4Jp&uR={⯣DcbJ:\bml:L͜t97E[D@($.8z>Y˸q3(0YWhWnf:A;ev@%Rw#EaVZ=Cު C~\**5|yoTGW+- 8Kcۮ2#%Y% #_) e?- >j/TS6g(qw㨑Dd"yDlfQ2KwqM MYS;}Z5{(ܨ,7CZ-Ĩ;Ym>C˫5H̶WI>eG`J=B/"b $6rS+]I \v _ Zjh},tA}@FE'L;=}6XC=sf& o.PK!pytest_mockservers/__init__.pyPK! ܎ͩ!<pytest_mockservers/http_server.pyPK! DD $pytest_mockservers/udp_server.pyPK!HBR/`3pytest_mockservers-0.3.0.dist-info/entry_points.txtPK!=-//*&pytest_mockservers-0.3.0.dist-info/LICENSEPK!H=jTT(pytest_mockservers-0.3.0.dist-info/WHEELPK!Hz]g. +7pytest_mockservers-0.3.0.dist-info/METADATAPK!Hr<)kpytest_mockservers-0.3.0.dist-info/RECORDPKJ