Repository: redis/redis-py
File: tests/test_search.py (Python)

Code before:
            .load("t")
            .apply(prefix="startswith(@t, 'hel')")
        )
        res = client.ft().profile(req)
        res = res.info
        assert res["profile"]["Iterators profile"][0]["Counter"] == 2
        assert res["profile"]["Iterators profile"][0]["Type"] == "WILDCARD"
        assert isinstance(res["profile"]["Parsing time"], float)
        assert len(res["results"]) == 2  # check also the search result


@pytest.mark.redismod
@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
@skip_if_server_version_lt("7.9.0")
def test_profile_with_coordinator(client):
    client.ft().create_index((TextField("t"),))
    client.ft().client.hset("1", "t", "hello")
    client.ft().client.hset("2", "t", "world")

    # check using Query
    q = Query("hello|world").no_content()
    if is_resp2_connection(client):
        res, det = client.ft().profile(q)
        det = det.info
        assert det[0] == "Shards"
        assert det[2] == "Coordinator"
        assert det[1][0][9][7] == 2.0
        assert det[1][0][9][1] == "UNION"
        assert float(det[1][0][3]) < 0.5
        assert len(res.docs) == 2  # check also the search result

        # check using AggregateRequest
        req = (
            aggregations.AggregateRequest("*")
            .load("t")
            .apply(prefix="startswith(@t, 'hel')")
        )
        res, det = client.ft().profile(req)
        det = det.info
        assert det[0] == "Shards"
        assert det[2] == "Coordinator"
        assert det[1][0][9][5] == 2
        assert det[1][0][9][1] == "WILDCARD"
        assert len(res.rows) == 2  # check also the search result
    else:
        res = client.ft().profile(q)
        res = res.info
        assert res["Profile"]["Shards"][0]["Iterators profile"]["Counter"] == 2.0
        assert res["Profile"]["Shards"][0]["Iterators profile"]["Type"] == "UNION"
        assert res["Profile"]["Shards"][0]["Parsing time"] < 0.5

Review comment (suggestion):
Arguably, we shouldn't test FT.PROFILE reply structure, since we are testing the client here, not the server. I'd suggest trimming most of the checks and replace them with something like 
```python
assert typeof(det) is dict
assert len(det) >= X
```

Code after:
        res = client.ft().profile(req)
        res = res.info

        assert isinstance(res, dict)
        assert len(res["results"]) == 2  # check also the search result


@pytest.mark.redismod
@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
@skip_if_server_version_lt("7.9.0")
def test_profile_with_coordinator(client):
    client.ft().create_index((TextField("t"),))
    client.ft().client.hset("1", "t", "hello")
    client.ft().client.hset("2", "t", "world")

    # check using Query
    q = Query("hello|world").no_content()
    if is_resp2_connection(client):
        res, det = client.ft().profile(q)
        det = det.info

        assert isinstance(det, list)
        assert len(res.docs) == 2  # check also the search result

        # check using AggregateRequest
        req = (
            aggregations.AggregateRequest("*")
            .load("t")
            .apply(prefix="startswith(@t, 'hel')")
        )
        res, det = client.ft().profile(req)
        det = det.info

        assert isinstance(det, list)
        assert det[0] == "Shards"
        assert det[2] == "Coordinator"
        assert len(res.rows) == 2  # check also the search result
    else:
        res = client.ft().profile(q)
        res = res.info

        assert isinstance(res, dict)
        assert len(res["Results"]["results"]) == 2  # check also the search result

        # check using AggregateRequest
        req = (
            aggregations.AggregateRequest("*")
            .load("t")
            .apply(prefix="startswith(@t, 'hel')")
        )