diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-04 07:58:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-04 07:58:56 +0000 |
commit | a785d1c2de7d227674051b865935013bdd27e60f (patch) | |
tree | cf642e98373f0a1b8fbc5e772c30c334f2cd4d30 /tests/unittests/test_completers.py | |
parent | Adding upstream version 1.11.1. (diff) | |
download | iredis-a785d1c2de7d227674051b865935013bdd27e60f.tar.xz iredis-a785d1c2de7d227674051b865935013bdd27e60f.zip |
Adding upstream version 1.12.0.upstream/1.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/unittests/test_completers.py | 93 |
1 files changed, 88 insertions, 5 deletions
diff --git a/tests/unittests/test_completers.py b/tests/unittests/test_completers.py index d0344fd..5441b0e 100644 --- a/tests/unittests/test_completers.py +++ b/tests/unittests/test_completers.py @@ -183,7 +183,7 @@ def test_group_completer(): @patch("iredis.completers.pendulum.now") def test_timestamp_completer_humanize_time_completion(fake_now): fake_now.return_value = pendulum.from_timestamp(1578487013) - c = TimestampCompleter() + c = TimestampCompleter(is_milliseconds=True, future_time=False) fake_document = MagicMock() fake_document.text = fake_document.text_before_cursor = "30" @@ -260,8 +260,87 @@ def test_timestamp_completer_humanize_time_completion(fake_now): ] +@patch("iredis.completers.pendulum.now") +def test_timestamp_completer_humanize_time_completion_seconds(fake_now): + fake_now.return_value = pendulum.from_timestamp(1578487013) + c = TimestampCompleter(is_milliseconds=False, future_time=False) + + fake_document = MagicMock() + fake_document.text = fake_document.text_before_cursor = "30" + completions = list(c.get_completions(fake_document, None)) + + assert completions == [ + Completion( + text="1575895013", + start_position=-2, + display=FormattedText([("", "1575895013")]), + display_meta="30 days ago (2019-12-09 12:36:53)", + ), + Completion( + text="1578379013", + start_position=-2, + display=FormattedText([("", "1578379013")]), + display_meta="30 hours ago (2020-01-07 06:36:53)", + ), + Completion( + text="1578485213", + start_position=-2, + display=FormattedText([("", "1578485213")]), + display_meta="30 minutes ago (2020-01-08 12:06:53)", + ), + Completion( + text="1578486983", + start_position=-2, + display=FormattedText([("", "1578486983")]), + display_meta="30 seconds ago (2020-01-08 12:36:23)", + ), + ] + + +@patch("iredis.completers.pendulum.now") +def test_timestamp_completer_humanize_time_completion_seconds_future_time(fake_now): + fake_now.return_value = pendulum.from_timestamp(1578487013) + c = TimestampCompleter(is_milliseconds=False, future_time=True) + + fake_document = MagicMock() + fake_document.text = fake_document.text_before_cursor = "30" + completions = list(c.get_completions(fake_document, None)) + + print(completions) + for c in completions: + print(c.text) + print(c.display) + print(c.display_meta) + assert completions == [ + Completion( + text="1578487043", + start_position=-2, + display=FormattedText([("", "1578487043")]), + display_meta="30 seconds later (2020-01-08 12:37:23)", + ), + Completion( + text="1578488813", + start_position=-2, + display=FormattedText([("", "1578488813")]), + display_meta="30 minutes later (2020-01-08 13:06:53)", + ), + Completion( + text="1578595013", + start_position=-2, + display=FormattedText([("", "1578595013")]), + display_meta="30 hours later (2020-01-09 18:36:53)", + ), + Completion( + text="1581079013", + start_position=-2, + display=FormattedText([("", "1581079013")]), + display_meta="30 days later (2020-02-07 12:36:53)", + ), + ] + + def test_timestamp_completer_datetime_format_time_completion(): - c = TimestampCompleter() + c = TimestampCompleter(is_milliseconds=True, future_time=False) fake_document = MagicMock() fake_document.text = fake_document.text_before_cursor = "2020-02-07" completions = list(c.get_completions(fake_document, None)) @@ -299,14 +378,18 @@ def test_completion_casing(): completion.text for completion in c.get_completions(fake_document, None) ] == [ "get", + "getex", "getset", + "getdel", "getbit", "geopos", "geoadd", "geohash", "geodist", "getrange", + "geosearch", "georadius", + "geosearchstore", "georadiusbymember", ] @@ -314,19 +397,19 @@ def test_completion_casing(): fake_document.text = fake_document.text_before_cursor = "GET" assert [ completion.text for completion in c.get_completions(fake_document, None) - ] == ["GET", "GETSET", "GETBIT", "GETRANGE"] + ] == ["GET", "GETEX", "GETSET", "GETDEL", "GETBIT", "GETRANGE"] c = IRedisCompleter(completion_casing="upper") fake_document.text = fake_document.text_before_cursor = "get" assert [ completion.text for completion in c.get_completions(fake_document, None) - ] == ["GET", "GETSET", "GETBIT", "GETRANGE"] + ] == ["GET", "GETEX", "GETSET", "GETDEL", "GETBIT", "GETRANGE"] c = IRedisCompleter(completion_casing="lower") fake_document.text = fake_document.text_before_cursor = "GET" assert [ completion.text for completion in c.get_completions(fake_document, None) - ] == ["get", "getset", "getbit", "getrange"] + ] == ["get", "getex", "getset", "getdel", "getbit", "getrange"] def test_username_completer(): |