about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/mocket/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/python-modules/mocket/default.nix')
-rw-r--r--nixpkgs/pkgs/development/python-modules/mocket/default.nix115
1 files changed, 115 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/python-modules/mocket/default.nix b/nixpkgs/pkgs/development/python-modules/mocket/default.nix
new file mode 100644
index 000000000000..37a8c8d9cc74
--- /dev/null
+++ b/nixpkgs/pkgs/development/python-modules/mocket/default.nix
@@ -0,0 +1,115 @@
+{ lib
+, buildPythonPackage
+, fetchPypi
+, pythonOlder
+, stdenv
+
+# build-system
+, hatchling
+
+# dependencies
+, decorator
+, httptools
+, python-magic
+, urllib3
+
+# optional-dependencies
+, xxhash
+, pook
+
+# tests
+, aiohttp
+, asgiref
+, fastapi
+, gevent
+, httpx
+, pytest-asyncio
+, pytestCheckHook
+, redis
+, redis-server
+, requests
+, sure
+
+}:
+
+buildPythonPackage rec {
+  pname = "mocket";
+  version = "3.12.0";
+  pyproject = true;
+
+  src = fetchPypi {
+    inherit pname version;
+    hash = "sha256-brvBWwTWT2F/usVBRr7wz9L0kct4X1Fddl4mu5LUENA=";
+  };
+
+  nativeBuildInputs = [
+    hatchling
+  ];
+
+  propagatedBuildInputs = [
+    decorator
+    httptools
+    python-magic
+    urllib3
+  ];
+
+  passthru.optional-dependencies = {
+    pook = [
+      pook
+    ];
+    speedups = [
+      xxhash
+    ];
+  };
+
+  nativeCheckInputs = [
+    asgiref
+    fastapi
+    gevent
+    httpx
+    pytest-asyncio
+    pytestCheckHook
+    redis
+    requests
+    sure
+  ] ++ lib.optionals (pythonOlder "3.12") [
+    aiohttp
+  ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies);
+
+  preCheck = lib.optionalString stdenv.isLinux ''
+    ${redis-server}/bin/redis-server &
+    REDIS_PID=$!
+  '';
+
+  postCheck = lib.optionalString stdenv.isLinux ''
+    kill $REDIS_PID
+  '';
+
+  # Skip http tests, they require network access
+  env.SKIP_TRUE_HTTP = true;
+
+  _darwinAllowLocalNetworking = true;
+
+  disabledTests = [
+    # tests that require network access (like DNS lookups)
+    "test_truesendall_with_dump_from_recording"
+    "test_asyncio_record_replay"
+    "test_gethostbyname"
+  ];
+
+  disabledTestPaths = lib.optionals stdenv.isDarwin [
+    "tests/main/test_redis.py"
+  ];
+
+  pythonImportsCheck = [
+    "mocket"
+  ];
+
+  meta = with lib; {
+    changelog = "https://github.com/mindflayer/python-mocket/releases/tag/${version}";
+    description = "A socket mock framework for all kinds of sockets including web-clients";
+    homepage = "https://github.com/mindflayer/python-mocket";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ ];
+  };
+}