| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,10 @@ def ok(self) -> bool: | |||
| 77 | 77 | """``True`` if the status is in the 2xx range.""" | |
| 78 | 78 | return 200 <= self.status < 300 | |
| 79 | 79 | ||
| 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 | + | ||
| 80 | 84 | def text(self, encoding: Optional[str] = None) -> str: | |
| 81 | 85 | """Decode ``content`` to ``str``. | |
| 82 | 86 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,6 +118,17 @@ async def run() -> Response: | |||
| 118 | 118 | assert resp.json() == {"ok": True} | |
| 119 | 119 | ||
| 120 | 120 | ||
| 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 | + | ||
| 121 | 132 | def test_non_2xx_does_not_raise_but_keeps_body(echo_server: str) -> None: | |
| 122 | 133 | async def run() -> Response: | |
| 123 | 134 | return await fetch(echo_server + "/status/418") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments