1{
2 lib,
3 buildPythonPackage,
4 fetchPypi,
5 pythonOlder,
6 stdenv,
7
8 # build-system
9 hatchling,
10
11 # dependencies
12 decorator,
13 httptools,
14 python-magic,
15 urllib3,
16
17 # optional-dependencies
18 xxhash,
19 pook,
20
21 # tests
22 aiohttp,
23 asgiref,
24 fastapi,
25 gevent,
26 httpx,
27 psutil,
28 pytest-asyncio,
29 pytest-cov-stub,
30 pytestCheckHook,
31 redis,
32 redis-server,
33 requests,
34 sure,
35
36}:
37
38buildPythonPackage rec {
39 pname = "mocket";
40 version = "3.13.0";
41 pyproject = true;
42
43 src = fetchPypi {
44 inherit pname version;
45 hash = "sha256-GFzIDSE+09L4RC5w4h3fqgq9lkyOVjq5JN++ZNbHWc8=";
46 };
47
48 nativeBuildInputs = [ hatchling ];
49
50 propagatedBuildInputs = [
51 decorator
52 httptools
53 python-magic
54 urllib3
55 ];
56
57 optional-dependencies = {
58 pook = [ pook ];
59 speedups = [ xxhash ];
60 };
61
62 nativeCheckInputs =
63 [
64 asgiref
65 fastapi
66 gevent
67 httpx
68 psutil
69 pytest-asyncio
70 pytest-cov-stub
71 pytestCheckHook
72 redis
73 requests
74 sure
75 ]
76 ++ lib.optionals (pythonOlder "3.12") [ aiohttp ]
77 ++ lib.flatten (builtins.attrValues optional-dependencies);
78
79 preCheck = lib.optionalString stdenv.hostPlatform.isLinux ''
80 ${redis-server}/bin/redis-server &
81 REDIS_PID=$!
82 '';
83
84 postCheck = lib.optionalString stdenv.hostPlatform.isLinux ''
85 kill $REDIS_PID
86 '';
87
88 # Skip http tests, they require network access
89 env.SKIP_TRUE_HTTP = true;
90
91 _darwinAllowLocalNetworking = true;
92
93 disabledTests = [
94 # tests that require network access (like DNS lookups)
95 "test_truesendall_with_dump_from_recording"
96 "test_aiohttp"
97 "test_asyncio_record_replay"
98 "test_gethostbyname"
99 # httpx read failure
100 "test_no_dangling_fds"
101 ];
102
103 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [ "tests/main/test_redis.py" ];
104
105 pythonImportsCheck = [ "mocket" ];
106
107 meta = with lib; {
108 changelog = "https://github.com/mindflayer/python-mocket/releases/tag/${version}";
109 description = "Socket mock framework for all kinds of sockets including web-clients";
110 homepage = "https://github.com/mindflayer/python-mocket";
111 license = licenses.bsd3;
112 maintainers = [ ];
113 };
114}