Skip to content

Commit

Permalink
Merge pull request #228 from mindflayer/feat/get-blocking
Browse files Browse the repository at this point in the history
Add getblocking() method
  • Loading branch information
mindflayer authored Apr 14, 2024
2 parents c4240b7 + 442aaaf commit 1eefc61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
13 changes: 13 additions & 0 deletions tests/main/test_socket.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1eefc61

Please sign in to comment.