From 0bfa955f9cc06bf88ff82be7c1ff9bae37636c6a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 19 Sep 2018 12:09:19 +0200 Subject: [PATCH] some better printing, fixing py35 --- python/conftest.py | 14 +++++++++++++- python/src/deltachat/account.py | 7 +++++++ python/src/deltachat/chatting.py | 2 +- python/tests/test_account.py | 20 +++++++++++++------- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/python/conftest.py b/python/conftest.py index 6d39bb3f..0a90376a 100644 --- a/python/conftest.py +++ b/python/conftest.py @@ -1,3 +1,4 @@ +from __future__ import print_function import pytest import re import threading @@ -48,7 +49,7 @@ def acfactory(pytestconfig, tmpdir, request): configdict = self.configlist.pop(0) tmpdb = tmpdir.join("livedb%d" % self.live_count) ac = Account(tmpdb.strpath, logid="ac{}".format(self.live_count)) - ac._evlogger.set_timeout(20) + ac._evlogger.set_timeout(30) ac.set_config(**configdict) if started: ac.start() @@ -61,3 +62,14 @@ def acfactory(pytestconfig, tmpdir, request): @pytest.fixture def tmp_db_path(tmpdir): return tmpdir.join("test.db").strpath + + +@pytest.fixture +def lp(): + class Printer: + def sec(self, msg): + print() + print("=" * 10, msg, "=" * 10) + def step(self, msg): + print("-" * 5, "step " + msg, "-" * 5) + return Printer() diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index aa628894..ed9e7dbc 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -330,6 +330,13 @@ class EventLogger: if rex.match(ev[0]): 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[2]): + return ev + def _log_event(self, evt_name, data1, data2): # don't show events that are anyway empty impls now if evt_name in ("DC_EVENT_GET_STRING", "DC_EVENT_IS_OFFLINE"): diff --git a/python/src/deltachat/chatting.py b/python/src/deltachat/chatting.py index 8f009a64..28d0cfe4 100644 --- a/python/src/deltachat/chatting.py +++ b/python/src/deltachat/chatting.py @@ -77,9 +77,9 @@ class Chat(object): def set_name(self, name): """ set name of this chat. """ + name = as_dc_charpointer(name) return lib.dc_set_chat_name(self._dc_context, self.id, name) - # ------ chat messaging API ------------------------------ def send_text_message(self, msg): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 78321e51..74870e3f 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -158,7 +158,8 @@ class TestOnlineAccount: ac2.delete_messages(messages) assert not chat3.get_messages() - def test_send_and_receive_message(self, acfactory): + def test_send_and_receive_message(self, acfactory, lp): + lp.sec("starting accounts, waiting for configuration") ac1 = acfactory.get_live_account() ac2 = acfactory.get_live_account() c2 = ac1.create_contact(email=ac2.get_config("addr")) @@ -169,6 +170,8 @@ class TestOnlineAccount: self.wait_successful_IMAP_SMTP_connection(ac2) self.wait_configuration_progress(ac1, 1000) self.wait_configuration_progress(ac2, 1000) + + lp.sec("sending text message from ac1 to ac2") msg_out = chat.send_text_message("message1") ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED") evt_name, data1, data2 = ev @@ -176,28 +179,31 @@ class TestOnlineAccount: assert data2 == msg_out.id assert msg_out.get_state().is_out_delivered() - # wait for other account to receive + lp.sec("wait for ac2 to receive message") ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED") assert ev[2] == msg_out.id msg_in = ac2.get_message_by_id(msg_out.id) assert msg_in.text == "message1" - # check the message arrived in contact-requets/deaddrop + lp.sec("check the message arrived in contact-requets/deaddrop") chat2 = msg_in.chat assert msg_in in chat2.get_messages() assert chat2.is_deaddrop() assert chat2.count_fresh_messages() == 0 - # create new chat with contact and verify it's proper + lp.sec("create new chat with contact and verify it's proper") chat2b = ac2.create_chat_by_message(msg_in) assert not chat2b.is_deaddrop() assert chat2b.count_fresh_messages() == 1 - # mark chat as noticed + lp.sec("mark chat as noticed") chat2b.mark_noticed() assert chat2b.count_fresh_messages() == 0 - # mark messages as seen and check ac1 sees the MDN + lp.sec("mark message as seen on ac2, wait for changes on ac1") ac2.mark_seen_messages([msg_in]) - ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED") + lp.step("1") + ac1._evlogger.get_matching("DC_EVENT_MSG_READ") + lp.step("2") + ac1._evlogger.get_info_matching("Message marked as seen") assert msg_out.get_state().is_out_mdn_received()