Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f11e140
dummy-commit to get the PR back online
Bibo-Joshi Mar 26, 2022
54408ae
up coverage a bit
Bibo-Joshi Mar 26, 2022
c8bedc3
Test{Pickle, Dict}Persistence
Bibo-Joshi Mar 26, 2022
f0103bd
Bump coverage for persistence a bit
Bibo-Joshi Mar 27, 2022
f588c19
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Mar 27, 2022
da3e3db
A few minor coverage improvements
Bibo-Joshi Mar 27, 2022
e247a9d
Test string representation of errors
Bibo-Joshi Mar 30, 2022
0010d06
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 1, 2022
0b27905
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 1, 2022
8546e3c
A first test on persisting non-blocking conversations
Bibo-Joshi Apr 1, 2022
786096e
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 3, 2022
527f94a
Some more tests on CH + persistence
Bibo-Joshi Apr 3, 2022
5c6ef3b
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 3, 2022
f0fa1dd
Test persistence of nested conversations
Bibo-Joshi Apr 3, 2022
0614a43
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 3, 2022
5d8acfa
Slow start on testing ConversationHandler
Bibo-Joshi Apr 5, 2022
f85cdff
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 5, 2022
a59a3e0
Some CH tests
Bibo-Joshi Apr 7, 2022
32547eb
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 7, 2022
2c149da
re-add test_slot_behaviours
harshil21 Apr 9, 2022
55d8441
remove leftovers from test_bot
harshil21 Apr 10, 2022
eb48c0f
A few more CH tests
Bibo-Joshi Apr 11, 2022
3e5c8cb
More CH tests
Bibo-Joshi Apr 11, 2022
aa5f29b
remove duplicate in test
Bibo-Joshi Apr 11, 2022
88a69a8
more ch tests
Bibo-Joshi Apr 11, 2022
e3a0f70
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 12, 2022
3294bd5
new tests for app.run
Bibo-Joshi Apr 12, 2022
7f649c3
adjust remaining ch timeout tests
Bibo-Joshi Apr 12, 2022
e98a787
adjust tests for nested conversations
Bibo-Joshi Apr 12, 2022
fa05c14
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 12, 2022
c82cdf3
test new ch-timeout-jq warning
Bibo-Joshi Apr 12, 2022
7234a36
fix a test
Bibo-Joshi Apr 13, 2022
93a190b
try stabilizing tests on macOS
Bibo-Joshi Apr 13, 2022
d81ef77
more ch tests
Bibo-Joshi Apr 16, 2022
6e4212a
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 16, 2022
c00b72b
increase coverage a bit
Bibo-Joshi Apr 16, 2022
5201aff
Merge branch 'asyncio' into asyncio-tests
Bibo-Joshi Apr 16, 2022
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
3 changes: 1 addition & 2 deletions telegram/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ def __init__(self, message: str):
def __str__(self) -> str:
return self.message

# TODO: test this
def __repr__(self) -> str:
return f'{self.__class__.__name__}({self.message})'
return f"{self.__class__.__name__}('{self.message}')"

def __reduce__(self) -> Tuple[type, Tuple[str]]:
return self.__class__, (self.message,)
Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/_utils/trackingdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TrackingDict(UserDict, Generic[_KT, _VT]):
DELETED: ClassVar = object()
"""Special marker indicating that an entry was deleted."""

__slots__ = ('_data', '_write_access_keys')
__slots__ = ('_write_access_keys',)

def __init__(self) -> None:
super().__init__()
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ class DictApplication(Application):
@pytest.fixture(scope='session')
@pytest.mark.asyncio
async def bot(bot_info):
"""Makes an ExtBot instance with the given bot_info"""
async with make_bot(bot_info) as _bot:
yield _bot


@pytest.fixture(scope='session')
@pytest.mark.asyncio
async def raw_bot(bot_info):
"""Makes an regular Bot instance with the given bot_info"""
async with DictBot(
bot_info['token'],
private_key=PRIVATE_KEY,
Expand Down
45 changes: 45 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,3 +1609,48 @@ def test_run_without_updater(self, bot):

with pytest.raises(RuntimeError, match='only available if the application has an Updater'):
app.run_polling()

@pytest.mark.parametrize('method', ['start', 'initialize'])
def test_run_error_in_application(self, bot, monkeypatch, method):
shutdowns = []

async def raise_method(*args, **kwargs):
raise RuntimeError('Test Exception')

async def shutdown(*args, **kwargs):
shutdowns.append(True)

monkeypatch.setattr(Application, method, raise_method)
monkeypatch.setattr(Application, 'shutdown', shutdown)
monkeypatch.setattr(Updater, 'shutdown', shutdown)
app = ApplicationBuilder().token(bot.token).build()
with pytest.raises(RuntimeError, match='Test Exception'):
app.run_polling(close_loop=False)

assert not app.running
assert not app.updater.running
assert shutdowns == [True, True]

@pytest.mark.parametrize('method', ['start_polling', 'start_webhook'])
def test_run_error_in_updater(self, bot, monkeypatch, method):
shutdowns = []

async def raise_method(*args, **kwargs):
raise RuntimeError('Test Exception')

async def shutdown(*args, **kwargs):
shutdowns.append(True)

monkeypatch.setattr(Updater, method, raise_method)
monkeypatch.setattr(Application, 'shutdown', shutdown)
monkeypatch.setattr(Updater, 'shutdown', shutdown)
app = ApplicationBuilder().token(bot.token).build()
with pytest.raises(RuntimeError, match='Test Exception'):
if 'polling' in method:
app.run_polling(close_loop=False)
else:
app.run_webhook(close_loop=False)

assert not app.running
assert not app.updater.running
assert shutdowns == [True, True]
5 changes: 5 additions & 0 deletions tests/test_applicationbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def builder():


class TestApplicationBuilder:
def test_slot_behaviour(self, builder, mro_slots):
for attr in builder.__slots__:
assert getattr(builder, attr, 'err') != 'err', f"got extra slot '{attr}'"
assert len(mro_slots(builder)) == len(set(mro_slots(builder))), "duplicate slot"

def test_build_without_token(self, builder):
with pytest.raises(RuntimeError, match='No bot token was set.'):
builder.build()
Expand Down
Loading