Skip to content

Commit

Permalink
chore: tried to pass python 12 but it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
bamthomas committed Jan 10, 2025
1 parent fcb3cd7 commit 0b09244
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: true
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.9", "3.10", "3.11" ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This library is inspired by imaplib_ and imaplib2_ from Piers Lauder, Nicolas Se

The aim is to port the imaplib with asyncio_, to benefit from the sleep or treat model.

It runs with python 3.9, 3.10, 3.11.
It is tested against python 3.9, 3.10, 3.11 matrix. But the library itself *could* run with other python versions.

Example
-------
Expand Down
12 changes: 7 additions & 5 deletions aioimaplib/tests/server_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
async def main_test(server: MockImapServer, ssl_context: Optional[SSLContext]):
srv = await server.run_server(host='127.0.0.1', port=12345, fetch_chunk_size=64, ssl_context=ssl_context)
async with srv:
await srv.serve_forever()
try:
await srv.serve_forever()
except Exception:
srv.shutdown()


@pytest.fixture()
Expand All @@ -36,13 +39,13 @@ def advance_time(event_loop, request):
def with_server(event_loop, request):
capabilities = request.param if hasattr(request, 'param') else None #
imapserver = create_server(capabilities, event_loop)
cancel_handle = asyncio.ensure_future(main_test(server=imapserver, ssl_context=None))
main_server_future = asyncio.ensure_future(main_test(server=imapserver, ssl_context=None))
event_loop.run_until_complete(asyncio.sleep(0.01))
try:
yield imapserver
finally:
imapserver.reset()
cancel_handle.cancel()
main_server_future.cancel()


def create_server(capabilities, event_loop):
Expand All @@ -66,10 +69,9 @@ def with_ssl_server(event_loop, with_ssl):
try:
yield imapserver
finally:
imapserver.reset()
cancel_handle.cancel()

imapserver.reset()


async def login_user(login, password, select=False, lib=imaplib.IMAP4, loop=None):
args = {'host': '127.0.0.1', 'port': 12345} if loop is None else {'host': '127.0.0.1', 'port': 12345, 'loop': loop}
Expand Down
1 change: 0 additions & 1 deletion aioimaplib/tests/test_aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ async def test_rfc2971_id(with_server):
assert ('OK', [b'ID command completed']) == response



@pytest.mark.asyncio()
async def test_callback_is_called_when_connection_is_lost(event_loop):
imapserver = create_server(None, event_loop)
Expand Down
50 changes: 26 additions & 24 deletions aioimaplib/tests/test_aioimaplib_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from aioimaplib import aioimaplib
from aioimaplib.aioimaplib import Abort
from aioimaplib.tests.imapserver import ImapProtocol, ServerState
from aioimaplib.tests.server_fixture import with_server, login_user_async
from aioimaplib.tests.imapserver import ImapProtocol, ServerState, MockImapServer
from aioimaplib.tests.server_fixture import with_server, login_user_async, main_test

aioimaplib.log.setLevel(logging.WARNING)
sh = logging.StreamHandler()
Expand All @@ -15,6 +15,30 @@
aioimaplib.log.addHandler(sh)


# test failing with python 12
@pytest.mark.asyncio()
async def test_capabilities_server_not_compliant(event_loop):
class NotCompliantProtocol(ImapProtocol):
def capability(self, tag, *args):
"""should send CAPABILITY IMAP4rev1 YESAUTH """
self.send_untagged_line('CAPABILITY YESAUTH')
self.send_tagged_line(tag, 'OK Pre-login capabilities listed, post-login capabilities have more')

class NotCompliantServer(MockImapServer):
def run_server(self, host='127.0.0.1', port=1143, fetch_chunk_size=0, ssl_context=None):
return event_loop.create_server(lambda: NotCompliantProtocol(ServerState(), loop=self.loop), host=host, port=port, ssl=None)

imap_srv = NotCompliantServer(loop=event_loop)
srv = await imap_srv.run_server(port=12345)
main_server_future = asyncio.ensure_future(main_test(server=srv, ssl_context=None))

with pytest.raises(asyncio.TimeoutError):
with pytest.raises(aioimaplib.Error) as expected:
await login_user_async('user', 'pass', timeout=0.1)

assert expected == 'server not IMAP4 compliant'


@pytest.mark.asyncio()
async def test_capabilities(with_server):
imap_client = aioimaplib.IMAP4(port=12345, loop=asyncio.get_running_loop())
Expand All @@ -25,28 +49,6 @@ async def test_capabilities(with_server):
assert imap_client.has_capability('YESAUTH')


@pytest.mark.asyncio()
async def test_capabilities_server_not_compliant(event_loop):
def create_protocol():
class NotCompliantProtocol(ImapProtocol):
def capability(self, tag, *args):
"""No sent IMAP4rev1"""
self.send_untagged_line('CAPABILITY YESAUTH')
self.send_tagged_line(tag, 'OK Pre-login capabilities listed, post-login capabilities have more')
protocol = NotCompliantProtocol(ServerState(), loop=event_loop)
return protocol

srv = await event_loop.create_server(create_protocol, host='127.0.0.1', port=12345, ssl=None)
async with srv:
await srv.start_serving()

with pytest.raises(asyncio.TimeoutError):
with pytest.raises(aioimaplib.Error) as expected:
await login_user_async('user', 'pass', timeout=0.1)

assert expected == 'server not IMAP4 compliant'


@pytest.mark.parametrize("with_server", [''], indirect=True) # '' = no capabilities
@pytest.mark.asyncio()
async def test_idle_messages_without_idle_capability_abort_command(with_server):
Expand Down
1 change: 1 addition & 0 deletions aioimaplib/tests/test_aioimaplib_clocked.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def test_when_sync_commands_timeout__they_should_be_removed_from_protocol_
assert imap_client.protocol.pending_sync_command is None


# test failing with python 12
@pytest.mark.asyncio()
async def test_idle_start__exits_queue_get_without_timeout_error(event_loop, with_server, advance_time):
imap_client = await login_user_async('user', 'pass', select=True, loop=event_loop)
Expand Down

0 comments on commit 0b09244

Please sign in to comment.