|
| 1 | +import string |
| 2 | +from redis.commands.helpers import ( |
| 3 | + delist, |
| 4 | + list_or_args, |
| 5 | + nativestr, |
| 6 | + parse_to_list, |
| 7 | + quote_string, |
| 8 | + random_string |
| 9 | +) |
| 10 | + |
| 11 | + |
| 12 | +def test_list_or_args(): |
| 13 | + k = ["hello, world"] |
| 14 | + a = ["some", "argument", "list"] |
| 15 | + assert list_or_args(k, a) == k+a |
| 16 | + |
| 17 | + for i in ["banana", b"banana"]: |
| 18 | + assert list_or_args(i, a) == [i] + a |
| 19 | + |
| 20 | + |
| 21 | +def test_parse_to_list(): |
| 22 | + r = ["hello", b"my name", "45", "555.55", "is simon!", None] |
| 23 | + assert parse_to_list(r) == \ |
| 24 | + ["hello", "my name", 45, 555.55, "is simon!", None] |
| 25 | + |
| 26 | + |
| 27 | +def test_nativestr(): |
| 28 | + assert nativestr('teststr') == 'teststr' |
| 29 | + assert nativestr(b'teststr') == 'teststr' |
| 30 | + assert nativestr('null') is None |
| 31 | + |
| 32 | + |
| 33 | +def test_delist(): |
| 34 | + assert delist(None) is None |
| 35 | + assert delist([b'hello', 'world', b'banana']) == \ |
| 36 | + ['hello', 'world', 'banana'] |
| 37 | + |
| 38 | + |
| 39 | +def test_random_string(): |
| 40 | + assert len(random_string()) == 10 |
| 41 | + assert len(random_string(15)) == 15 |
| 42 | + for a in random_string(): |
| 43 | + assert a in string.ascii_lowercase |
| 44 | + |
| 45 | + |
| 46 | +def test_quote_string(): |
| 47 | + assert quote_string("hello world!") == '"hello world!"' |
| 48 | + assert quote_string('') == '""' |
| 49 | + assert quote_string('hello world!') == '"hello world!"' |
0 commit comments