Debian Codegraph @

tests/unittests/command_parse/test_list_parse.py

raw
1 def test_lpop_rpop(judge_command):
2 """LPOP/RPOP accept key and optional count (per commands.json since 6.2)."""
3 judge_command("LPOP mylist", {"command": "LPOP", "key": "mylist"})
4 judge_command(
5 "LPOP mylist 3",
6 {"command": "LPOP", "key": "mylist", "count": "3"},
7 )
8 judge_command("RPOP mylist", {"command": "RPOP", "key": "mylist"})
9 judge_command(
10 "RPOP mylist 2",
11 {"command": "RPOP", "key": "mylist", "count": "2"},
12 )
13
14
15 def test_rpushx(judge_command):
16 """RPUSHX accepts key and one or more elements (per commands.json since 4.0)."""
17 judge_command(
18 "RPUSHX mylist a",
19 {"command": "RPUSHX", "key": "mylist", "values": "a"},
20 )
21 judge_command(
22 "RPUSHX mylist a b c",
23 {"command": "RPUSHX", "key": "mylist", "values": "a b c"},
24 )
25
26
27 def test_rpush(judge_command):
28 judge_command(
29 "RPUSH list1 foo bar hello world",
30 {"command": "RPUSH", "key": "list1", "values": "foo bar hello world"},
31 )
32 judge_command(
33 "LPUSH list1 foo", {"command": "LPUSH", "key": "list1", "values": "foo"}
34 )
35
36
37 def test_lindex(judge_command):
38 judge_command(
39 "LINDEX list1 10", {"command": "LINDEX", "key": "list1", "position": "10"}
40 )
41 judge_command(
42 "LINDEX list1 -10", {"command": "LINDEX", "key": "list1", "position": "-10"}
43 )
44 judge_command("LINDEX list1 1.1", None)
45
46
47 def test_lset(judge_command):
48 judge_command(
49 "LSET list1 10 newbie",
50 {"command": "LSET", "key": "list1", "position": "10", "value": "newbie"},
51 )
52 judge_command(
53 "LSET list1 -1 newbie",
54 {"command": "LSET", "key": "list1", "position": "-1", "value": "newbie"},
55 )
56
57
58 def test_brpoplpush(judge_command):
59 judge_command(
60 "BRPOPLPUSH list1 list2 10",
61 {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "10"},
62 )
63 judge_command(
64 "BRPOPLPUSH list1 list2 0",
65 {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "0"},
66 )
67 judge_command("BRPOPLPUSH list1 list2 -1", None)
68
69
70 def test_brpoplpush_with_double_timeout(judge_command):
71 judge_command(
72 "BRPOPLPUSH list1 list2 10.0",
73 {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": "10.0"},
74 )
75 judge_command(
76 "BRPOPLPUSH list1 list2 .2",
77 {"command": "BRPOPLPUSH", "key": "list1", "newkey": "list2", "timeout": ".2"},
78 )
79 judge_command("BRPOPLPUSH list1 list2 12.", None)
80
81
82 def test_linsert(judge_command):
83 judge_command(
84 'LINSERT mylist BEFORE "World" "There"',
85 {
86 "command": "LINSERT",
87 "key": "mylist",
88 "position_choice": "BEFORE",
89 "value": ['"World"', '"There"'],
90 },
91 )
92 judge_command(
93 'LINSERT mylist after "World" "There"',
94 {
95 "command": "LINSERT",
96 "key": "mylist",
97 "position_choice": "after",
98 "value": ['"World"', '"There"'],
99 },
100 )
101
102
103 def test_lpos(judge_command):
104 judge_command("LPOS mylist c", {"command": "LPOS", "key": "mylist", "element": "c"})
105 judge_command(
106 "LPOS mylist c RANK 2",
107 {
108 "command": "LPOS",
109 "key": "mylist",
110 "element": "c",
111 "rank_const": "RANK",
112 "rank": "2",
113 },
114 )
115 judge_command(
116 "LPOS mylist c RANK -1",
117 {
118 "command": "LPOS",
119 "key": "mylist",
120 "element": "c",
121 "rank_const": "RANK",
122 "rank": "-1",
123 },
124 )
125 judge_command(
126 "LPOS mylist c COUNT 2",
127 {
128 "command": "LPOS",
129 "key": "mylist",
130 "element": "c",
131 "count_const": "COUNT",
132 "count": "2",
133 },
134 )
135 judge_command(
136 "LPOS mylist c RANK -1 COUNT 2",
137 {
138 "command": "LPOS",
139 "key": "mylist",
140 "element": "c",
141 "count_const": "COUNT",
142 "count": "2",
143 "rank_const": "RANK",
144 "rank": "-1",
145 },
146 )
147
148
149 def test_lmove(judge_command):
150 """LMOVE (since 6.2) source dest LEFT|RIGHT LEFT|RIGHT (per commands.json)."""
151 judge_command(
152 "LMOVE src dest LEFT RIGHT",
153 {
154 "command": "LMOVE",
155 "key": ["src", "dest"],
156 "lr_const": ["LEFT", "RIGHT"],
157 },
158 )
159 judge_command(
160 "LMOVE mylist other RIGHT LEFT",
161 {
162 "command": "LMOVE",
163 "key": ["mylist", "other"],
164 "lr_const": ["RIGHT", "LEFT"],
165 },
166 )
167
168
169 def test_blmove(judge_command):
170 judge_command(
171 "blmove list1 list2 left right 1.2",
172 {
173 "command": "blmove",
174 "key": ["list1", "list2"],
175 "lr_const": ["left", "right"],
176 "timeout": "1.2",
177 },
178 )
179 judge_command(
180 "blmove list1 list2 right right .2",
181 {
182 "command": "blmove",
183 "key": ["list1", "list2"],
184 "lr_const": ["right", "right"],
185 "timeout": ".2",
186 },
187 )
188 judge_command("blmove list1 list2 right right", None)
189 judge_command("blmove list1 right right 1", None)