Debian Codegraph @

tests/unittests/command_parse/test_generic_parse.py

raw
1 def test_del(judge_command):
2 judge_command("DEL abc", {"command": "DEL", "keys": "abc"})
3 judge_command("DEL bc1", {"command": "DEL", "keys": "bc1"})
4 judge_command("DEL 1", {"command": "DEL", "keys": "1"})
5 judge_command('DEL "hello world"', {"command": "DEL", "keys": '"hello world"'})
6 judge_command(
7 r'DEL "hell\"o world"', {"command": "DEL", "keys": r'"hell\"o world"'}
8 )
9 judge_command("DEL abc def", {"command": "DEL", "keys": "abc def"})
10 judge_command("DEL 1 2", {"command": "DEL", "keys": "1 2"})
11 judge_command("DEL 'he \"llo'", {"command": "DEL", "keys": "'he \"llo'"})
12 judge_command(
13 """DEL 'he "llo' "abc" 'def' """,
14 {"command": "DEL", "keys": "'he \"llo' \"abc\" 'def'"},
15 )
16
17
18 def test_exists(judge_command):
19 judge_command("EXISTS foo bar", {"command": "EXISTS", "keys": "foo bar"})
20 judge_command("EXISTS foo", {"command": "EXISTS", "keys": "foo"})
21 judge_command("EXISTS 1", {"command": "EXISTS", "keys": "1"})
22 judge_command('EXISTS "foo bar"', {"command": "EXISTS", "keys": '"foo bar"'})
23 judge_command(r'EXISTS "\""', {"command": "EXISTS", "keys": r'"\""'})
24
25
26 def test_expire(judge_command):
27 judge_command("EXPIRE key 12", {"command": "EXPIRE", "key": "key", "second": "12"})
28 judge_command("EXPIRE key a12", None)
29 judge_command("EXPIRE 12 12", {"command": "EXPIRE", "key": "12", "second": "12"})
30 judge_command("EXPIRE 12", None)
31
32
33 def test_expireat(judge_command):
34 judge_command(
35 "EXPIRE key 1565787643",
36 {"command": "EXPIRE", "key": "key", "second": "1565787643"},
37 )
38 judge_command("EXPIRE key a12", None)
39
40
41 def test_keys(judge_command):
42 judge_command("KEYS *", {"command": "KEYS", "pattern": "*"})
43 judge_command("KEYS *abc", {"command": "KEYS", "pattern": "*abc"})
44 judge_command("keys abc*", {"command": "keys", "pattern": "abc*"})
45
46
47 def test_move(judge_command):
48 judge_command("MOVE key 14", {"command": "MOVE", "key": "key", "index": "14"})
49
50
51 def test_pexpire(judge_command):
52 judge_command(
53 "PEXPIRE key 12", {"command": "PEXPIRE", "key": "key", "millisecond": "12"}
54 )
55 judge_command("PEXPIRE key a12", None)
56 judge_command(
57 "PEXPIRE 12 12", {"command": "PEXPIRE", "key": "12", "millisecond": "12"}
58 )
59 judge_command("PEXPIRE 12", None)
60
61
62 def test_pexpireat(judge_command):
63 judge_command(
64 "PEXPIREAT key 1565787643",
65 {"command": "PEXPIREAT", "key": "key", "timestampms": "1565787643"},
66 )
67 judge_command("PEXPIREAT key a12", None)
68
69
70 def test_rename(judge_command):
71 judge_command(
72 "rename key newkey", {"command": "rename", "key": "key", "newkey": "newkey"}
73 )
74 judge_command(
75 "rename 123 newkey", {"command": "rename", "key": "123", "newkey": "newkey"}
76 )
77 judge_command("rename 123 ", None)
78
79
80 def test_scan(judge_command):
81 judge_command(
82 "SCAN 0 MATCH task* COUNT 15 TYPE string",
83 {
84 "command": "SCAN",
85 "cursor": "0",
86 "match": "MATCH",
87 "pattern": "task*",
88 "count_const": "COUNT",
89 "count": "15",
90 "type_const": "TYPE",
91 "type": "string",
92 },
93 )
94 judge_command("SCAN 0", {"command": "SCAN", "cursor": "0"})
95 judge_command(
96 "SCAN 0 MATCH task*",
97 {"command": "SCAN", "cursor": "0", "match": "MATCH", "pattern": "task*"},
98 )
99 judge_command(
100 "SCAN 0 COUNT 15 TYPE string",
101 {
102 "command": "SCAN",
103 "cursor": "0",
104 "count_const": "COUNT",
105 "count": "15",
106 "type_const": "TYPE",
107 "type": "string",
108 },
109 )
110 # Test different parameter orders (Redis allows any order)
111 judge_command(
112 "SCAN 0 COUNT 15 MATCH task*",
113 {
114 "command": "SCAN",
115 "cursor": "0",
116 "count_const": "COUNT",
117 "count": "15",
118 "match": "MATCH",
119 "pattern": "task*",
120 },
121 )
122 judge_command(
123 "SCAN 0 TYPE string MATCH task*",
124 {
125 "command": "SCAN",
126 "cursor": "0",
127 "type_const": "TYPE",
128 "type": "string",
129 "match": "MATCH",
130 "pattern": "task*",
131 },
132 )
133 judge_command(
134 "SCAN 0 TYPE string COUNT 15 MATCH task*",
135 {
136 "command": "SCAN",
137 "cursor": "0",
138 "type_const": "TYPE",
139 "type": "string",
140 "count_const": "COUNT",
141 "count": "15",
142 "match": "MATCH",
143 "pattern": "task*",
144 },
145 )
146
147
148 def test_migrate(judge_command):
149 judge_command(
150 'MIGRATE 192.168.1.34 6379 " " 0 5000 KEYS key1 key2 key3',
151 {
152 "command": "MIGRATE",
153 "host": "192.168.1.34",
154 "port": "6379",
155 "key": '" "',
156 "index": "0",
157 "timeout": "5000",
158 "const_keys": "KEYS",
159 "keys": "key1 key2 key3",
160 },
161 )
162 judge_command(
163 "MIGRATE 192.168.1.34 6379 foo 0 5000 auth password1 KEYS key1 key2 key3",
164 {
165 "command": "MIGRATE",
166 "host": "192.168.1.34",
167 "port": "6379",
168 "key": "foo",
169 "index": "0",
170 "timeout": "5000",
171 "const_keys": "KEYS",
172 "keys": "key1 key2 key3",
173 "auth": "auth",
174 "password": "password1",
175 },
176 )
177 judge_command(
178 "MIGRATE 192.168.1.34 6379 foo 0 5000 auth username1 password1 KEYS key1 key2 key3",
179 {
180 "command": "MIGRATE",
181 "host": "192.168.1.34",
182 "port": "6379",
183 "key": "foo",
184 "index": "0",
185 "timeout": "5000",
186 "const_keys": "KEYS",
187 "keys": "key1 key2 key3",
188 "auth": "auth",
189 "password": "password1",
190 "username": "username1",
191 },
192 )
193
194
195 def test_object(judge_command):
196 """OBJECT HELP (no args) and OBJECT ENCODING/REFCOUNT key (per commands.json)."""
197 judge_command("OBJECT HELP", {"command": "OBJECT HELP"})
198 judge_command(
199 "object encoding mylist",
200 {"command": "object encoding", "any": "mylist"},
201 )
202 judge_command(
203 "object refcount mylist",
204 {"command": "object refcount", "any": "mylist"},
205 )
206
207
208 def test_wait(judge_command):
209 judge_command("WAIT 3 100", {"command": "WAIT", "count": "3", "timeout": "100"})
210
211
212 def test_restore(judge_command):
213 judge_command(
214 'RESTORE mykey 0 "\n\x17\x17\x00\x00\x00\x12\x00\x00\x00\x03\x00\x00\xc0\x01\x00\x04\xc0\x02\x00\x04\xc0\x03\x00\xff\x04\x00u#<\xc0;.\xe9\xdd"', # noqa
215 {
216 "command": "RESTORE",
217 "key": "mykey",
218 "timeout": "0",
219 "value": '"\n\x17\x17\x00\x00\x00\x12\x00\x00\x00\x03\x00\x00\xc0\x01\x00\x04\xc0\x02\x00\x04\xc0\x03\x00\xff\x04\x00u#<\xc0;.\xe9\xdd"', # noqa
220 },
221 )
222
223
224 def test_copy(judge_command):
225 judge_command(
226 "COPY foo bar DB 3 REPLACE",
227 {
228 "command": "COPY",
229 "key": ["foo", "bar"],
230 "db_const": "DB",
231 "index": "3",
232 "replace_const": "REPLACE",
233 },
234 )
235 judge_command(
236 "COPY foo bar REPLACE",
237 {"command": "COPY", "key": ["foo", "bar"], "replace_const": "REPLACE"},
238 )
239 judge_command("COPY foo bar", {"command": "COPY", "key": ["foo", "bar"]})
240
241
242 def test_getex(judge_command):
243 judge_command("GETEX foo", {"command": "GETEX", "key": "foo"})
244 judge_command(
245 "GETEX bar ex 5",
246 {"command": "GETEX", "key": "bar", "expiration": "ex", "millisecond": "5"},
247 )
248 judge_command(
249 "GETEX bar px 5",
250 {"command": "GETEX", "key": "bar", "expiration": "px", "millisecond": "5"},
251 )
252 judge_command(
253 "GETEX bar pxat 5",
254 {"command": "GETEX", "key": "bar", "pxat_const": "pxat", "timestampms": "5"},
255 )
256 judge_command(
257 "GETEX bar exat 5",
258 {"command": "GETEX", "key": "bar", "exat_const": "exat", "timestamp": "5"},
259 )
260 judge_command("GETEX bar ex 5 exat 5", None)