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

Code before:
                b"mylib",
                b"engine",
                b"LUA",
                b"functions",
                [[b"name", b"myfunc", b"description", None, b"flags", [b"no-writes"]]],
            ]
        ]
        primaries = r.get_primaries()
        res = {}
        for node in primaries:
            res[node.name] = function_list
        assert r.function_list() == res
        assert r.function_list(library="*lib") == res
        node = primaries[0].name
        assert (
            r.function_list(withcode=True)[node][0][7]
            == f"#!{engine} name={lib} \n {function}".encode()
        )

    def test_fcall(self, r):
        r.function_load(f"#!{engine} name={lib} \n {set_function}")
        r.function_load(f"#!{engine} name={lib2} \n {get_function}")
        assert r.fcall("set", 1, "foo", "bar") == b"OK"
        assert r.fcall("get", 1, "foo") == b"bar"
        with pytest.raises(ResponseError):
            r.fcall("myfunc", 0, "hello")

    def test_fcall_ro(self, r):
        r.function_load(f"#!{engine} name={lib} \n {function}")
        assert r.fcall_ro("myfunc", 0, "hello") == b"hello"
        r.function_load(f"#!{engine} name={lib2} \n {set_function}")
        with pytest.raises(ResponseError):
            r.fcall_ro("set", 1, "foo", "bar")

    def test_function_dump_restore(self, r):
        r.function_load(f"#!{engine} name={lib} \n {set_function}")
        payload = r.function_dump()
        assert r.fcall("set", 1, "foo", "bar") == b"OK"
        r.function_delete("mylib")
        with pytest.raises(ResponseError):
            r.fcall("set", 1, "foo", "bar")
        assert r.function_restore(payload)
        assert r.fcall("set", 1, "foo", "bar") == b"OK"
        r.function_load(f"#!{engine} name={lib2} \n {get_function}")
        assert r.fcall("get", 1, "foo") == b"bar"
        r.function_delete("mylib")
        assert r.function_restore(payload, "FLUSH")
        with pytest.raises(ResponseError):
            r.fcall("get", 1, "foo")


Review comment (suggestion):
shouldn't the gears test code not be here? I think this contains part of your discussion with @shacharPash for #2861 

Code after:
                b"mylib",
                b"engine",
                b"LUA",
                b"functions",
                [[b"name", b"myfunc", b"description", None, b"flags", [b"no-writes"]]],
            ]
        ]
        resp3_function_list = [
            {
                b"library_name": b"mylib",
                b"engine": b"LUA",
                b"functions": [
                    {b"name": b"myfunc", b"description": None, b"flags": {b"no-writes"}}
                ],
            }
        ]
        primaries = r.get_primaries()
        res = {}
        resp3_res = {}
        for node in primaries:
            res[node.name] = function_list
            resp3_res[node.name] = resp3_function_list
        assert_resp_response(r, r.function_list(), res, resp3_res)
        assert_resp_response(r, r.function_list(library="*lib"), res, resp3_res)
        node = primaries[0].name
        code = f"#!{engine} name={lib} \n {function}".encode()
        res[node][0].extend([b"library_code", code])
        resp3_res[node][0][b"library_code"] = code
        assert_resp_response(r, r.function_list(withcode=True), res, resp3_res)

    def test_fcall(self, r):
        r.function_load(f"#!{engine} name={lib} \n {set_function}")
        r.function_load(f"#!{engine} name={lib2} \n {get_function}")
        assert r.fcall("set", 1, "foo", "bar") == b"OK"
        assert r.fcall("get", 1, "foo") == b"bar"
        with pytest.raises(ResponseError):
            r.fcall("myfunc", 0, "hello")

    def test_fcall_ro(self, r):
        r.function_load(f"#!{engine} name={lib} \n {function}")
        assert r.fcall_ro("myfunc", 0, "hello") == b"hello"
        r.function_load(f"#!{engine} name={lib2} \n {set_function}")
        with pytest.raises(ResponseError):
            r.fcall_ro("set", 1, "foo", "bar")

    def test_function_dump_restore(self, r):
        r.function_load(f"#!{engine} name={lib} \n {set_function}")
        payload = r.function_dump()
        assert r.fcall("set", 1, "foo", "bar") == b"OK"
        r.function_delete("mylib")
        with pytest.raises(ResponseError):