Skip to content

Commit

Permalink
Merge branch 'filipre:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joe128 authored Dec 11, 2024
2 parents bcd794d + be4a8f0 commit 34454cf
Show file tree
Hide file tree
Showing 10 changed files with 764 additions and 724 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ jobs:
with:
ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }}

- name: Set up Python 3.11
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: 3.13.1

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1
poetry-version: 1.8.4

- name: Install dependencies
run: poetry install --no-dev
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Python 3.11
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: 3.13.1
- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1
poetry-version: 1.8.4
- name: Install dependencies
run: poetry install --no-dev
- name: Get Package Version
Expand All @@ -51,14 +51,14 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: 3.13.1
- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1
poetry-version: 1.8.4
- name: Install dependencies
run: poetry install --no-dev
- name: Get Package Version
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: 3.13.1
- uses: pre-commit/[email protected]

unittest:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
python-version: 3.13.1
- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1
poetry-version: 1.8.4
- name: Install dependencies
run: poetry install --no-dev
- name: Run unit tests
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
exclude: ^dist/
1,406 changes: 716 additions & 690 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ maintainers = ["René Filip"]
name = "signalbot"
readme = "README.md"
repository = "https://github.com/filipre/signalbot"
version = "0.10.1"
version = "0.10.2"

[tool.poetry.dependencies]
APScheduler = "^3.9.1"
aiohttp = "^3.8.1"
python = "^3.9"
redis = "^4.1.4"
websockets = "^10.2"
APScheduler = ">=3.11.0"
aiohttp = ">=3.11.9"
python = ">=3.13.1"
redis = ">=5.2.0"
websockets = ">=14.1"

[tool.poetry.dev-dependencies]
black = "^22.1.0"
flake8 = "^4.0.1"
pre-commit = "^2.17.0"
black = ">=24.10.0"
flake8 = ">=7.1.1"
pre-commit = ">=4.0.1"

[build-system]
build-backend = "poetry.core.masonry.api"
Expand Down
6 changes: 4 additions & 2 deletions signalbot/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
from abc import ABC, abstractmethod

from .message import Message
from .context import Context
Expand Down Expand Up @@ -27,7 +28,7 @@ async def wrapper_triggered(*args, **kwargs):
return decorator_triggered


class Command:
class Command(ABC):
# optional
def setup(self):
pass
Expand All @@ -37,8 +38,9 @@ def describe(self) -> str:
return None

# overwrite
@abstractmethod
async def handle(self, context: Context):
raise NotImplementedError
pass

# helper method
# deprecated: please use @triggered
Expand Down
2 changes: 2 additions & 0 deletions signalbot/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .chat_testing import (
ChatTestCase,
DummyCommand,
SendMessagesMock,
ReceiveMessagesMock,
ReactMessageMock,
Expand All @@ -8,6 +9,7 @@

__all__ = [
"ChatTestCase",
"DummyCommand",
"SendMessagesMock",
"ReceiveMessagesMock",
"ReactMessageMock",
Expand Down
7 changes: 6 additions & 1 deletion signalbot/utils/chat_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import aiohttp
from unittest.mock import AsyncMock, MagicMock

from ..bot import SignalBot
from ..bot import SignalBot, Command, Context

from unittest.mock import patch

Expand Down Expand Up @@ -131,3 +131,8 @@ def _extract_responses(self):
for args in self.call_args_list:
results.append(args[0])
return results


class DummyCommand(Command):
async def handle(self, context: Context):
pass
17 changes: 11 additions & 6 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import asyncio
from unittest.mock import patch, AsyncMock
from signalbot import SignalBot, Command, SignalAPI
from signalbot.context import Context
from signalbot.utils import DummyCommand


class BotTestCase(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -35,8 +37,8 @@ async def test_produce(self, mock):
)
self.signal_bot.listen(TestProducer.group_id, TestProducer.internal_id)
# Any two commands
self.signal_bot.register(Command())
self.signal_bot.register(Command())
self.signal_bot.register(DummyCommand())
self.signal_bot.register(DummyCommand())

await self.signal_bot._produce(1337)

Expand Down Expand Up @@ -99,13 +101,13 @@ def test_listen_valid_invalid_phone_number(self):

class TestRegisterCommand(BotTestCase):
def test_register_one_command(self):
self.signal_bot.register(Command())
self.signal_bot.register(DummyCommand())
self.assertEqual(len(self.signal_bot.commands), 1)

def test_register_three_commands(self):
self.signal_bot.register(Command())
self.signal_bot.register(Command())
self.signal_bot.register(Command())
self.signal_bot.register(DummyCommand())
self.signal_bot.register(DummyCommand())
self.signal_bot.register(DummyCommand())
self.assertEqual(len(self.signal_bot.commands), 3)

def test_register_calls_setup_of_command(self):
Expand All @@ -116,6 +118,9 @@ def __init__(self):
def setup(self):
self.state = True

def handle(self, context: Context):
pass

cmd = SomeTestCommand()
self.assertEqual(cmd.state, False)

Expand Down

0 comments on commit 34454cf

Please sign in to comment.