matrix-python 1.4.0a0__tar.gz → 1.4.1a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/PKG-INFO +1 -1
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/_version.py +3 -3
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/bot.py +1 -1
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/extension.py +16 -3
- matrix_python-1.4.1a0/matrix/protocols.py +9 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix_python.egg-info/PKG-INFO +1 -1
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix_python.egg-info/SOURCES.txt +1 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_extension.py +92 -6
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/dependabot.yml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/workflows/CODEOWNERS +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/workflows/codeql.yml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/workflows/publish.yml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/workflows/scorecard.yml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.github/workflows/tests.yml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/.gitignore +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/CODE_OF_CONDUCT.md +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/CONTRIBUTING.md +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/LICENSE +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/README.md +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/README.md +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/checks.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/config.yaml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/cooldown.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/error_handling.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/extension.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/ping.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/reaction.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/examples/scheduler.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/__init__.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/checks.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/command.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/config.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/content.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/context.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/errors.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/group.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/help/__init__.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/help/help_command.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/help/pagination.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/message.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/registry.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/room.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/scheduler.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix/types.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix_python.egg-info/dependency_links.txt +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix_python.egg-info/requires.txt +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/matrix_python.egg-info/top_level.txt +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/mypy.ini +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/pyproject.toml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/setup.cfg +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/config_fixture.yaml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/config_fixture_token.yaml +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/help/test_default_help_command.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/help/test_help_command.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/help/test_pagination.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_bot.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_command.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_config.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_context.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_group.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_message.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_registry.py +0 -0
- {matrix_python-1.4.0a0 → matrix_python-1.4.1a0}/tests/test_room.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.1a0
|
|
4
4
|
Summary: An easy-to-use Matrix bot framework designed for quick development and minimal setup
|
|
5
5
|
Author: Simon Roy, Chris Dedman Rollet
|
|
6
6
|
Maintainer-email: Code Society Lab <admin@codesociety.xyz>
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.4.
|
|
22
|
-
__version_tuple__ = version_tuple = (1, 4,
|
|
21
|
+
__version__ = version = '1.4.1a0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 4, 1, 'a0')
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id = '
|
|
24
|
+
__commit_id__ = commit_id = 'gcd71354ad'
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import logging
|
|
2
1
|
import inspect
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Callable, Optional
|
|
3
4
|
|
|
4
|
-
from
|
|
5
|
+
from matrix.protocols import BotLike
|
|
5
6
|
from matrix.registry import Registry
|
|
7
|
+
from matrix.room import Room
|
|
6
8
|
|
|
7
9
|
logger = logging.getLogger(__name__)
|
|
8
10
|
|
|
@@ -10,10 +12,19 @@ logger = logging.getLogger(__name__)
|
|
|
10
12
|
class Extension(Registry):
|
|
11
13
|
def __init__(self, name: str, prefix: Optional[str] = None) -> None:
|
|
12
14
|
super().__init__(name, prefix=prefix)
|
|
15
|
+
|
|
16
|
+
self.bot: Optional[BotLike] = None
|
|
13
17
|
self._on_load: Optional[Callable] = None
|
|
14
18
|
self._on_unload: Optional[Callable] = None
|
|
15
19
|
|
|
16
|
-
def
|
|
20
|
+
def get_room(self, room_id: str) -> Room:
|
|
21
|
+
if self.bot is None:
|
|
22
|
+
raise RuntimeError("Extension is not loaded")
|
|
23
|
+
return self.bot.get_room(room_id)
|
|
24
|
+
|
|
25
|
+
def load(self, bot: BotLike) -> None:
|
|
26
|
+
self.bot = bot
|
|
27
|
+
|
|
17
28
|
if self._on_load:
|
|
18
29
|
self._on_load()
|
|
19
30
|
|
|
@@ -35,6 +46,8 @@ class Extension(Registry):
|
|
|
35
46
|
return func
|
|
36
47
|
|
|
37
48
|
def unload(self) -> None:
|
|
49
|
+
self.bot = None
|
|
50
|
+
|
|
38
51
|
if self._on_unload:
|
|
39
52
|
self._on_unload()
|
|
40
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.1a0
|
|
4
4
|
Summary: An easy-to-use Matrix bot framework designed for quick development and minimal setup
|
|
5
5
|
Author: Simon Roy, Chris Dedman Rollet
|
|
6
6
|
Maintainer-email: Code Society Lab <admin@codesociety.xyz>
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
|
+
from unittest.mock import MagicMock
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
3
6
|
from matrix.extension import Extension
|
|
7
|
+
from matrix.room import Room
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MockBot:
|
|
11
|
+
prefix: str = "!"
|
|
12
|
+
|
|
13
|
+
def __init__(self, room: Optional[Room] = None) -> None:
|
|
14
|
+
self.get_room = MagicMock(return_value=room or MagicMock(spec=Room))
|
|
4
15
|
|
|
5
16
|
|
|
6
17
|
@pytest.fixture
|
|
@@ -8,6 +19,14 @@ def extension() -> Extension:
|
|
|
8
19
|
return Extension(name="test_ext", prefix="!")
|
|
9
20
|
|
|
10
21
|
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def bot() -> MockBot:
|
|
24
|
+
return MockBot()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# INIT
|
|
28
|
+
|
|
29
|
+
|
|
11
30
|
def test_init_with_name_and_prefix__expect_attributes_set():
|
|
12
31
|
ext = Extension(name="math", prefix="!")
|
|
13
32
|
|
|
@@ -21,6 +40,10 @@ def test_init_with_name_only__expect_prefix_is_none():
|
|
|
21
40
|
assert ext.prefix is None
|
|
22
41
|
|
|
23
42
|
|
|
43
|
+
def test_init__expect_bot_is_none(extension: Extension):
|
|
44
|
+
assert extension.bot is None
|
|
45
|
+
|
|
46
|
+
|
|
24
47
|
def test_init__expect_on_load_is_none(extension: Extension):
|
|
25
48
|
assert extension._on_load is None
|
|
26
49
|
|
|
@@ -45,6 +68,9 @@ def test_init__expect_empty_checks(extension: Extension):
|
|
|
45
68
|
assert extension._checks == []
|
|
46
69
|
|
|
47
70
|
|
|
71
|
+
# ON LOAD
|
|
72
|
+
|
|
73
|
+
|
|
48
74
|
def test_on_load_with_sync_function__expect_handler_registered(extension: Extension):
|
|
49
75
|
@extension.on_load
|
|
50
76
|
def setup():
|
|
@@ -86,20 +112,34 @@ def test_on_load_overwrites_previous_handler__expect_latest_handler(
|
|
|
86
112
|
assert extension._on_load is second
|
|
87
113
|
|
|
88
114
|
|
|
89
|
-
|
|
115
|
+
# LOAD
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_load__expect_bot_set(extension: Extension, bot: MockBot):
|
|
119
|
+
extension.load(bot)
|
|
120
|
+
|
|
121
|
+
assert extension.bot is bot
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_load_with_registered_handler__expect_handler_called(
|
|
125
|
+
extension: Extension, bot: MockBot
|
|
126
|
+
):
|
|
90
127
|
called = []
|
|
91
128
|
|
|
92
129
|
@extension.on_load
|
|
93
130
|
def setup():
|
|
94
131
|
called.append(True)
|
|
95
132
|
|
|
96
|
-
extension.load()
|
|
133
|
+
extension.load(bot)
|
|
97
134
|
|
|
98
135
|
assert called == [True]
|
|
99
136
|
|
|
100
137
|
|
|
101
|
-
def test_load_with_no_handler__expect_no_error(extension: Extension):
|
|
102
|
-
extension.load()
|
|
138
|
+
def test_load_with_no_handler__expect_no_error(extension: Extension, bot: MockBot):
|
|
139
|
+
extension.load(bot)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ON UNLOAD
|
|
103
143
|
|
|
104
144
|
|
|
105
145
|
def test_on_unload_with_sync_function__expect_handler_registered(extension: Extension):
|
|
@@ -143,17 +183,63 @@ def test_on_unload_overwrites_previous_handler__expect_latest_handler(
|
|
|
143
183
|
assert extension._on_unload is second
|
|
144
184
|
|
|
145
185
|
|
|
146
|
-
|
|
186
|
+
# UNLOAD
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_unload__expect_bot_cleared(extension: Extension, bot: MockBot):
|
|
190
|
+
extension.load(bot)
|
|
191
|
+
extension.unload()
|
|
192
|
+
|
|
193
|
+
assert extension.bot is None
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_unload_with_registered_handler__expect_handler_called(
|
|
197
|
+
extension: Extension, bot: MockBot
|
|
198
|
+
):
|
|
147
199
|
called = []
|
|
148
200
|
|
|
149
201
|
@extension.on_unload
|
|
150
202
|
def teardown():
|
|
151
203
|
called.append(True)
|
|
152
204
|
|
|
205
|
+
extension.load(bot)
|
|
153
206
|
extension.unload()
|
|
154
207
|
|
|
155
208
|
assert called == [True]
|
|
156
209
|
|
|
157
210
|
|
|
158
|
-
def test_unload_with_no_handler__expect_no_error(extension: Extension):
|
|
211
|
+
def test_unload_with_no_handler__expect_no_error(extension: Extension, bot: MockBot):
|
|
212
|
+
extension.load(bot)
|
|
159
213
|
extension.unload()
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# GET ROOM
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def test_get_room_before_load__expect_runtime_error(extension: Extension):
|
|
220
|
+
with pytest.raises(RuntimeError, match="Extension is not loaded"):
|
|
221
|
+
extension.get_room("!room:example.com")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_get_room_after_load__expect_delegates_to_bot(
|
|
225
|
+
extension: Extension, bot: MockBot
|
|
226
|
+
):
|
|
227
|
+
room_id = "!room:example.com"
|
|
228
|
+
expected_room = MagicMock(spec=Room)
|
|
229
|
+
bot.get_room.return_value = expected_room
|
|
230
|
+
|
|
231
|
+
extension.load(bot)
|
|
232
|
+
result = extension.get_room(room_id)
|
|
233
|
+
|
|
234
|
+
bot.get_room.assert_called_once_with(room_id)
|
|
235
|
+
assert result is expected_room
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def test_get_room_after_unload__expect_runtime_error(
|
|
239
|
+
extension: Extension, bot: MockBot
|
|
240
|
+
):
|
|
241
|
+
extension.load(bot)
|
|
242
|
+
extension.unload()
|
|
243
|
+
|
|
244
|
+
with pytest.raises(RuntimeError, match="Extension is not loaded"):
|
|
245
|
+
extension.get_room("!room:example.com")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|