MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / TestAsyncOpencode

Class TestAsyncOpencode

tests/test_client.py:832–1661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

830
831
832class TestAsyncOpencode:
833 client = AsyncOpencode(base_url=base_url, _strict_response_validation=True)
834
835 @pytest.mark.respx(base_url=base_url)
836 @pytest.mark.asyncio
837 async def test_raw_response(self, respx_mock: MockRouter) -> None:
838 respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"}))
839
840 response = await self.client.post("/foo", cast_to=httpx.Response)
841 assert response.status_code == 200
842 assert isinstance(response, httpx.Response)
843 assert response.json() == {"foo": "bar"}
844
845 @pytest.mark.respx(base_url=base_url)
846 @pytest.mark.asyncio
847 async def test_raw_response_for_binary(self, respx_mock: MockRouter) -> None:
848 respx_mock.post("/foo").mock(
849 return_value=httpx.Response(200, headers={"Content-Type": "application/binary"}, content='{"foo": "bar"}')
850 )
851
852 response = await self.client.post("/foo", cast_to=httpx.Response)
853 assert response.status_code == 200
854 assert isinstance(response, httpx.Response)
855 assert response.json() == {"foo": "bar"}
856
857 def test_copy(self) -> None:
858 copied = self.client.copy()
859 assert id(copied) != id(self.client)
860
861 def test_copy_default_options(self) -> None:
862 # options that have a default are overridden correctly
863 copied = self.client.copy(max_retries=7)
864 assert copied.max_retries == 7
865 assert self.client.max_retries == 2
866
867 copied2 = copied.copy(max_retries=6)
868 assert copied2.max_retries == 6
869 assert copied.max_retries == 7
870
871 # timeout
872 assert isinstance(self.client.timeout, httpx.Timeout)
873 copied = self.client.copy(timeout=None)
874 assert copied.timeout is None
875 assert isinstance(self.client.timeout, httpx.Timeout)
876
877 def test_copy_default_headers(self) -> None:
878 client = AsyncOpencode(base_url=base_url, _strict_response_validation=True, default_headers={"X-Foo": "bar"})
879 assert client.default_headers["X-Foo"] == "bar"
880
881 # does not override the already given value when not specified
882 copied = client.copy()
883 assert copied.default_headers["X-Foo"] == "bar"
884
885 # merges already given headers
886 copied = client.copy(default_headers={"X-Bar": "stainless"})
887 assert copied.default_headers["X-Foo"] == "bar"
888 assert copied.default_headers["X-Bar"] == "stainless"
889

Callers

nothing calls this directly

Calls 1

AsyncOpencodeClass · 0.90

Tested by

no test coverage detected