diff --git a/mocket/mocket.py b/mocket/mocket.py index c2c065cf..94581f11 100644 --- a/mocket/mocket.py +++ b/mocket/mocket.py @@ -235,6 +235,9 @@ def getpeername(self): def setblocking(self, block): self.settimeout(None) if block else self.settimeout(0.0) + def getblocking(self): + return self.gettimeout() is None + def getsockname(self): return socket.gethostbyname(self._address[0]), self._address[1] diff --git a/tests/main/test_socket.py b/tests/main/test_socket.py new file mode 100644 index 00000000..8a6e65ad --- /dev/null +++ b/tests/main/test_socket.py @@ -0,0 +1,13 @@ +import socket + +import pytest + +from mocket.mocket import MocketSocket + + +@pytest.mark.parametrize("blocking", (False, True)) +def test_blocking_socket(blocking): + sock = MocketSocket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect(("locahost", 1234)) + sock.setblocking(blocking) + assert sock.getblocking() is blocking