1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 10:19:16 +02:00

some initial test code, also fixing callback machinery to actually call the callback (thanks flub for the hint), also test file rename

This commit is contained in:
holger krekel 2018-09-04 15:38:18 +02:00
parent 9967b2127a
commit eec2261cca
4 changed files with 100 additions and 18 deletions

View file

@ -1,6 +1,8 @@
import pytest
import deltachat
from deltachat import capi
import threading
@pytest.fixture
@ -13,3 +15,56 @@ def register_dc_callback(monkeypatch):
def register_dc_callback(ctx, func):
monkeypatch.setitem(deltachat._DC_CALLBACK_MAP, ctx, func)
return register_dc_callback
def pytest_addoption(parser):
parser.addoption("--user", action="store", default=None,
help="user and domain of test account: example user@example.org")
parser.addoption("--password", action="store", default=None)
@pytest.fixture
def userpassword(pytestconfig):
user = pytestconfig.getoption("--user")
passwd = pytestconfig.getoption("--password")
if user and passwd:
return user, passwd
pytest.skip("specify a test account with --user and --password options")
def imap_thread(context, quitflag):
print ("starting imap thread")
while not quitflag.is_set():
capi.lib.dc_perform_imap_jobs(context)
capi.lib.dc_perform_imap_fetch(context)
capi.lib.dc_perform_imap_idle(context)
def smtp_thread(context, quitflag):
print ("starting smtp thread")
while not quitflag.is_set():
capi.lib.dc_perform_smtp_jobs(context)
capi.lib.dc_perform_smtp_idle(context)
@pytest.fixture
def dc_context():
ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback,
capi.ffi.NULL, capi.ffi.NULL)
yield ctx
capi.lib.dc_close(ctx)
@pytest.fixture
def dc_threads(dc_context):
quitflag = threading.Event()
t1 = threading.Thread(target=imap_thread, name="imap", args=[dc_context, quitflag])
t1.setDaemon(1)
t1.start()
t2 = threading.Thread(target=smtp_thread, name="smtp", args=[dc_context, quitflag])
t2.setDaemon(1)
t2.start()
yield
quitflag.set()