summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAvital Fine <79420960+AvitalFineRedis@users.noreply.github.com>2021-08-29 11:36:50 +0300
committerGitHub <noreply@github.com>2021-08-29 11:36:50 +0300
commit9f82778b78b2e4fd1482255edc91d10c4dda2988 (patch)
tree2f7559fe0a611b6806afbf5804b960692f950a18 /tests
parent5964d700beb9a6b195d64430b0a655e6aa6fd721 (diff)
downloadredis-py-9f82778b78b2e4fd1482255edc91d10c4dda2988.tar.gz
Stralgo (#1528)
* add support to STRALDO command * add tests * skip if version .. * new line * lower case * fix comments * callback * change to get
Diffstat (limited to 'tests')
-rw-r--r--tests/test_commands.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 1d829d6..4b7957c 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1052,6 +1052,49 @@ class TestRedisCommands:
assert r.setrange('a', 6, '12345') == 11
assert r['a'] == b'abcdef12345'
+ @skip_if_server_version_lt('6.0.0')
+ def test_stralgo_lcs(self, r):
+ key1 = 'key1'
+ key2 = 'key2'
+ value1 = 'ohmytext'
+ value2 = 'mynewtext'
+ res = 'mytext'
+ # test LCS of strings
+ assert r.stralgo('LCS', value1, value2) == res
+ # test using keys
+ r.mset({key1: value1, key2: value2})
+ assert r.stralgo('LCS', key1, key2, specific_argument="keys") == res
+ # test other labels
+ assert r.stralgo('LCS', value1, value2, len=True) == len(res)
+ assert r.stralgo('LCS', value1, value2, idx=True) == \
+ {
+ 'len': len(res),
+ 'matches': [[(4, 7), (5, 8)], [(2, 3), (0, 1)]]
+ }
+ assert r.stralgo('LCS', value1, value2,
+ idx=True, withmatchlen=True) == \
+ {
+ 'len': len(res),
+ 'matches': [[4, (4, 7), (5, 8)], [2, (2, 3), (0, 1)]]
+ }
+ assert r.stralgo('LCS', value1, value2,
+ idx=True, minmatchlen=4, withmatchlen=True) == \
+ {
+ 'len': len(res),
+ 'matches': [[4, (4, 7), (5, 8)]]
+ }
+
+ @skip_if_server_version_lt('6.0.0')
+ def test_stralgo_negative(self, r):
+ with pytest.raises(exceptions.DataError):
+ r.stralgo('ISSUB', 'value1', 'value2')
+ with pytest.raises(exceptions.DataError):
+ r.stralgo('LCS', 'value1', 'value2', len=True, idx=True)
+ with pytest.raises(exceptions.DataError):
+ r.stralgo('LCS', 'value1', 'value2', specific_argument="INT")
+ with pytest.raises(ValueError):
+ r.stralgo('LCS', 'value1', 'value2', idx=True, minmatchlen="one")
+
def test_strlen(self, r):
r['a'] = 'foo'
assert r.strlen('a') == 3