Compare commits

...
2 Commits
Author SHA1 Message Date
Tanner 5c4b1a7dbd Upgrade to Python 3.11 2026-11-18 17:52:06 +00:00
Tanner f9c6845da4 Add Python 3.11 upgrade tests 2026-11-18 17:14:24 +00:00
3 changed files with 135 additions and 12 deletions
+2
View File
@@ -0,0 +1,2 @@
aiohttp
Telethon
+37 -12
View File
@@ -1,13 +1,38 @@
aiohttp==3.6.3 # This file was autogenerated by uv via the following command:
async-timeout==3.0.1 # uv pip compile --python-version 3.11 -o requirements.txt requirements.in
attrs==20.3.0 aiohappyeyeballs==2.7.1
chardet==3.0.4 # via aiohttp
idna==3.1 aiohttp==3.14.5
idna-ssl==1.1.0 # via -r requirements.in
multidict==4.7.6 aiosignal==1.4.0
# via aiohttp
attrs==26.1.0
# via aiohttp
frozenlist==1.8.0
# via
# aiohttp
# aiosignal
idna==3.20
# via yarl
multidict==7.2.1
# via
# aiohttp
# yarl
propcache==0.5.4
# via
# aiohttp
# yarl
pyaes==1.6.1 pyaes==1.6.1
pyasn1==0.4.8 # via telethon
rsa==4.7.2 pyasn1==0.6.5
telethon==1.45.0 # via rsa
typing-extensions==3.7.4.3 rsa==4.9.1
yarl==1.5.1 # via telethon
telethon==1.46.0
# via -r requirements.in
typing-extensions==4.16.0
# via
# aiohttp
# aiosignal
yarl==1.25.1
# via aiohttp
+96
View File
@@ -0,0 +1,96 @@
import importlib.util
import sys
import types
import unittest
from pathlib import Path
import aiohttp
ROOT = Path(__file__).parent
class _FakeLoop:
def run_until_complete(self, coroutine):
coroutine.close()
class _FakeBot:
def __init__(self):
self.loop = _FakeLoop()
def on(self, event):
return lambda callback: callback
def start(self, **kwargs):
return self
def __enter__(self):
return self
def __exit__(self, *args):
return False
def load_service():
settings = types.ModuleType('settings')
settings.API_ID = 1
settings.API_HASH = 'test-hash'
settings.API_TOKEN = 'test-token'
settings.DYNMAP_ADDRESS = 'https://dynmap.example.test'
settings.CUSTOM_NAMES = {}
settings.CUSTOM_EMOJIS = {}
settings.CHAT_ID = 1
settings.THIS_SERVER_IP = '127.0.0.1'
telethon = types.ModuleType('telethon')
telethon.TelegramClient = lambda *args: _FakeBot()
telethon.events = types.SimpleNamespace(NewMessage=lambda **kwargs: object())
saved = {name: sys.modules.get(name) for name in ('settings', 'telethon')}
sys.modules['settings'] = settings
sys.modules['telethon'] = telethon
try:
spec = importlib.util.spec_from_file_location('teledynmap_service_under_test', ROOT / 'teledynmap.py')
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
finally:
for name, previous in saved.items():
if previous is None:
sys.modules.pop(name, None)
else:
sys.modules[name] = previous
service = load_service()
class TeleDynmapUpgradeTests(unittest.TestCase):
def test_suite_runs_on_supported_python(self):
self.assertEqual(sys.version_info[0], 3)
self.assertGreaterEqual(sys.version_info[:2], (3, 11))
def test_service_sources_compile_under_target_python(self):
for path in ROOT.rglob('*.py'):
if 'env' in path.parts or '.git' in path.parts or path.name == 'tests.py':
continue
with self.subTest(source=str(path.relative_to(ROOT))):
compile(path.read_bytes(), str(path), 'exec')
def test_aiohttp_and_telethon_apis_import(self):
from telethon import TelegramClient, events
self.assertTrue(aiohttp.ClientSession)
self.assertTrue(TelegramClient)
self.assertTrue(events.NewMessage)
def test_api_url_and_name_hash_are_stable(self):
import hashlib
self.assertEqual(service.api('/route'), 'https://dynmap.example.test/route')
expected = int(hashlib.md5('🌎 Tanner'.encode()).hexdigest(), 16)
self.assertEqual(service.md5('🌎 Tanner'), expected)
self.assertGreaterEqual(expected % len(service.emojis), 0)
self.assertLess(expected % len(service.emojis), len(service.emojis))
if __name__ == '__main__':
unittest.main()