blob: 49c990501ba6fecff9f8223f01677f85efefe89d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# Copyright 2020-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DISTUTILS_USE_PEP517=hatchling
PYPI_VERIFY_REPO=https://github.com/cunla/fakeredis-py
PYTHON_COMPAT=( python3_{13..14} )
inherit distutils-r1 pypi
DESCRIPTION="Fake implementation of redis API for testing purposes"
HOMEPAGE="
https://github.com/cunla/fakeredis-py/
https://pypi.org/project/fakeredis/
"
LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~sparc ~x86"
RDEPEND="
>=dev-python/redis-4.3[${PYTHON_USEDEP}]
>=dev-python/sortedcontainers-2[${PYTHON_USEDEP}]
"
BDEPEND="
test? (
dev-db/redis
dev-db/valkey
dev-python/packaging[${PYTHON_USEDEP}]
dev-python/valkey[${PYTHON_USEDEP}]
)
"
EPYTEST_PLUGINS=( pytest-{asyncio,mock} )
EPYTEST_XDIST=1
distutils_enable_tests pytest
src_prepare() {
distutils-r1_src_prepare
# do not install duplicate license
sed -i -e '\@fakeredis/LICENSE@d' pyproject.toml || die
}
wait_for_status() {
local expected=${1}
local i
for i in {1..50}; do
"${server}-cli" -p "${redis_port}" ping
[[ ${?} -eq ${expected} ]] && return
sleep 0.2
done
die "Timeout while waiting for ${1}-server to start/stop"
}
src_test() {
local server
for server in redis valkey; do
local redis_pid="${T}/${server}.pid"
local redis_port=6390
local redis_log="${T}/${server}.log"
local redis_db="${T}/${server}.db"
einfo "Running ${server} server tests"
"${EPREFIX}/usr/sbin/${server}-server" - <<- EOF || die "Unable to start ${server} server"
daemonize yes
pidfile ${redis_pid}
port ${redis_port}
logfile ${redis_log}
dir ${redis_db%/*}
dbfilename ${redis_db##*/}
bind 127.0.0.1
EOF
# wait for the server to start
wait_for_status 0
distutils-r1_src_test
"${server}-cli" -p "${redis_port}" shutdown || die "Unable to stop ${server} server"
# wait for the server to stop
wait_for_status 1
done
}
python_test() {
local EPYTEST_DESELECT=(
# json ext
test/test_stack/test_json.py
test/test_stack/test_json_arr_commands.py
test/test_stack/test_json_fpha.py
# TODO
"test/test_mixins/test_pubsub_commands.py::test_published_message_to_shard_channel[Strict3]"
"test/test_mixins/test_pubsub_commands.py::test_pubsub_shardnumsub[Strict2]"
"test/test_mixins/test_pubsub_commands.py::test_pubsub_shardnumsub[Strict3]"
)
local EPYTEST_IGNORE=(
# these tests fail a lot...
test/test_hypothesis
test/test_hypothesis_joint.py
)
case ${server} in
redis)
EPYTEST_DESELECT+=(
"test/test_mixins/test_set_commands.py::test_smismember_wrong_type[Strict2]"
"test/test_mixins/test_set_commands.py::test_smismember_wrong_type[Strict3]"
"test/test_async/test_redis_only.py::test_async_lock[fake_resp2]"
"test/test_async/test_redis_only.py::test_async_lock[fake_resp3]"
"test/test_mixins/test_set_commands.py::test_smismember_wrong_type[FakeStrict2]"
"test/test_mixins/test_set_commands.py::test_smismember_wrong_type[FakeStrict3]"
)
# run fake tests only once
epytest -m "not real"
;;
valkey)
EPYTEST_DESELECT+=(
test/test_stack/test_vectorset.py
)
;;
esac
# we can run "fake" tests in parallel, but "real" seem to share
# the same connection
EPYTEST_XDIST= epytest -m "real"
}
|