mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
refactor some python infra, and don't do shutdown on __del__, it's not prepared for running during teardown
This commit is contained in:
@@ -67,8 +67,8 @@ class Account(object):
|
|||||||
""" re-enable logging. """
|
""" re-enable logging. """
|
||||||
self._logging = True
|
self._logging = True
|
||||||
|
|
||||||
def __del__(self):
|
# def __del__(self):
|
||||||
self.shutdown()
|
# self.shutdown()
|
||||||
|
|
||||||
def log(self, msg):
|
def log(self, msg):
|
||||||
if self._logging:
|
if self._logging:
|
||||||
|
|||||||
@@ -77,9 +77,26 @@ class FFIEventTracker:
|
|||||||
timeout = timeout if timeout is not None else self._timeout
|
timeout = timeout if timeout is not None else self._timeout
|
||||||
ev = self._event_queue.get(timeout=timeout)
|
ev = self._event_queue.get(timeout=timeout)
|
||||||
if check_error and ev.name == "DC_EVENT_ERROR":
|
if check_error and ev.name == "DC_EVENT_ERROR":
|
||||||
raise ValueError(str(ev))
|
raise ValueError("unexpected event: {}".format(ev))
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
|
def iter_events(self, timeout=None, check_error=True):
|
||||||
|
while 1:
|
||||||
|
yield self.get(timeout=timeout, check_error=check_error)
|
||||||
|
|
||||||
|
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
||||||
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
|
for ev in self.iter_events(timeout=timeout, check_error=check_error):
|
||||||
|
if rex.match(ev.name):
|
||||||
|
return ev
|
||||||
|
|
||||||
|
def get_info_matching(self, regex):
|
||||||
|
rex = re.compile("(?:{}).*".format(regex))
|
||||||
|
while 1:
|
||||||
|
ev = self.get_matching("DC_EVENT_INFO")
|
||||||
|
if rex.match(ev.data2):
|
||||||
|
return ev
|
||||||
|
|
||||||
def ensure_event_not_queued(self, event_name_regex):
|
def ensure_event_not_queued(self, event_name_regex):
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
@@ -98,25 +115,6 @@ class FFIEventTracker:
|
|||||||
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
|
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
|
||||||
break
|
break
|
||||||
|
|
||||||
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
|
||||||
for ev in self.yield_matching(event_name_regex, check_error, timeout):
|
|
||||||
return ev
|
|
||||||
|
|
||||||
def yield_matching(self, event_name_regex, check_error=True, timeout=None):
|
|
||||||
self.account.log("-- waiting for event with regex: {} --".format(event_name_regex))
|
|
||||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
|
||||||
while 1:
|
|
||||||
ev = self.get(timeout=timeout, check_error=check_error)
|
|
||||||
if rex.match(ev.name):
|
|
||||||
yield ev
|
|
||||||
|
|
||||||
def get_info_matching(self, regex):
|
|
||||||
rex = re.compile("(?:{}).*".format(regex))
|
|
||||||
while 1:
|
|
||||||
ev = self.get_matching("DC_EVENT_INFO")
|
|
||||||
if rex.match(ev.data2):
|
|
||||||
return ev
|
|
||||||
|
|
||||||
def wait_next_incoming_message(self):
|
def wait_next_incoming_message(self):
|
||||||
""" wait for and return next incoming message. """
|
""" wait for and return next incoming message. """
|
||||||
ev = self.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = self.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
|
|||||||
@@ -1087,7 +1087,7 @@ class TestOnlineAccount:
|
|||||||
lp.sec("ac2: mark seen {}".format(msg))
|
lp.sec("ac2: mark seen {}".format(msg))
|
||||||
msg.mark_seen()
|
msg.mark_seen()
|
||||||
|
|
||||||
for ev in ac1._evtracker.yield_matching(""):
|
for ev in ac1._evtracker.iter_events():
|
||||||
if ev.name == "DC_EVENT_INCOMING_MSG":
|
if ev.name == "DC_EVENT_INCOMING_MSG":
|
||||||
pytest.fail("MDN arrived as regular incoming message")
|
pytest.fail("MDN arrived as regular incoming message")
|
||||||
elif ev.name == "DC_EVENT_MSG_READ":
|
elif ev.name == "DC_EVENT_MSG_READ":
|
||||||
|
|||||||
Reference in New Issue
Block a user