1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 setuptools,
6 pg8000,
7 postgresql,
8 psycopg2,
9 pytestCheckHook,
10 pythonOlder,
11 sqlalchemy,
12 testing-common-database,
13}:
14
15buildPythonPackage {
16 pname = "testing-postgresql";
17 # Version 1.3.0 isn't working so let's use the latest commit from GitHub
18 version = "unstable-2017-10-31";
19 pyproject = true;
20
21 disabled = pythonOlder "3.7";
22
23 src = fetchFromGitHub {
24 owner = "tk0miya";
25 repo = "testing.postgresql";
26 rev = "c81ded434d00ec8424de0f9e1f4063c778c6aaa8";
27 hash = "sha256-A4tahAaa98X66ZYa3QxIQDZkwAwVB6ZDRObEhkbUWKs=";
28 };
29
30 build-system = [ setuptools ];
31
32 dependencies = [
33 testing-common-database
34 pg8000
35 ];
36
37 nativeCheckInputs = [
38 pytestCheckHook
39 psycopg2
40 sqlalchemy
41 ];
42
43 # Add PostgreSQL to search path
44 prePatch = ''
45 substituteInPlace src/testing/postgresql.py \
46 --replace-fail "/usr/local/pgsql" "${postgresql}"
47 '';
48
49 pythonRelaxDeps = [ "pg8000" ];
50
51 postPatch = ''
52 substituteInPlace setup.py \
53 --replace-fail "pg8000 >= 1.10" "pg8000"
54 substituteInPlace tests/test_postgresql.py \
55 --replace-fail "self.assertRegexpMatches" "self.assertRegex"
56 '';
57
58 pythonImportsCheck = [ "testing.postgresql" ];
59
60 # Fix tests for Darwin build. See:
61 # https://github.com/NixOS/nixpkgs/pull/74716#issuecomment-598546916
62 __darwinAllowLocalNetworking = true;
63
64 meta = with lib; {
65 description = "Use temporary postgresql instance in testing";
66 homepage = "https://github.com/tk0miya/testing.postgresql";
67 license = licenses.asl20;
68 platforms = platforms.linux;
69 maintainers = with maintainers; [ jluttine ];
70 };
71}