Skip to content

Commit

Permalink
Python3.12 Support (#19)
Browse files Browse the repository at this point in the history
* Python3.12 ready
* fix formatting
  • Loading branch information
ckreisl committed Jun 14, 2024
1 parent e0b1c15 commit 5752a23
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ repos:
- id: reorder-python-imports
args: [--py310-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/hhatto/autopep8
rev: v2.0.4
rev: v2.2.0
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
args: ['--ignore=E501']
9 changes: 6 additions & 3 deletions cs2posts/bot/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ def create_text(chat: Chat) -> str:

return (f"<b>Options</b>\n\n"
"Handle the automatically send Counter-Strike post notifications.\n\n"
f"{icon_is_update_interested} - Send Update Posts ({text_enabled_update})\n"
f"{icon_is_news_interested} - Send News Posts ({text_enabled_news})\n"
f"{icon_is_external_news_interested} - Send External News Posts ({text_enabled_external_news})\n\n"
f"{icon_is_update_interested} - Send Update Posts ("
f"{text_enabled_update})\n"
f"{icon_is_news_interested} - Send News Posts ("
f"{text_enabled_news})\n"
f"{icon_is_external_news_interested} - Send External News Posts ("
f"{text_enabled_external_news})\n\n"
f"Select an option to change, or press 'Close' to keep everything as it is.")


Expand Down
2 changes: 1 addition & 1 deletion cs2posts/bot/spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def warning(chat: Chat, max_strikes: int) -> str:

@staticmethod
def banned(chat: Chat, timout: int, max_strikes: int) -> str:
return f"<b>Strike ({chat.strikes}/{max_strikes})</b> Chat is now <b>banned</b> for spamming (Timeout: {int(timout/60)} mins)."
return f"<b>Strike ({chat.strikes}/{max_strikes})</b> Chat is now <b>banned</b> for spamming (Timeout: {int(timout / 60)} mins)."


class SpamProtector:
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pytest-asyncio==0.23.6
pytest-mock==3.14.0
pytest-cov==5.0.0
flake8==7.0.0
pre-commit
16 changes: 8 additions & 8 deletions tests/bot/test_cs2bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def bot(mocked_crawler, mocked_post_store, mocked_chat_store, mocked_spam_protec

def test_cs2_bot_init_no_files(bot):
bot.local_chat_store.is_empty.return_value = True
bot.local_chat_store.is_empty.called_once()
bot.local_chat_store.save.called_once()
bot.local_chat_store.is_empty.assert_called()
bot.local_chat_store.save.assert_called()

bot.local_post_store.is_empty.return_value = True
bot.local_post_store.is_empty.called_once()
bot.crawler.crawl.called_once()
bot.local_post_store.save.called_once()
bot.local_chat_store.save.called_once()
bot.local_post_store.is_empty.assert_called()
bot.crawler.crawl.assert_called()
bot.local_post_store.save.assert_called()
bot.local_chat_store.save.assert_called()

# TODO finish up setup

Expand Down Expand Up @@ -163,8 +163,8 @@ async def test_cs2_bot_left_chat_member_bot_left(bot):
bot.local_chat_store.reset_mock()
await bot.left_chat_member(mocked_update, mocked_context)

bot.chats.remove.called_once_with(chat)
bot.local_chat_store.save.called_once()
bot.chats.remove.assert_called_once_with(chat)
bot.local_chat_store.save.assert_called_once()


@pytest.mark.asyncio
Expand Down
4 changes: 2 additions & 2 deletions tests/bot/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ async def test_telegram_message_send_update(mocked_cs2_update_post):

await msg.send(bot=mocked_bot, chat_id=1337)

assert mocked_bot.send_photo.not_called
assert mocked_bot.send_message.called
mocked_bot.send_photo.assert_not_called()
mocked_bot.send_message.assert_called()
25 changes: 16 additions & 9 deletions tests/bot/test_spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from zoneinfo import ZoneInfo

import pytest
from telegram.constants import ParseMode

from cs2posts.bot import settings
from cs2posts.bot.chats import Chat
Expand Down Expand Up @@ -139,19 +140,25 @@ async def test_spam_protector_strike(spam_protector, chat):
chat.is_banned = False
await spam_protector.strike(mock_bot, chat)
assert chat.strikes == 1
assert await mock_bot.send_message.called_once_with(
chat.chat_id,
SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES))
mock_bot.send_message.assert_called_once_with(
chat_id=chat.chat_id,
text=SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES),
parse_mode=ParseMode.HTML)
mock_bot.reset_mock()

await spam_protector.strike(mock_bot, chat)
assert chat.strikes == 2
assert await mock_bot.send_message.called_once_with(
chat.chat_id,
SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES))
mock_bot.send_message.assert_called_once_with(
chat_id=chat.chat_id,
text=SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES),
parse_mode=ParseMode.HTML)
mock_bot.reset_mock()

await spam_protector.strike(mock_bot, chat)
assert chat.strikes == 3
assert await mock_bot.send_message.called_once_with(
chat.chat_id,
SpamProtectorMessages.banned(chat, settings.CHAT_BAN_TIMEOUT_SECONDS, settings.CHAT_MAX_STRIKES))
mock_bot.send_message.assert_called_once_with(
chat_id=chat.chat_id,
text=SpamProtectorMessages.banned(
chat, settings.CHAT_BAN_TIMEOUT_SECONDS, settings.CHAT_MAX_STRIKES),
parse_mode=ParseMode.HTML)
assert chat.is_banned

1 comment on commit 5752a23

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
crawler.py300100% 
cs2.py82890%30, 37, 42, 48, 103, 116–118
post.py58493%61–63, 66
store.py982475%21, 25, 29, 33, 42, 49–50, 57–58, 62, 68–69, 76, 87–88, 90, 104, 107–110, 117, 123, 132
bot
   __init__.py00100% 
   chats.py72593%80–83, 101
   constants.py40100% 
   content.py76692%28, 49, 62, 90, 100, 106
   cs2.py2826975%37–42, 44–46, 170, 173, 175, 178–183, 185–188, 293–296, 299–300, 302–303, 305, 307, 310–311, 314–315, 317–318, 320, 322, 325–326, 329–330, 332, 334–335, 337, 339, 342–343, 353, 355–357, 359–361, 363–365, 367, 379, 411, 413–416, 422
   decorators.py330%1, 3, 5
   message.py1585763%62, 85, 96, 109, 111, 121, 123–124, 126, 128–130, 139–142, 144, 156–159, 193–194, 196, 198–199, 201–202, 204, 206–211, 213–215, 217–220, 222–227, 229–230, 232, 234, 237–238, 253–255
   options.py1052080%35, 42–44, 49–51, 53, 70, 74–75, 79, 81, 83, 86–88, 90, 168–169
   settings.py130100% 
   spam.py710100% 
   utils.py24770%17, 21–23, 31–33
parser
   __init__.py00100% 
   parser.py14192%21
   steam2telegram_html.py260100% 
   steam_list.py520100% 
   steam_news_image.py160100% 
   steam_news_youtube.py120100% 
   steam_update_heading.py210100% 
TOTAL121720483% 

Tests Skipped Failures Errors Time
121 0 💤 0 ❌ 0 🔥 3.494s ⏱️

Please sign in to comment.