FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(net): add concise __repr__ to Response (#49) · pythonnative/pythonnative@2ffc701 · GitHub

Repository navigation

Commit 2ffc701

Browse files
authored
feat(net): add concise __repr__ to Response (#49)
Refs: #43
1 parent c90bbcb commit 2ffc701

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/pythonnative/net.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def ok(self) -> bool:
7777
"""``True`` if the status is in the 2xx range."""
7878
return 200 <= self.status < 300
7979

80+
def __repr__(self) -> str:
81+
cls = type(self).__name__
82+
return f"{cls}(status={self.status}, url={self.url!r}, ok={self.ok}, content={len(self.content)} bytes)"
83+
8084
def text(self, encoding: Optional[str] = None) -> str:
8185
"""Decode ``content`` to ``str``.
8286

‎tests/test_net.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ async def run() -> Response:
118118
assert resp.json() == {"ok": True}
119119

120120

121+
def test_repr_summarizes_body(echo_server: str) -> None:
122+
async def run() -> Response:
123+
return await fetch(echo_server + "/text")
124+
125+
resp = asyncio.run(run())
126+
text = repr(resp)
127+
assert "status=200" in text
128+
assert f"{len(resp.content)} bytes" in text
129+
assert resp.text() not in text
130+
131+
121132
def test_non_2xx_does_not_raise_but_keeps_body(echo_server: str) -> None:
122133
async def run() -> Response:
123134
return await fetch(echo_server + "/status/418")

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL