mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +02:00
better modularize functionality and use it from tests
This commit is contained in:
parent
1ff06c071b
commit
55b05be6af
4 changed files with 152 additions and 121 deletions
|
@ -1,20 +1,6 @@
|
|||
import pytest
|
||||
|
||||
import deltachat
|
||||
from deltachat import capi
|
||||
import threading
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def register_dc_callback(monkeypatch):
|
||||
"""Register a callback for a given context.
|
||||
|
||||
This is a function-scoped fixture and the function will be
|
||||
unregisterd automatically on fixture teardown.
|
||||
"""
|
||||
def register_dc_callback(ctx, func):
|
||||
monkeypatch.setitem(deltachat._DC_CALLBACK_MAP, ctx, func)
|
||||
return register_dc_callback
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
|
@ -32,39 +18,6 @@ def userpassword(pytestconfig):
|
|||
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()
|
||||
|
||||
def tmp_db_path(tmpdir):
|
||||
return tmpdir.join("test.db").strpath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue