Commit a297a4d2 authored by Denis Bilenko's avatar Denis Bilenko

restore test_patched_threading.py; update helper.py

parent ff21e5ab
......@@ -5,6 +5,12 @@ import tempfile
import glob
from pipes import quote
chdir = os.path.join(tempfile.gettempdir(), 'gevent-test')
try:
os.makedirs(chdir)
except EnvironmentError:
pass
version = '%s.%s' % sys.version_info[:2]
missing_modules = {
......@@ -46,7 +52,7 @@ def imp_find_dotted_module(name):
return result
def _prepare_stdlib_test(filename):
def prepare_stdlib_test(filename, assets=None):
patch_all(timeout=20)
import test
try:
......@@ -77,27 +83,25 @@ def _prepare_stdlib_test(filename):
module_code = compile(module_source, _filename, 'exec')
print >> sys.stderr, 'Testing %s with monkey patching' % _filename
return module_code, _filename
def prepare_stdlib_test(filename):
return _prepare_stdlib_test(filename)[0]
copy_assets(os.path.dirname(_filename), assets)
os.chdir(chdir)
return module_code
def run(filename, d, assets=None):
module_code, filename = _prepare_stdlib_test(filename)
chdir = os.path.join(tempfile.gettempdir(), 'gevent-test')
try:
os.makedirs(chdir)
except EnvironmentError:
pass
def copy_assets(source, assets):
if assets:
directory = os.path.dirname(filename)
cwd = os.getcwd()
os.chdir(directory)
if isinstance(assets, basestring):
assets = glob.glob(assets)
for asset in assets:
os.system('cp -r %s %s' % (quote(asset), quote(os.path.join(chdir, asset))))
try:
if isinstance(assets, basestring):
assets = glob.glob(assets)
for asset in assets:
os.system('cp -r %s %s' % (quote(asset), quote(os.path.join(chdir, asset))))
finally:
os.chdir(cwd)
os.chdir(chdir)
exec module_code in d
def run(filename, d, assets=None):
exec prepare_stdlib_test(filename) in d
import helper
helper.run(__file__, globals())
module = helper.prepare_stdlib_test(__file__)
import sys
import subprocess
from subprocess import Popen as _Popen
monkey_patch = 'from gevent import monkey; monkey.patch_all()\n\n'
class MyPopen(_Popen):
def __init__(self, arg, *args, **kwargs):
if arg[:2] == [sys.executable, '-c']:
assert len(arg) == 3, arg
arg = arg[:2] + [monkey_patch + arg[2]]
_Popen.__init__(self, arg, *args, **kwargs)
subprocess.Popen = MyPopen
exec module in globals()
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