MCPcopy
hub / github.com/redis/redis-py / test_multi_reverse_range

Function test_multi_reverse_range

tests/test_timeseries.py:769–898  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

767@pytest.mark.redismod
768@skip_ifmodversion_lt("1.10.0", "timeseries")
769def test_multi_reverse_range(client):
770 client.ts().create(1, labels={"Test": "This", "team": "ny"})
771 client.ts().create(2, labels={"Test": "This", "Taste": "That", "team": "sf"})
772 for i in range(100):
773 client.ts().add(1, i, i % 7)
774 client.ts().add(2, i, i % 11)
775
776 # ``expected_response_shape`` is ``"unified"`` for
777 # ``legacy_responses=False`` (any protocol) and ``"legacy_resp3"`` for
778 # ``protocol=3`` with ``legacy_responses=True``. The unified shape
779 # always emits ``[labels, [], samples]`` (samples at index 2); legacy
780 # RESP3 preserves the wire layout, appending an extra ``sources``
781 # element under GROUPBY which pushes samples to index 3.
782 groupby_samples_idx = 2 if expected_response_shape(client) == "unified" else 3
783
784 res = client.ts().mrange(0, 200, filters=["Test=This"])
785 assert 2 == len(res)
786 if expects_resp2_shape(client):
787 assert 100 == len(res[0]["1"][1])
788 else:
789 assert 100 == len(res["1"][2])
790
791 res = client.ts().mrange(0, 200, filters=["Test=This"], count=10)
792 if expects_resp2_shape(client):
793 assert 10 == len(res[0]["1"][1])
794 else:
795 assert 10 == len(res["1"][2])
796
797 for i in range(100):
798 client.ts().add(1, i + 200, i % 7)
799 res = client.ts().mrevrange(
800 0, 500, filters=["Test=This"], aggregation_type="avg", bucket_size_msec=10
801 )
802 assert 2 == len(res)
803 if expects_resp2_shape(client):
804 assert 20 == len(res[0]["1"][1])
805 assert {} == res[0]["1"][0]
806 else:
807 assert 20 == len(res["1"][2])
808 assert {} == res["1"][0]
809
810 # test withlabels
811 res = client.ts().mrevrange(0, 200, filters=["Test=This"], with_labels=True)
812 if expects_resp2_shape(client):
813 assert {"Test": "This", "team": "ny"} == res[0]["1"][0]
814 else:
815 assert {"Test": "This", "team": "ny"} == res["1"][0]
816
817 # test with selected labels
818 res = client.ts().mrevrange(0, 200, filters=["Test=This"], select_labels=["team"])
819 if expects_resp2_shape(client):
820 assert {"team": "ny"} == res[0]["1"][0]
821 assert {"team": "sf"} == res[1]["2"][0]
822 else:
823 assert {"team": "ny"} == res["1"][0]
824 assert {"team": "sf"} == res["2"][0]
825
826 # test filterby

Callers

nothing calls this directly

Calls 7

expected_response_shapeFunction · 0.85
expects_resp2_shapeFunction · 0.85
mrangeMethod · 0.80
mrevrangeMethod · 0.80
createMethod · 0.45
tsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected