Commit 989c7105 authored by Kirill Smelkov's avatar Kirill Smelkov

Y wcfs: tests: Teach tSubProcess to run function from any module

We will soon need to use tSubProcess not only for tests and so will move
it out to another place. It will need to be able to run functions from
both wcfs/wcfs_faultyprot_test.py and from other modules. Prepare to
that.
parent 5571e203
......@@ -25,7 +25,7 @@ from __future__ import print_function, absolute_import
from wendelin.lib.zodb import zstor_2zurl
from wendelin import wcfs
import sys, os, subprocess, traceback
import sys, os, subprocess, traceback, importlib
import six
from golang import select, func, defer
from golang import context, sync, time
......@@ -68,7 +68,7 @@ def with_prompt_pintimeout(monkeypatch):
class tSubProcess(object):
def __init__(proc, f, *argv, **kw):
exev = [sys.executable, '-c', 'from wendelin.wcfs import wcfs_faultyprot_test as t; '
't.tSubProcess._start(%r)' % f.__name__]
't.tSubProcess._start(%r)' % '%s.%s' % (f.__module__, f.__name__)]
proc.popen = subprocess.Popen(exev, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
try:
proc.cin = MPConnection(os.dup(proc.popen.stdin.fileno()), readable=False)
......@@ -83,15 +83,17 @@ class tSubProcess(object):
# _start is trampoline ran in the subprocess to launch to user function.
@staticmethod
def _start(funcname):
def _start(funcpath):
cin = MPConnection(os.dup(sys.stdin.fileno()), writable=False)
cout = MPConnection(os.dup(sys.stdout.fileno()), readable=False)
sys.stdin = open(os.devnull, 'r') # XXX better dup2 ?
sys.stdout = open(os.devnull, 'w')
argv = cin.recv()
kw = cin.recv()
f = globals()[funcname]
procname = kw.pop('_procname', f.__name__)
modname, funcname = funcpath.rsplit('.', 1)
mod = importlib.import_module(modname)
f = getattr(mod, funcname)
procname = kw.pop('_procname', funcpath)
try:
f(cin, cout, *argv, **kw)
_ = 'END'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment