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 ...@@ -5,6 +5,12 @@ import tempfile
import glob import glob
from pipes import quote 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] version = '%s.%s' % sys.version_info[:2]
missing_modules = { missing_modules = {
...@@ -46,7 +52,7 @@ def imp_find_dotted_module(name): ...@@ -46,7 +52,7 @@ def imp_find_dotted_module(name):
return result return result
def _prepare_stdlib_test(filename): def prepare_stdlib_test(filename, assets=None):
patch_all(timeout=20) patch_all(timeout=20)
import test import test
try: try:
...@@ -77,27 +83,25 @@ def _prepare_stdlib_test(filename): ...@@ -77,27 +83,25 @@ def _prepare_stdlib_test(filename):
module_code = compile(module_source, _filename, 'exec') module_code = compile(module_source, _filename, 'exec')
print >> sys.stderr, 'Testing %s with monkey patching' % _filename print >> sys.stderr, 'Testing %s with monkey patching' % _filename
return module_code, _filename
def prepare_stdlib_test(filename): copy_assets(os.path.dirname(_filename), assets)
return _prepare_stdlib_test(filename)[0] os.chdir(chdir)
return module_code
def run(filename, d, assets=None): def copy_assets(source, assets):
module_code, filename = _prepare_stdlib_test(filename)
chdir = os.path.join(tempfile.gettempdir(), 'gevent-test')
try:
os.makedirs(chdir)
except EnvironmentError:
pass
if assets: if assets:
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
cwd = os.getcwd()
os.chdir(directory) os.chdir(directory)
if isinstance(assets, basestring): try:
assets = glob.glob(assets) if isinstance(assets, basestring):
for asset in assets: assets = glob.glob(assets)
os.system('cp -r %s %s' % (quote(asset), quote(os.path.join(chdir, asset)))) 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 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