Skip to content

Commit a53bc0c

Browse files
authored
fix incorrect test (#2177)
* fix incorrect test * Fix types
1 parent 42b937f commit a53bc0c

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

redis/commands/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,8 +3943,8 @@ def zadd(
39433943
xx: bool = False,
39443944
ch: bool = False,
39453945
incr: bool = False,
3946-
gt: bool = None,
3947-
lt: bool = None,
3946+
gt: bool = False,
3947+
lt: bool = False,
39483948
) -> ResponseT:
39493949
"""
39503950
Set any number of element-name, score pairs to the key ``name``. Pairs
@@ -3983,12 +3983,14 @@ def zadd(
39833983
raise DataError("ZADD requires at least one element/score pair")
39843984
if nx and xx:
39853985
raise DataError("ZADD allows either 'nx' or 'xx', not both")
3986+
if gt and lt:
3987+
raise DataError("ZADD allows either 'gt' or 'lt', not both")
39863988
if incr and len(mapping) != 1:
39873989
raise DataError(
39883990
"ZADD option 'incr' only works when passing a "
39893991
"single element/score pair"
39903992
)
3991-
if nx is True and (gt is not None or lt is not None):
3993+
if nx and (gt or lt):
39923994
raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")
39933995

39943996
pieces: list[EncodableT] = []

tests/test_commands.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,20 +2215,21 @@ def test_zadd_incr_with_xx(self, r):
22152215

22162216
@skip_if_server_version_lt("6.2.0")
22172217
def test_zadd_gt_lt(self, r):
2218+
r.zadd("a", {"a": 2})
2219+
assert r.zadd("a", {"a": 5}, gt=True, ch=True) == 1
2220+
assert r.zadd("a", {"a": 1}, gt=True, ch=True) == 0
2221+
assert r.zadd("a", {"a": 5}, lt=True, ch=True) == 0
2222+
assert r.zadd("a", {"a": 1}, lt=True, ch=True) == 1
22182223

2219-
for i in range(1, 20):
2220-
r.zadd("a", {f"a{i}": i})
2221-
assert r.zadd("a", {"a20": 5}, gt=3) == 1
2222-
2223-
for i in range(1, 20):
2224-
r.zadd("a", {f"a{i}": i})
2225-
assert r.zadd("a", {"a2": 5}, lt=1) == 0
2226-
2227-
# cannot use both nx and xx options
2224+
# cannot combine both nx and xx options and gt and lt options
2225+
with pytest.raises(exceptions.DataError):
2226+
r.zadd("a", {"a15": 15}, nx=True, lt=True)
2227+
with pytest.raises(exceptions.DataError):
2228+
r.zadd("a", {"a15": 15}, nx=True, gt=True)
2229+
with pytest.raises(exceptions.DataError):
2230+
r.zadd("a", {"a15": 15}, lt=True, gt=True)
22282231
with pytest.raises(exceptions.DataError):
2229-
r.zadd("a", {"a15": 155}, nx=True, lt=True)
2230-
r.zadd("a", {"a15": 155}, nx=True, gt=True)
2231-
r.zadd("a", {"a15": 155}, lt=True, gt=True)
2232+
r.zadd("a", {"a15": 15}, nx=True, xx=True)
22322233

22332234
def test_zcard(self, r):
22342235
r.zadd("a", {"a1": 1, "a2": 2, "a3": 3})

0 commit comments

Comments
 (0)