mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
test(rpc-client): Replace remaining print()s with logging (#6082)
This is to fix tests failing with `OSError: [Errno 9] Bad file descriptor`. Maybe stdout closes
earlier than stderr, before the test finishes, not sure. For reference, the previous commit removing
print()s is 800edc6fce.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
@@ -204,14 +205,13 @@ def log():
|
|||||||
|
|
||||||
class Printer:
|
class Printer:
|
||||||
def section(self, msg: str) -> None:
|
def section(self, msg: str) -> None:
|
||||||
print()
|
logging.info("\n%s %s %s", "=" * 10, msg, "=" * 10)
|
||||||
print("=" * 10, msg, "=" * 10)
|
|
||||||
|
|
||||||
def step(self, msg: str) -> None:
|
def step(self, msg: str) -> None:
|
||||||
print("-" * 5, "step " + msg, "-" * 5)
|
logging.info("%s step %s %s", "-" * 5, msg, "-" * 5)
|
||||||
|
|
||||||
def indent(self, msg: str) -> None:
|
def indent(self, msg: str) -> None:
|
||||||
print(" " + msg)
|
logging.info(" " + msg)
|
||||||
|
|
||||||
return Printer()
|
return Printer()
|
||||||
|
|
||||||
@@ -261,7 +261,7 @@ def get_core_python_env(tmp_path_factory):
|
|||||||
envs[core_version] = venv
|
envs[core_version] = venv
|
||||||
python = find_path(venv, "python")
|
python = find_path(venv, "python")
|
||||||
rpc_server_path = find_path(venv, "deltachat-rpc-server")
|
rpc_server_path = find_path(venv, "deltachat-rpc-server")
|
||||||
print(f"python={python}\nrpc_server={rpc_server_path}")
|
logging.info(f"Paths:\npython={python}\nrpc_server={rpc_server_path}")
|
||||||
return python, rpc_server_path
|
return python, rpc_server_path
|
||||||
|
|
||||||
return get_versioned_venv
|
return get_versioned_venv
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import imaplib
|
import imaplib
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import ssl
|
import ssl
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
@@ -45,13 +46,13 @@ class DirectImap:
|
|||||||
try:
|
try:
|
||||||
self.conn.logout()
|
self.conn.logout()
|
||||||
except (OSError, imaplib.IMAP4.abort):
|
except (OSError, imaplib.IMAP4.abort):
|
||||||
print("Could not logout direct_imap conn")
|
logging.warning("Could not logout direct_imap conn")
|
||||||
|
|
||||||
def create_folder(self, foldername):
|
def create_folder(self, foldername):
|
||||||
try:
|
try:
|
||||||
self.conn.folder.create(foldername)
|
self.conn.folder.create(foldername)
|
||||||
except errors.MailboxFolderCreateError as e:
|
except errors.MailboxFolderCreateError as e:
|
||||||
print("Can't create", foldername, "probably it already exists:", str(e))
|
logging.warning(f"Cannot create '{foldername}', probably it already exists: {str(e)}")
|
||||||
|
|
||||||
def select_folder(self, foldername: str) -> tuple:
|
def select_folder(self, foldername: str) -> tuple:
|
||||||
assert not self._idling
|
assert not self._idling
|
||||||
@@ -95,7 +96,7 @@ class DirectImap:
|
|||||||
messages = self.get_unread_messages()
|
messages = self.get_unread_messages()
|
||||||
if messages:
|
if messages:
|
||||||
res = self.conn.flag(messages, MailMessageFlags.SEEN, True)
|
res = self.conn.flag(messages, MailMessageFlags.SEEN, True)
|
||||||
print("marked seen:", messages, res)
|
logging.info(f"Marked seen: {messages} {res}")
|
||||||
|
|
||||||
def get_unread_cnt(self) -> int:
|
def get_unread_cnt(self) -> int:
|
||||||
return len(self.get_unread_messages())
|
return len(self.get_unread_messages())
|
||||||
|
|||||||
@@ -370,13 +370,13 @@ def test_selfavatar_sync(acfactory, data, log) -> None:
|
|||||||
alice.set_config("selfavatar", image)
|
alice.set_config("selfavatar", image)
|
||||||
avatar_config = alice.get_config("selfavatar")
|
avatar_config = alice.get_config("selfavatar")
|
||||||
avatar_hash = os.path.basename(avatar_config)
|
avatar_hash = os.path.basename(avatar_config)
|
||||||
print("Info: avatar hash is ", avatar_hash)
|
logging.info(f"Avatar hash is {avatar_hash}")
|
||||||
|
|
||||||
log.section("First device receives avatar change")
|
log.section("First device receives avatar change")
|
||||||
alice2.wait_for_event(EventType.SELFAVATAR_CHANGED)
|
alice2.wait_for_event(EventType.SELFAVATAR_CHANGED)
|
||||||
avatar_config2 = alice2.get_config("selfavatar")
|
avatar_config2 = alice2.get_config("selfavatar")
|
||||||
avatar_hash2 = os.path.basename(avatar_config2)
|
avatar_hash2 = os.path.basename(avatar_config2)
|
||||||
print("Info: avatar hash on second device is ", avatar_hash2)
|
logging.info(f"Avatar hash on second device is {avatar_hash2}")
|
||||||
assert avatar_hash == avatar_hash2
|
assert avatar_hash == avatar_hash2
|
||||||
assert avatar_config != avatar_config2
|
assert avatar_config != avatar_config2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user