Skip to content

Commit

Permalink
Introduce SolipsismWarning class
Browse files Browse the repository at this point in the history
Use it for cases where emulation is incomplete but not critically so.
  • Loading branch information
bmerry committed Aug 9, 2020
1 parent 027fb01 commit 22ddf7b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/async_solipsism/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with async-solipsism. If not, see <https://www.gnu.org/licenses/>.

__all__ = ('ResolutionWarning', 'SolipsismError', 'SleepForeverError')
__all__ = ('ResolutionWarning', 'SolipsismWarning', 'SolipsismError', 'SleepForeverError')


class ResolutionWarning(Warning):
class SolipsismWarning(Warning):
pass


class ResolutionWarning(SolipsismWarning):
pass


Expand Down
4 changes: 2 additions & 2 deletions src/async_solipsism/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from collections import deque
import warnings

from .exceptions import SolipsismError
from .exceptions import SolipsismWarning, SolipsismError


DEFAULT_CAPACITY = 65536
Expand Down Expand Up @@ -120,7 +120,7 @@ def setsockopt(self, level, optname, value, optlen=None):
(socket.SOL_SOCKET, socket.SO_REUSEADDR),
(socket.SOL_SOCKET, socket.SO_REUSEPORT)
}:
warnings.warn(f'Ignoring socket option {level}:{optname}')
warnings.warn(f'Ignoring socket option {level}:{optname}', SolipsismWarning)
# TODO: implement SO_RCVBUF/SO_SNDBUF to change the queue capacity.


Expand Down
22 changes: 13 additions & 9 deletions test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def test_setblocking(sock):
sock.setblocking(True)


def test_setsockopt_known(sock, caplog):
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)


def test_setsockopt_unknown(sock, caplog):
try:
opt = socket.IP_MULTICAST_LOOP
except AttributeError:
pytest.skip('IP_MULTICAST_LOOP not defined')
with pytest.warns(async_solipsism.SolipsismWarning, match='Ignoring socket option'):
sock.setsockopt(socket.IPPROTO_IP, opt, 1)


@pytest.mark.parametrize(
'given, expected',
[
Expand All @@ -44,12 +57,3 @@ def test_setblocking(sock):
def test_sockaddr(given, expected):
sock = async_solipsism.socketpair(sock1_name=given)[0]
assert sock.getsockname() == expected


def test_setsockopt_known(sock):
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)


def test_setsockopt_unknown(sock):
with pytest.warns(UserWarning, match='Ignoring socket option'):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)

0 comments on commit 22ddf7b

Please sign in to comment.