Skip to content

Commit 6ae626b

Browse files
committed
feat: add some tests
1 parent 1fef719 commit 6ae626b

19 files changed

Lines changed: 472 additions & 34 deletions

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ jobs:
5858

5959
- name: Run linters
6060
run: |
61-
poetry run ./scripts/docs-lint
61+
poetry run bash ./scripts/docs-lint

pybotx/async_buffer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pragma: no cover
21
import abc
32
import os
43
from typing import Optional
@@ -33,7 +32,7 @@ async def read(
3332

3433

3534
async def get_file_size(async_buffer: AsyncBufferReadable) -> int:
36-
await async_buffer.seek(0, os.SEEK_END) # pragma: no cover
37-
file_size = await async_buffer.tell() # pragma: no cover
38-
await async_buffer.seek(0) # pragma: no cover
39-
return file_size # pragma: no cover
35+
await async_buffer.seek(0, os.SEEK_END)
36+
file_size = await async_buffer.tell()
37+
await async_buffer.seek(0)
38+
return file_size

pybotx/client/chats_api/chat_info.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ class BotXAPIChatInfoResult(VerifiedPayloadBaseModel):
4646
@field_validator("members", mode="before")
4747
@classmethod
4848
def validate_members(
49-
cls, value: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]
49+
cls, value: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]], info: Any
5050
) -> List[Union[BotXAPIChatInfoMember, Dict[str, Any]]]:
5151
parsed: List[Union[BotXAPIChatInfoMember, Dict[str, Any]]] = []
5252
for item in value:
5353
if isinstance(item, dict):
5454
try:
5555
parsed.append(BotXAPIChatInfoMember.model_validate(item))
56-
except ValidationError: # pragma: no cover
56+
except ValidationError:
5757
parsed.append(item)
5858
else:
59-
parsed.append(item) # pragma: no cover
59+
parsed.append(item)
6060
return parsed
6161

6262

@@ -66,9 +66,7 @@ class BotXAPIChatInfoResponsePayload(VerifiedPayloadBaseModel):
6666

6767
def to_domain(self) -> ChatInfo:
6868
if any(isinstance(member, dict) for member in self.result.members):
69-
logger.warning(
70-
"One or more unsupported user types skipped"
71-
) # pragma: no cover
69+
logger.warning("One or more unsupported user types skipped")
7270

7371
members = [
7472
ChatInfoMember(

pybotx/client/chats_api/list_chats.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class BotXAPIListChatResponsePayload(VerifiedPayloadBaseModel):
2828
@field_validator("result", mode="before")
2929
@classmethod
3030
def validate_result(
31-
cls, value: List[Union[BotXAPIListChatResult, Dict[str, Any]]]
31+
cls, value: List[Union[BotXAPIListChatResult, Dict[str, Any]]], info: Any
3232
) -> List[Union[BotXAPIListChatResult, Dict[str, Any]]]:
3333
parsed: List[Union[BotXAPIListChatResult, Dict[str, Any]]] = []
3434
for item in value:
3535
if isinstance(item, dict):
3636
try:
3737
parsed.append(BotXAPIListChatResult.model_validate(item))
38-
except ValidationError: # pragma: no cover
38+
except ValidationError:
3939
parsed.append(item)
4040
else:
41-
parsed.append(item) # pragma: no cover
41+
parsed.append(item)
4242
return parsed
4343

4444
def to_domain(self) -> List[ChatListItem]:
@@ -58,9 +58,7 @@ def to_domain(self) -> List[ChatListItem]:
5858
]
5959

6060
if len(chats_list) != len(self.result):
61-
logger.warning(
62-
"One or more unsupported chat types skipped"
63-
) # pragma: no cover
61+
logger.warning("One or more unsupported chat types skipped")
6462

6563
return chats_list
6664

pybotx/client/exceptions/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, callback: BotAPIMethodFailedCallback) -> None:
1616

1717
def __reduce__(self) -> Any:
1818
# This method required to pass exception from pybotx logger to bot logger.
19-
return type(self), (self.callback,) # pragma: no cover
19+
return type(self), (self.callback,)
2020

2121

2222
class CallbackNotReceivedError(Exception):

pybotx/client/exceptions/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, response: httpx.Response) -> None:
1616

1717
def __reduce__(self) -> Any:
1818
# This method required to pass exception from pybotx logger to bot logger.
19-
return type(self), (self.response,) # pragma: no cover
19+
return type(self), (self.response,)
2020

2121

2222
class InvalidBotXStatusCodeError(InvalidBotXResponseError):

pybotx/client/files_api/download_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def execute(
6161
params=payload.jsonable_dict(),
6262
) as response:
6363
# https://github.com/nedbat/coveragepy/issues/1223
64-
async for chunk in response.aiter_bytes(): # pragma: no cover
64+
async for chunk in response.aiter_bytes(): # pragma: no branch
6565
await async_buffer.write(chunk)
6666

6767
await async_buffer.seek(0)

pybotx/client/users_api/users_as_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ async def execute(
4343
params=payload.jsonable_dict(),
4444
) as response:
4545
# https://github.com/nedbat/coveragepy/issues/1223
46-
async for chunk in response.aiter_bytes(): # pragma: no cover
46+
async for chunk in response.aiter_bytes(): # pragma: no branch
4747
await async_buffer.write(chunk)

pybotx/models/bot_account.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class BotAccountWithSecret(BaseModel):
2020

2121
model_config = ConfigDict(frozen=True)
2222

23-
def __setattr__(self, name: str, value: object) -> None: # pragma: no cover
23+
def __setattr__(self, name: str, value: object) -> None:
2424
if not getattr(self.model_config, "frozen", True) and name in self.model_fields:
2525
raise TypeError("BotAccountWithSecret is immutable") # pragma: no cover
26-
super().__setattr__(name, value) # pragma: no cover
26+
super().__setattr__(name, value)
2727

2828
@property
2929
def host(self) -> str:

pybotx/models/message/incoming_message.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class BotAPIIncomingMessage(BotAPIBaseCommand):
200200
@classmethod
201201
def validate_items(
202202
cls, value: List[Union[Dict[str, Any], Any]], info: Any
203-
) -> List[Any]: # pragma: no cover
203+
) -> List[Any]:
204204
item_model = (
205205
BotAPIAttachment if info.field_name == "attachments" else BotAPIEntity
206206
)
@@ -211,16 +211,14 @@ def validate_items(
211211
parsed.append(TypeAdapter(item_model).validate_python(item))
212212
except ValidationError:
213213
parsed.append(item)
214-
else:
215-
parsed.append(item) # pragma: no cover
216214
return parsed
217215

218216
def to_domain(self, raw_command: Dict[str, Any]) -> IncomingMessage: # noqa: WPS231
219217
if self.sender.device_meta:
220218
pushes = self.sender.device_meta.pushes
221219
timezone = self.sender.device_meta.timezone
222220
permissions = self.sender.device_meta.permissions
223-
else: # pragma: no cover
221+
else:
224222
pushes, timezone, permissions = None, None, None
225223

226224
device = UserDevice(

0 commit comments

Comments
 (0)