mindflayer / python-mocket

a socket mock framework - for all kinds of socket animals, web-clients included
BSD 3-Clause "New" or "Revised" License
281 stars 42 forks source link

Documentation on direct socket mocking? #208

Closed j3pic closed 10 months ago

j3pic commented 11 months ago

I have a project that directly uses sockets, without HTTP. But all the documentation is geared towards HTTP. What can Mocket do when it comes to opening and closing connections (both via connect or create_connection, and via listen and accept), sending and receiving data, and using select.epoll?

Also, are UDP sockets supported in any way? What about UNIX domain sockets, which can transfer not only bytes but also file descriptors?

mindflayer commented 11 months ago

Hi @j3pic, the only meaningful examples, like you said, are showing how to mock HTTP[S]. Many users ended up using Mocket for replacing HTTPretty, which is only capable of mocking web clients.

This said, Mocket also implements a stub for mocking Redis, which does not use HTTP as communication protocol. That's for sure the biggest example of a non-web mock. See: https://github.com/mindflayer/python-mocket/blob/main/mocket/mockredis.py

You'll probably realise you need three main components:

You can close the loop having a look at the tests for the above mock: https://github.com/mindflayer/python-mocket/blob/main/tests/main/test_redis.py

mindflayer commented 11 months ago

Answering your first question, create_connection and connect are already mocked. It's all done in https://github.com/mindflayer/python-mocket/blob/main/mocket/mocket.py MocketSocket is pretty advance, supporting even non-blocking sockets.

mindflayer commented 10 months ago

Hi @j3pic, did you manage to get started with low-level mocking of the socket module?

mindflayer commented 10 months ago

Feel free to open a new issue with a more specific question. Thanks!