mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
cache virtualevns with core versions
This commit is contained in:
@@ -4,8 +4,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator, Optional
|
||||||
|
|
||||||
|
import execnet
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -205,37 +208,54 @@ def log():
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(scope="session")
|
||||||
def alice_and_remote_bob(tmp_path, acfactory):
|
def get_core_python_env(tmp_path_factory):
|
||||||
"""return local Alice account, and a remote 'eval' function.
|
envs = {}
|
||||||
|
|
||||||
The 'eval' function allows to remote-execute arbitrary expressions
|
def get_core_python(core_version):
|
||||||
that can use the `bob` online account, and the `alice_contact`.
|
venv = envs.get(core_version)
|
||||||
"""
|
if venv:
|
||||||
import subprocess
|
return venv
|
||||||
import sys
|
venv = tmp_path_factory.mktemp(f"temp-{core_version}")
|
||||||
|
|
||||||
import execnet
|
|
||||||
|
|
||||||
def factory(v):
|
|
||||||
alice = acfactory.get_online_account()
|
|
||||||
|
|
||||||
venv = tmp_path.joinpath("venv1")
|
|
||||||
python = sys.executable
|
python = sys.executable
|
||||||
subprocess.check_call([python, "-m", "venv", venv])
|
subprocess.check_call([python, "-m", "venv", venv])
|
||||||
pip = venv.joinpath("bin", "pip")
|
pip = venv.joinpath("bin", "pip")
|
||||||
subprocess.check_call([pip, "install", "pytest", f"deltachat-rpc-server=={v}", f"deltachat-rpc-client=={v}"])
|
pkgs = [f"deltachat-rpc-server=={core_version}", f"deltachat-rpc-client=={core_version}"]
|
||||||
|
subprocess.check_call([pip, "install", "pytest"] + pkgs)
|
||||||
|
|
||||||
|
envs[core_version] = venv
|
||||||
|
return venv
|
||||||
|
|
||||||
|
return get_core_python
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def alice_and_remote_bob(tmp_path, acfactory, get_core_python_env):
|
||||||
|
"""return local Alice account, a contact to bob, and a remote 'eval' function for bob.
|
||||||
|
|
||||||
|
The 'eval' function allows to remote-execute arbitrary expressions
|
||||||
|
that can use the `bob` online account, and the `bob_contact_alice`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def factory(core_version):
|
||||||
|
venv = get_core_python_env(core_version)
|
||||||
python = venv.joinpath("bin", "python")
|
python = venv.joinpath("bin", "python")
|
||||||
gw = execnet.makegateway(f"popen//python={python}")
|
gw = execnet.makegateway(f"popen//python={python}")
|
||||||
|
|
||||||
accounts_dir = str(tmp_path.joinpath("account1_venv1"))
|
accounts_dir = str(tmp_path.joinpath("account1_venv1"))
|
||||||
channel = gw.remote_exec(v220_loop)
|
channel = gw.remote_exec(remote_bob_loop)
|
||||||
cm = os.environ.get("CHATMAIL_DOMAIN")
|
cm = os.environ.get("CHATMAIL_DOMAIN")
|
||||||
|
|
||||||
|
# trigger getting an online account on bob's side
|
||||||
channel.send((accounts_dir, str(venv.joinpath("bin", "deltachat-rpc-server")), cm))
|
channel.send((accounts_dir, str(venv.joinpath("bin", "deltachat-rpc-server")), cm))
|
||||||
sysinfo = channel.receive()
|
|
||||||
assert sysinfo == f"v{v}"
|
# meanwhile get a local alice account
|
||||||
|
alice = acfactory.get_online_account()
|
||||||
channel.send(alice.self_contact.make_vcard())
|
channel.send(alice.self_contact.make_vcard())
|
||||||
|
|
||||||
|
# wait for bob to have started
|
||||||
|
sysinfo = channel.receive()
|
||||||
|
assert sysinfo == f"v{core_version}"
|
||||||
bob_vcard = channel.receive()
|
bob_vcard = channel.receive()
|
||||||
[alice_contact_bob] = alice.import_vcard(bob_vcard)
|
[alice_contact_bob] = alice.import_vcard(bob_vcard)
|
||||||
|
|
||||||
@@ -248,7 +268,7 @@ def alice_and_remote_bob(tmp_path, acfactory):
|
|||||||
return factory
|
return factory
|
||||||
|
|
||||||
|
|
||||||
def v220_loop(channel):
|
def remote_bob_loop(channel):
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
def test_qr_setup_contact(alice_and_remote_bob) -> None:
|
import pytest
|
||||||
alice, alice_contact_bob, remote_eval = alice_and_remote_bob("2.20.0")
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("version", ["2.20.0", "2.10.0"])
|
||||||
|
def test_qr_setup_contact(alice_and_remote_bob, version) -> None:
|
||||||
|
alice, alice_contact_bob, remote_eval = alice_and_remote_bob(version)
|
||||||
|
|
||||||
qr_code = alice.get_qr_code()
|
qr_code = alice.get_qr_code()
|
||||||
remote_eval(f"bob.secure_join({qr_code!r})")
|
remote_eval(f"bob.secure_join({qr_code!r})")
|
||||||
|
|||||||
Reference in New Issue
Block a user