@@ -222,28 +222,49 @@ def indent(self, msg: str) -> None:
222222#
223223
224224
225+ def find_path (venv , name ):
226+ is_windows = platform .system () == "Windows"
227+ bin = venv / ("bin" if not is_windows else "Scripts" )
228+
229+ tryadd = ["" ]
230+ if is_windows :
231+ tryadd += os .environ ["PATHEXT" ].split (os .pathsep )
232+ for ext in tryadd :
233+ p = bin .joinpath (name + ext )
234+ if p .exists ():
235+ return str (p )
236+
237+ return None
238+
239+
225240@pytest .fixture (scope = "session" )
226241def get_core_python_env (tmp_path_factory ):
227- if platform .system () == "Windows" :
228- pytest .skip ("cross-core-version testing not available on Windows" )
242+ """Return a factory to create virtualenv environments with rpc server/client packages
243+ installed.
244+
245+ The factory takes a version and returns a (python_path, rpc_server_path) tuple
246+ of the respective binaries in the virtualenv.
247+ """
229248
230249 envs = {}
231250
232- def get_core_python (core_version ):
251+ def get_versioned_venv (core_version ):
233252 venv = envs .get (core_version )
234- if venv :
235- return venv
236- venv = tmp_path_factory .mktemp (f"temp-{ core_version } " )
237- python = sys .executable
238- subprocess .check_call ([python , "-m" , "venv" , venv ])
239- pip = venv .joinpath ("bin" , "pip" )
240- pkgs = [f"deltachat-rpc-server=={ core_version } " , f"deltachat-rpc-client=={ core_version } " ]
241- subprocess .check_call ([pip , "install" , "pytest" ] + pkgs )
253+ if not venv :
254+ venv = tmp_path_factory .mktemp (f"temp-{ core_version } " )
255+ subprocess .check_call ([sys .executable , "-m" , "venv" , venv ])
242256
243- envs [core_version ] = venv
244- return venv
257+ python = find_path (venv , "python" )
258+ pkgs = [f"deltachat-rpc-server=={ core_version } " , f"deltachat-rpc-client=={ core_version } " , "pytest" ]
259+ subprocess .check_call ([python , "-m" , "pip" , "install" ] + pkgs )
245260
246- return get_core_python
261+ envs [core_version ] = venv
262+ python = find_path (venv , "python" )
263+ rpc_server_path = find_path (venv , "deltachat-rpc-server" )
264+ print (f"python={ python } \n rpc_server={ rpc_server_path } " )
265+ return python , rpc_server_path
266+
267+ return get_versioned_venv
247268
248269
249270@pytest .fixture
@@ -255,16 +276,15 @@ def alice_and_remote_bob(tmp_path, acfactory, get_core_python_env):
255276 """
256277
257278 def factory (core_version ):
258- venv = get_core_python_env (core_version )
259- python = venv .joinpath ("bin" , "python" )
279+ python , rpc_server_path = get_core_python_env (core_version )
260280 gw = execnet .makegateway (f"popen//python={ python } " )
261281
262282 accounts_dir = str (tmp_path .joinpath ("account1_venv1" ))
263283 channel = gw .remote_exec (remote_bob_loop )
264284 cm = os .environ .get ("CHATMAIL_DOMAIN" )
265285
266286 # trigger getting an online account on bob's side
267- channel .send ((accounts_dir , str (venv . joinpath ( "bin" , "deltachat-rpc-server" ) ), cm ))
287+ channel .send ((accounts_dir , str (rpc_server_path ), cm ))
268288
269289 # meanwhile get a local alice account
270290 alice = acfactory .get_online_account ()
@@ -287,17 +307,19 @@ def eval(eval_str):
287307
288308def remote_bob_loop (channel ):
289309 import os
290- import pathlib
291310
292311 from deltachat_rpc_client import DeltaChat , Rpc
293312 from deltachat_rpc_client .pytestplugin import ACFactory
294313
295314 accounts_dir , rpc_server_path , chatmail_domain = channel .receive ()
296315 os .environ ["CHATMAIL_DOMAIN" ] = chatmail_domain
297- bin_path = str (pathlib .Path (rpc_server_path ).parent )
298- os .environ ["PATH" ] = bin_path + ":" + os .environ ["PATH" ]
299316
317+ # older core versions don't support specifying rpc_server_path
318+ # so we can't just pass `rpc_server_path` argument to Rpc constructor
319+ basepath = os .path .dirname (rpc_server_path )
320+ os .environ ["PATH" ] = os .pathsep .join ([basepath , os .environ ["PATH" ]])
300321 rpc = Rpc (accounts_dir = accounts_dir )
322+
301323 with rpc :
302324 dc = DeltaChat (rpc )
303325 channel .send (dc .rpc .get_system_info ()["deltachat_core_version" ])
0 commit comments