mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22:36:30 +03:00
python: type annotations for testplugin.py
This commit is contained in:
@@ -6,7 +6,7 @@ from array import array
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from email.utils import parseaddr
|
from email.utils import parseaddr
|
||||||
from threading import Event
|
from threading import Event
|
||||||
from typing import Any, Dict, Generator, List, Optional, Union
|
from typing import Any, Dict, Generator, List, Optional, Union, TYPE_CHECKING
|
||||||
|
|
||||||
from . import const, hookspec
|
from . import const, hookspec
|
||||||
from .capi import ffi, lib
|
from .capi import ffi, lib
|
||||||
@@ -22,6 +22,9 @@ from .cutil import (
|
|||||||
from .message import Message
|
from .message import Message
|
||||||
from .tracker import ConfigureTracker, ImexTracker
|
from .tracker import ConfigureTracker, ImexTracker
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .events import FFIEventTracker
|
||||||
|
|
||||||
|
|
||||||
class MissingCredentials(ValueError):
|
class MissingCredentials(ValueError):
|
||||||
"""Account is missing `addr` and `mail_pw` config values."""
|
"""Account is missing `addr` and `mail_pw` config values."""
|
||||||
@@ -60,6 +63,9 @@ class Account:
|
|||||||
|
|
||||||
MissingCredentials = MissingCredentials
|
MissingCredentials = MissingCredentials
|
||||||
|
|
||||||
|
_logid: str
|
||||||
|
_evtracker: "FFIEventTracker"
|
||||||
|
|
||||||
def __init__(self, db_path, os_name=None, logging=True, closed=False) -> None:
|
def __init__(self, db_path, os_name=None, logging=True, closed=False) -> None:
|
||||||
from .events import EventThread
|
from .events import EventThread
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,8 @@ class ACSetup:
|
|||||||
CONFIGURED = "CONFIGURED"
|
CONFIGURED = "CONFIGURED"
|
||||||
IDLEREADY = "IDLEREADY"
|
IDLEREADY = "IDLEREADY"
|
||||||
|
|
||||||
|
_configured_events: Queue
|
||||||
|
|
||||||
def __init__(self, testprocess, init_time):
|
def __init__(self, testprocess, init_time):
|
||||||
self._configured_events = Queue()
|
self._configured_events = Queue()
|
||||||
self._account2state = {}
|
self._account2state = {}
|
||||||
@@ -376,8 +378,13 @@ class ACSetup:
|
|||||||
|
|
||||||
|
|
||||||
class ACFactory:
|
class ACFactory:
|
||||||
|
"""Account factory"""
|
||||||
|
|
||||||
|
init_time: float
|
||||||
_finalizers: List[Callable[[], None]]
|
_finalizers: List[Callable[[], None]]
|
||||||
_accounts: List[Account]
|
_accounts: List[Account]
|
||||||
|
_acsetup: ACSetup
|
||||||
|
_preconfigured_keys: List[str]
|
||||||
|
|
||||||
def __init__(self, request, testprocess, tmpdir, data) -> None:
|
def __init__(self, request, testprocess, tmpdir, data) -> None:
|
||||||
self.init_time = time.time()
|
self.init_time = time.time()
|
||||||
@@ -429,14 +436,15 @@ class ACFactory:
|
|||||||
assert "addr" in configdict and "mail_pw" in configdict
|
assert "addr" in configdict and "mail_pw" in configdict
|
||||||
return configdict
|
return configdict
|
||||||
|
|
||||||
def _get_cached_account(self, addr):
|
def _get_cached_account(self, addr) -> Optional[Account]:
|
||||||
if addr in self.testprocess._addr2files:
|
if addr in self.testprocess._addr2files:
|
||||||
return self._getaccount(addr)
|
return self._getaccount(addr)
|
||||||
|
return None
|
||||||
|
|
||||||
def get_unconfigured_account(self, closed=False):
|
def get_unconfigured_account(self, closed=False) -> Account:
|
||||||
return self._getaccount(closed=closed)
|
return self._getaccount(closed=closed)
|
||||||
|
|
||||||
def _getaccount(self, try_cache_addr=None, closed=False):
|
def _getaccount(self, try_cache_addr=None, closed=False) -> Account:
|
||||||
logid = f"ac{len(self._accounts) + 1}"
|
logid = f"ac{len(self._accounts) + 1}"
|
||||||
# we need to use fixed database basename for maybe_cache_* functions to work
|
# we need to use fixed database basename for maybe_cache_* functions to work
|
||||||
path = self.tmpdir.mkdir(logid).join("dc.db")
|
path = self.tmpdir.mkdir(logid).join("dc.db")
|
||||||
@@ -450,10 +458,10 @@ class ACFactory:
|
|||||||
self._accounts.append(ac)
|
self._accounts.append(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def set_logging_default(self, logging):
|
def set_logging_default(self, logging) -> None:
|
||||||
self._logging = bool(logging)
|
self._logging = bool(logging)
|
||||||
|
|
||||||
def remove_preconfigured_keys(self):
|
def remove_preconfigured_keys(self) -> None:
|
||||||
self._preconfigured_keys = []
|
self._preconfigured_keys = []
|
||||||
|
|
||||||
def _preconfigure_key(self, account, addr):
|
def _preconfigure_key(self, account, addr):
|
||||||
@@ -491,7 +499,7 @@ class ACFactory:
|
|||||||
self._acsetup.init_logging(ac)
|
self._acsetup.init_logging(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def new_online_configuring_account(self, cloned_from=None, cache=False, **kwargs):
|
def new_online_configuring_account(self, cloned_from=None, cache=False, **kwargs) -> Account:
|
||||||
if cloned_from is None:
|
if cloned_from is None:
|
||||||
configdict = self.get_next_liveconfig()
|
configdict = self.get_next_liveconfig()
|
||||||
else:
|
else:
|
||||||
@@ -513,7 +521,7 @@ class ACFactory:
|
|||||||
self._acsetup.start_configure(ac)
|
self._acsetup.start_configure(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def prepare_account_from_liveconfig(self, configdict):
|
def prepare_account_from_liveconfig(self, configdict) -> Account:
|
||||||
ac = self.get_unconfigured_account()
|
ac = self.get_unconfigured_account()
|
||||||
assert "addr" in configdict and "mail_pw" in configdict, configdict
|
assert "addr" in configdict and "mail_pw" in configdict, configdict
|
||||||
configdict.setdefault("bcc_self", False)
|
configdict.setdefault("bcc_self", False)
|
||||||
@@ -523,11 +531,11 @@ class ACFactory:
|
|||||||
self._preconfigure_key(ac, configdict["addr"])
|
self._preconfigure_key(ac, configdict["addr"])
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def wait_configured(self, account):
|
def wait_configured(self, account) -> None:
|
||||||
"""Wait until the specified account has successfully completed configure."""
|
"""Wait until the specified account has successfully completed configure."""
|
||||||
self._acsetup.wait_one_configured(account)
|
self._acsetup.wait_one_configured(account)
|
||||||
|
|
||||||
def bring_accounts_online(self):
|
def bring_accounts_online(self) -> None:
|
||||||
print("bringing accounts online")
|
print("bringing accounts online")
|
||||||
self._acsetup.bring_online()
|
self._acsetup.bring_online()
|
||||||
print("all accounts online")
|
print("all accounts online")
|
||||||
|
|||||||
Reference in New Issue
Block a user