diff --git a/python/doc/api.rst b/python/doc/api.rst index 049bc2928..f19306391 100644 --- a/python/doc/api.rst +++ b/python/doc/api.rst @@ -2,34 +2,34 @@ high level API reference ======================== -- :class:`deltachat.account.Account` (your main entry point, creates the +- :class:`deltachat.Account` (your main entry point, creates the other classes) -- :class:`deltachat.contact.Contact` -- :class:`deltachat.chat.Chat` -- :class:`deltachat.message.Message` +- :class:`deltachat.Contact` +- :class:`deltachat.Chat` +- :class:`deltachat.Message` Account ------- -.. autoclass:: deltachat.account.Account +.. autoclass:: deltachat.Account :members: Contact ------- -.. autoclass:: deltachat.contact.Contact +.. autoclass:: deltachat.Contact :members: Chat ---- -.. autoclass:: deltachat.chat.Chat +.. autoclass:: deltachat.Chat :members: Message ------- -.. autoclass:: deltachat.message.Message +.. autoclass:: deltachat.Message :members: diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 6d067f4fb..8272dc965 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -6,7 +6,7 @@ from array import array from contextlib import contextmanager from email.utils import parseaddr from threading import Event -from typing import Any, Dict, Generator, List, Optional, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, Union from . import const, hookspec from .capi import ffi, lib diff --git a/python/src/deltachat/events.py b/python/src/deltachat/events.py index 0ae86a9ad..4c4ec5119 100644 --- a/python/src/deltachat/events.py +++ b/python/src/deltachat/events.py @@ -9,11 +9,11 @@ from contextlib import contextmanager from queue import Empty, Queue from . import const +from .account import Account from .capi import ffi, lib from .cutil import from_optional_dc_charpointer from .hookspec import account_hookimpl from .message import map_system_message -from .account import Account def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}): diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index 6ac62f43b..3dee022bf 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -9,7 +9,7 @@ import threading import time import weakref from queue import Queue -from typing import Callable, List, Optional, Dict, Set +from typing import Callable, Dict, List, Optional, Set import pytest import requests diff --git a/python/src/deltachat/tracker.py b/python/src/deltachat/tracker.py index f8fbc3f8f..1fa88044c 100644 --- a/python/src/deltachat/tracker.py +++ b/python/src/deltachat/tracker.py @@ -1,6 +1,6 @@ from queue import Queue from threading import Event -from typing import List, TYPE_CHECKING +from typing import TYPE_CHECKING, List from .hookspec import Global, account_hookimpl diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index b412b1d45..10fbb77dd 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -7,9 +7,8 @@ from datetime import datetime, timezone import pytest from imap_tools import AND, U -from deltachat import const -from deltachat.hookspec import account_hookimpl -from deltachat.message import Message +import deltachat as dc +from deltachat import account_hookimpl, Message from deltachat.tracker import ImexTracker @@ -36,8 +35,8 @@ def test_basic_imap_api(acfactory, tmp_path): def test_configure_generate_key(acfactory, lp): # A slow test which will generate new keys. acfactory.remove_preconfigured_keys() - ac1 = acfactory.new_online_configuring_account(key_gen_type=str(const.DC_KEY_GEN_RSA2048)) - ac2 = acfactory.new_online_configuring_account(key_gen_type=str(const.DC_KEY_GEN_ED25519)) + ac1 = acfactory.new_online_configuring_account(key_gen_type=str(dc.const.DC_KEY_GEN_RSA2048)) + ac2 = acfactory.new_online_configuring_account(key_gen_type=str(dc.const.DC_KEY_GEN_ED25519)) acfactory.bring_accounts_online() chat = acfactory.get_accepted_chat(ac1, ac2) @@ -175,7 +174,7 @@ def test_send_file_twice_unicode_filename_mangling(tmp_path, acfactory, lp): lp.sec("ac2: receive message") ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG") - assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL + assert ev.data2 > dc.const.DC_CHAT_ID_LAST_SPECIAL return ac2.get_message_by_id(ev.data2) msg = send_and_receive_message() @@ -207,7 +206,7 @@ def test_send_file_html_attachment(tmp_path, acfactory, lp): lp.sec("ac2: receive message") ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG") - assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL + assert ev.data2 > dc.const.DC_CHAT_ID_LAST_SPECIAL msg = ac2.get_message_by_id(ev.data2) assert open(msg.filename).read() == content @@ -351,7 +350,7 @@ def test_move_works(acfactory): # Message is downloaded ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG") - assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL + assert ev.data2 > dc.const.DC_CHAT_ID_LAST_SPECIAL def test_move_works_on_self_sent(acfactory): @@ -534,8 +533,8 @@ def test_send_and_receive_message_markseen(acfactory, lp): lp.step("1") for _i in range(2): ev = ac1._evtracker.get_matching("DC_EVENT_MSG_READ") - assert ev.data1 > const.DC_CHAT_ID_LAST_SPECIAL - assert ev.data2 > const.DC_MSG_ID_LAST_SPECIAL + assert ev.data1 > dc.const.DC_CHAT_ID_LAST_SPECIAL + assert ev.data2 > dc.const.DC_MSG_ID_LAST_SPECIAL lp.step("2") # Check that ac1 marks the read receipt as read. @@ -1386,7 +1385,7 @@ def test_reaction_to_partially_fetched_msg(acfactory, lp, tmp_path): lp.sec("wait for ac2 to receive a reaction") msg2 = ac2._evtracker.wait_next_reactions_changed() assert msg2.get_sender_contact().addr == ac1_addr - assert msg2.download_state == const.DC_DOWNLOAD_AVAILABLE + assert msg2.download_state == dc.const.DC_DOWNLOAD_AVAILABLE assert reactions_queue.get() == msg2 reactions = msg2.get_reactions() contacts = reactions.get_contacts() @@ -1471,7 +1470,7 @@ def test_import_export_online_all(acfactory, tmp_path, data, lp): lp.sec(f"export all to {backupdir}") with ac1.temp_plugin(ImexTracker()) as imex_tracker: ac1.stop_io() - ac1.imex(str(backupdir), const.DC_IMEX_EXPORT_BACKUP) + ac1.imex(str(backupdir), dc.const.DC_IMEX_EXPORT_BACKUP) # check progress events for export assert imex_tracker.wait_progress(1, progress_upper_limit=249) @@ -1835,15 +1834,15 @@ def test_connectivity(acfactory, lp): ac1, ac2 = acfactory.get_online_accounts(2) ac1.set_config("scan_all_folders_debounce_secs", "0") - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_CONNECTED) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_CONNECTED) lp.sec("Test stop_io() and start_io()") ac1.stop_io() - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_NOT_CONNECTED) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_NOT_CONNECTED) ac1.start_io() - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_CONNECTING) - ac1._evtracker.wait_for_connectivity_change(const.DC_CONNECTIVITY_CONNECTING, const.DC_CONNECTIVITY_CONNECTED) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_CONNECTING) + ac1._evtracker.wait_for_connectivity_change(dc.const.DC_CONNECTIVITY_CONNECTING, dc.const.DC_CONNECTIVITY_CONNECTED) lp.sec( "Test that after calling start_io(), maybe_network() and waiting for `all_work_done()`, " @@ -1864,8 +1863,8 @@ def test_connectivity(acfactory, lp): ac2.create_chat(ac1).send_text("Hi 2") - ac1._evtracker.wait_for_connectivity_change(const.DC_CONNECTIVITY_CONNECTED, const.DC_CONNECTIVITY_WORKING) - ac1._evtracker.wait_for_connectivity_change(const.DC_CONNECTIVITY_WORKING, const.DC_CONNECTIVITY_CONNECTED) + ac1._evtracker.wait_for_connectivity_change(dc.const.DC_CONNECTIVITY_CONNECTED, dc.const.DC_CONNECTIVITY_WORKING) + ac1._evtracker.wait_for_connectivity_change(dc.const.DC_CONNECTIVITY_WORKING, dc.const.DC_CONNECTIVITY_CONNECTED) msgs = ac1.create_chat(ac2).get_messages() assert len(msgs) == 2 @@ -1875,7 +1874,7 @@ def test_connectivity(acfactory, lp): ac1.maybe_network() while 1: - assert ac1.get_connectivity() == const.DC_CONNECTIVITY_CONNECTED + assert ac1.get_connectivity() == dc.const.DC_CONNECTIVITY_CONNECTED if ac1.all_work_done(): break ac1._evtracker.get_matching("DC_EVENT_CONNECTIVITY_CHANGED") @@ -1890,7 +1889,7 @@ def test_connectivity(acfactory, lp): ac1.maybe_network() while 1: - assert ac1.get_connectivity() == const.DC_CONNECTIVITY_CONNECTED + assert ac1.get_connectivity() == dc.const.DC_CONNECTIVITY_CONNECTED if ac1.all_work_done(): break ac1._evtracker.get_matching("DC_EVENT_CONNECTIVITY_CHANGED") @@ -1899,10 +1898,10 @@ def test_connectivity(acfactory, lp): ac1.set_config("configured_mail_pw", "abc") ac1.stop_io() - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_NOT_CONNECTED) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_NOT_CONNECTED) ac1.start_io() - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_CONNECTING) - ac1._evtracker.wait_for_connectivity(const.DC_CONNECTIVITY_NOT_CONNECTED) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_CONNECTING) + ac1._evtracker.wait_for_connectivity(dc.const.DC_CONNECTIVITY_NOT_CONNECTED) def test_fetch_deleted_msg(acfactory, lp): @@ -2385,9 +2384,9 @@ def test_archived_muted_chat(acfactory, lp): lp.sec("wait for ac2 to receive DC_EVENT_MSGS_CHANGED for DC_CHAT_ID_ARCHIVED_LINK") while 1: ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED") - if ev.data1 == const.DC_CHAT_ID_ARCHIVED_LINK: + if ev.data1 == dc.const.DC_CHAT_ID_ARCHIVED_LINK: assert ev.data2 == 0 - archive = ac2.get_chat_by_id(const.DC_CHAT_ID_ARCHIVED_LINK) + archive = ac2.get_chat_by_id(dc.const.DC_CHAT_ID_ARCHIVED_LINK) assert archive.count_fresh_messages() == 1 assert chat2.count_fresh_messages() == 1 break diff --git a/python/tests/test_3_offline.py b/python/tests/test_3_offline.py index f498fc8de..ad30b7f55 100644 --- a/python/tests/test_3_offline.py +++ b/python/tests/test_3_offline.py @@ -4,12 +4,11 @@ from datetime import datetime, timedelta, timezone import pytest -from deltachat import Account, const +import deltachat as dc from deltachat.capi import ffi, lib from deltachat.cutil import iter_array -from deltachat.hookspec import account_hookimpl -from deltachat.message import Message from deltachat.tracker import ImexFailed +from deltachat import Account, account_hookimpl, Message @pytest.mark.parametrize( @@ -299,13 +298,13 @@ class TestOfflineChat: assert not d["draft"] if chat.get_draft() is None else chat.get_draft() def test_group_chat_creation_with_translation(self, ac1): - ac1.set_stock_translation(const.DC_STR_GROUP_NAME_CHANGED_BY_YOU, "abc %1$s xyz %2$s") + ac1.set_stock_translation(dc.const.DC_STR_GROUP_NAME_CHANGED_BY_YOU, "abc %1$s xyz %2$s") ac1._evtracker.consume_events() with pytest.raises(ValueError): - ac1.set_stock_translation(const.DC_STR_FILE, "xyz %1$s") + ac1.set_stock_translation(dc.const.DC_STR_FILE, "xyz %1$s") ac1._evtracker.get_matching("DC_EVENT_WARNING") with pytest.raises(ValueError): - ac1.set_stock_translation(const.DC_STR_CONTACT_NOT_VERIFIED, "xyz %2$s") + ac1.set_stock_translation(dc.const.DC_STR_CONTACT_NOT_VERIFIED, "xyz %2$s") ac1._evtracker.get_matching("DC_EVENT_WARNING") with pytest.raises(ValueError): ac1.set_stock_translation(500, "xyz %1$s") @@ -818,7 +817,7 @@ class TestOfflineChat: lp.sec("check message count of only system messages (without daymarkers)") dc_array = ffi.gc( - lib.dc_get_chat_msgs(ac1._dc_context, chat.id, const.DC_GCM_INFO_ONLY, 0), + lib.dc_get_chat_msgs(ac1._dc_context, chat.id, dc.const.DC_GCM_INFO_ONLY, 0), lib.dc_array_unref, ) assert len(list(iter_array(dc_array, lambda x: x))) == 2 diff --git a/python/tests/test_4_lowlevel.py b/python/tests/test_4_lowlevel.py index ac7ce1f12..1fd961bca 100644 --- a/python/tests/test_4_lowlevel.py +++ b/python/tests/test_4_lowlevel.py @@ -1,6 +1,7 @@ from queue import Queue -from deltachat import capi, const, cutil, register_global_plugin +import deltachat as dc +from deltachat import capi, cutil, register_global_plugin from deltachat.capi import ffi, lib from deltachat.hookspec import global_hookimpl from deltachat.testplugin import ( @@ -132,20 +133,20 @@ def test_empty_blobdir(tmp_path): def test_event_defines(): - assert const.DC_EVENT_INFO == 100 - assert const.DC_CONTACT_ID_SELF + assert dc.const.DC_EVENT_INFO == 100 + assert dc.const.DC_CONTACT_ID_SELF def test_sig(): sig = capi.lib.dc_event_has_string_data - assert not sig(const.DC_EVENT_MSGS_CHANGED) - assert sig(const.DC_EVENT_INFO) - assert sig(const.DC_EVENT_WARNING) - assert sig(const.DC_EVENT_ERROR) - assert sig(const.DC_EVENT_SMTP_CONNECTED) - assert sig(const.DC_EVENT_IMAP_CONNECTED) - assert sig(const.DC_EVENT_SMTP_MESSAGE_SENT) - assert sig(const.DC_EVENT_IMEX_FILE_WRITTEN) + assert not sig(dc.const.DC_EVENT_MSGS_CHANGED) + assert sig(dc.const.DC_EVENT_INFO) + assert sig(dc.const.DC_EVENT_WARNING) + assert sig(dc.const.DC_EVENT_ERROR) + assert sig(dc.const.DC_EVENT_SMTP_CONNECTED) + assert sig(dc.const.DC_EVENT_IMAP_CONNECTED) + assert sig(dc.const.DC_EVENT_SMTP_MESSAGE_SENT) + assert sig(dc.const.DC_EVENT_IMEX_FILE_WRITTEN) def test_markseen_invalid_message_ids(acfactory):