8000 Update Request and Response str/repr methods by mjcaley · Pull Request #313 · mjcaley/aiospamc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update Request and Response str/repr methods #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions aiospamc/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ def __bytes__(self) -> bytes:
b"body": body,
}

def __str__(self):
def __repr__(self) -&g 8000 t; str:
return str(self)

def __str__(self) -> str:
return (
f"<{self.verb}: "
f'{".".join([self.__class__.__module__, self.__class__.__qualname__])} '
f"object at {id(self)}>"
f"<{self.__class__.__module__}.{self.__class__.__qualname__} "
f"[{self.verb}] "
f"object at {hex(id(self))}>"
)

@property
Expand Down
12 changes: 7 additions & 5 deletions aiospamc/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ def __bytes__(self) -> bytes:
}
)

def __str__(self):
def __repr__(self) -> str:
return str(self)

def __str__(self) -> str:
return (
f"<{self.status_code} - "
f"{self.message}: "
f'{".".join([self.__class__.__module__, self.__class__.__qualname__])} '
f"object at {id(self)}>"
f"<{self.__class__.__module__}.{self.__class__.__qualname__} "
f"[{self.message}] "
f"object at {hex(id(self))}>"
)

def __eq__(self, other: Any) -> bool:
Expand Down
1 change: 1 addition & 0 deletions changes/310.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated __str__ and __repr__ methods for the Response and Request classes.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ branch = true
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__"
"def __repr__",
"def __str__"
]
fail_under = 95.0

Expand Down
7 changes: 0 additions & 7 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ def test_bytes_body_compressed():
assert result == zlib.compress(test_input)


def test_str():
r = Request(verb="TEST")
result = str(r)

assert result == f"<TEST: aiospamc.requests.Request object at {id(r)}>"


def test_request_from_parser_result(request_with_body):
p = RequestParser().parse(bytes(request_with_body))
r = Request(**p)
Expand Down
7 changes: 0 additions & 7 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ def test_bytes_body_compressed():
assert result == zlib.compress(test_input)


def test_str():
r = Response(status_code=0, message="EX_OK")
result = str(r)

assert result == f"<0 - EX_OK: aiospamc.responses.Response object at {id(r)}>"


def test_eq_other_obj_is_false():
r = Response()

Expand Down
0