From 858b63701752fbe55193d50a1702911af624c695 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Tue, 3 Sep 2024 12:56:44 -0600 Subject: [PATCH 1/4] test: remove redundant tests --- .github/workflows/test-fakeredis.yml | 4 +- tests/fakeredis/test/test_extract_args.py | 147 ---------------------- tests/fakeredis/test/test_general.py | 16 --- tests/fakeredis/test/test_mock.py | 16 --- 4 files changed, 3 insertions(+), 180 deletions(-) delete mode 100644 tests/fakeredis/test/test_extract_args.py delete mode 100644 tests/fakeredis/test/test_general.py delete mode 100644 tests/fakeredis/test/test_mock.py diff --git a/.github/workflows/test-fakeredis.yml b/.github/workflows/test-fakeredis.yml index e753731b1c37..4e8f7c0f39b7 100644 --- a/.github/workflows/test-fakeredis.yml +++ b/.github/workflows/test-fakeredis.yml @@ -73,7 +73,9 @@ jobs: - name: Run tests working-directory: tests/fakeredis run: | - poetry run pytest test/ --ignore test/test_hypothesis.py --ignore test/test_json/ \ + poetry run pytest test/ \ + --ignore test/test_hypothesis.py \ + --ignore test/test_json/ \ --ignore test_bitmap_commands.py \ --junit-xml=results-tests.xml --html=report-tests.html -v continue-on-error: true # For now to mark the flow as successful diff --git a/tests/fakeredis/test/test_extract_args.py b/tests/fakeredis/test/test_extract_args.py deleted file mode 100644 index c2ca14ee400b..000000000000 --- a/tests/fakeredis/test/test_extract_args.py +++ /dev/null @@ -1,147 +0,0 @@ -import pytest - -from fakeredis._command_args_parsing import extract_args -from fakeredis._helpers import SimpleError - - -def test_extract_args(): - args = ( - b"nx", - b"ex", - b"324", - b"xx", - ) - (xx, nx, ex, keepttl), _ = extract_args(args, ("nx", "xx", "+ex", "keepttl")) - assert xx - assert nx - assert ex == 324 - assert not keepttl - - -def test_extract_args__should_raise_error(): - args = (b"nx", b"ex", b"324", b"xx", b"something") - with pytest.raises(SimpleError): - _, _ = extract_args(args, ("nx", "xx", "+ex", "keepttl")) - - -def test_extract_args__should_return_something(): - args = (b"nx", b"ex", b"324", b"xx", b"something") - - (xx, nx, ex, keepttl), left = extract_args( - args, ("nx", "xx", "+ex", "keepttl"), error_on_unexpected=False - ) - assert xx - assert nx - assert ex == 324 - assert not keepttl - assert left == (b"something",) - - args = ( - b"nx", - b"something", - b"ex", - b"324", - b"xx", - ) - - (xx, nx, ex, keepttl), left = extract_args( - args, - ("nx", "xx", "+ex", "keepttl"), - error_on_unexpected=False, - left_from_first_unexpected=False, - ) - assert xx - assert nx - assert ex == 324 - assert not keepttl - assert left == [ - b"something", - ] - - -def test_extract_args__multiple_numbers(): - args = ( - b"nx", - b"limit", - b"324", - b"123", - b"xx", - ) - - (xx, nx, limit, keepttl), _ = extract_args(args, ("nx", "xx", "++limit", "keepttl")) - assert xx - assert nx - assert limit == [324, 123] - assert not keepttl - - (xx, nx, limit, keepttl), _ = extract_args( - ( - b"nx", - b"xx", - ), - ("nx", "xx", "++limit", "keepttl"), - ) - assert xx - assert nx - assert not keepttl - assert limit == [None, None] - - -def test_extract_args__extract_non_numbers(): - args = ( - b"by", - b"dd", - b"nx", - b"limit", - b"324", - b"123", - b"xx", - ) - - (xx, nx, limit, sortby), _ = extract_args(args, ("nx", "xx", "++limit", "*by")) - assert xx - assert nx - assert limit == [324, 123] - assert sortby == b"dd" - - -def test_extract_args__extract_maxlen(): - args = (b"MAXLEN", b"5") - (nomkstream, limit, maxlen, maxid), left_args = extract_args( - args, ("nomkstream", "+limit", "~+maxlen", "~maxid"), error_on_unexpected=False - ) - assert not nomkstream - assert limit is None - assert maxlen == 5 - assert maxid is None - - args = (b"MAXLEN", b"~", b"5", b"maxid", b"~", b"1") - (nomkstream, limit, maxlen, maxid), left_args = extract_args( - args, ("nomkstream", "+limit", "~+maxlen", "~maxid"), error_on_unexpected=False - ) - assert not nomkstream - assert limit is None - assert maxlen == 5 - assert maxid == b"1" - - args = ( - b"by", - b"dd", - b"nx", - b"maxlen", - b"~", - b"10", - b"limit", - b"324", - b"123", - b"xx", - ) - - (nx, maxlen, xx, limit, sortby), _ = extract_args( - args, ("nx", "~+maxlen", "xx", "++limit", "*by") - ) - assert xx - assert nx - assert maxlen == 10 - assert limit == [324, 123] - assert sortby == b"dd" diff --git a/tests/fakeredis/test/test_general.py b/tests/fakeredis/test/test_general.py deleted file mode 100644 index 196e6b236b15..000000000000 --- a/tests/fakeredis/test/test_general.py +++ /dev/null @@ -1,16 +0,0 @@ -import pytest -import redis - -from test.testtools import raw_command - - -def test_asyncioio_is_used(): - """Redis 4.2+ has support for asyncio and should be preferred over aioredis""" - from fakeredis import aioredis - - assert not hasattr(aioredis, "__version__") - - -def test_unknown_command(r: redis.Redis): - with pytest.raises(redis.ResponseError): - raw_command(r, "0 3 3") diff --git a/tests/fakeredis/test/test_mock.py b/tests/fakeredis/test/test_mock.py deleted file mode 100644 index fa1adb0e2ac9..000000000000 --- a/tests/fakeredis/test/test_mock.py +++ /dev/null @@ -1,16 +0,0 @@ -from unittest.mock import patch - -import redis -from fakeredis import FakeRedis - - -def test_mock(): - # Mock Redis connection - def bar(redis_host: str, redis_port: int): - redis.Redis(redis_host, redis_port) - - with patch("redis.Redis", FakeRedis): - # Call function - bar("localhost", 6000) - - # Related to #36 - this should fail if mocking Redis does not work From c84e97b5c2c49247b43e80bbfe1188d06983fc7f Mon Sep 17 00:00:00 2001 From: Daniel M Date: Tue, 3 Sep 2024 13:05:02 -0600 Subject: [PATCH 2/4] remove more tests --- tests/fakeredis/test/test_sortedset_commands.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/fakeredis/test/test_sortedset_commands.py b/tests/fakeredis/test/test_sortedset_commands.py index 3b447a332bf5..b42fd2ad9a84 100644 --- a/tests/fakeredis/test/test_sortedset_commands.py +++ b/tests/fakeredis/test/test_sortedset_commands.py @@ -8,9 +8,6 @@ import pytest import redis import redis.client -from packaging.version import Version - -REDIS_VERSION = Version(redis.__version__) def round_str(x): @@ -18,10 +15,6 @@ def round_str(x): return round(float(x)) -def zincrby(r, key, amount, value): - return r.zincrby(key, amount, value) - - def test_zpopmin(r: redis.Redis): r.zadd("foo", {"one": 1}) r.zadd("foo", {"two": 2}) @@ -215,14 +208,14 @@ def test_zcount_wrong_type(r: redis.Redis): def test_zincrby(r: redis.Redis): r.zadd("foo", {"one": 1}) - assert zincrby(r, "foo", 10, "one") == 11 + assert r.zincrby("foo", 10, "one") == 11 assert r.zrange("foo", 0, -1, withscores=True) == [(b"one", 11)] def test_zincrby_wrong_type(r: redis.Redis): r.sadd("foo", "bar") with pytest.raises(redis.ResponseError): - zincrby(r, "foo", 10, "one") + r.zincrby("foo", 10, "one") def test_zrange_descending(r: redis.Redis): From ab43651c8ecc27d56d2546a1888f4ee57172086f Mon Sep 17 00:00:00 2001 From: Daniel M Date: Tue, 3 Sep 2024 13:28:32 -0600 Subject: [PATCH 3/4] add test_bitmap_commands --- .github/workflows/test-fakeredis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-fakeredis.yml b/.github/workflows/test-fakeredis.yml index 4e8f7c0f39b7..6213016efdb8 100644 --- a/.github/workflows/test-fakeredis.yml +++ b/.github/workflows/test-fakeredis.yml @@ -76,7 +76,6 @@ jobs: poetry run pytest test/ \ --ignore test/test_hypothesis.py \ --ignore test/test_json/ \ - --ignore test_bitmap_commands.py \ --junit-xml=results-tests.xml --html=report-tests.html -v continue-on-error: true # For now to mark the flow as successful From 0fe1c6cede415d079506bd33a3847320beb4de77 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Wed, 4 Sep 2024 13:49:46 -0600 Subject: [PATCH 4/4] add test_bitmap_commands and test_geo_commands to ignore list --- .github/workflows/test-fakeredis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-fakeredis.yml b/.github/workflows/test-fakeredis.yml index 6213016efdb8..f5e9f1d960f8 100644 --- a/.github/workflows/test-fakeredis.yml +++ b/.github/workflows/test-fakeredis.yml @@ -75,6 +75,8 @@ jobs: run: | poetry run pytest test/ \ --ignore test/test_hypothesis.py \ + --ignore test/test_geo_commands.py \ + --ignore test/test_bitmap_commands.py \ --ignore test/test_json/ \ --junit-xml=results-tests.xml --html=report-tests.html -v continue-on-error: true # For now to mark the flow as successful