Add python-eventlet package to MOS 9.0 repository
[packages/trusty/python-eventlet.git] / python-eventlet / tests / __init__.py
index 26c0c2ec5ab49c5102314dcb7991e9dece9b0bf1..0c37cdde7bf45e9155e21fe613c57852ddb66a5a 100644 (file)
@@ -209,6 +209,13 @@ def check_idle_cpu_usage(duration, allowed_part):
     r2 = resource.getrusage(resource.RUSAGE_SELF)
     utime = r2.ru_utime - r1.ru_utime
     stime = r2.ru_stime - r1.ru_stime
+
+    # This check is reliably unreliable on Travis, presumably because of CPU
+    # resources being quite restricted by the build environment. The workaround
+    # is to apply an arbitrary factor that should be enough to make it work nicely.
+    if os.environ.get('TRAVIS') == 'true':
+        allowed_part *= 1.2
+
     assert utime + stime < duration * allowed_part, \
         "CPU usage over limit: user %.0f%% sys %.0f%% allowed %.0f%%" % (
             utime / duration * 100, stime / duration * 100,
@@ -292,15 +299,22 @@ def get_database_auth():
     return retval
 
 
-def run_python(path):
-    if not path.endswith('.py'):
-        path += '.py'
-    path = os.path.abspath(path)
-    src_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+def run_python(path, env=None, args=None):
+    new_argv = [sys.executable]
     new_env = os.environ.copy()
-    new_env['PYTHONPATH'] = os.pathsep.join(sys.path + [src_dir])
+    if path:
+        if not path.endswith('.py'):
+            path += '.py'
+        path = os.path.abspath(path)
+        new_argv.append(path)
+        src_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+        new_env['PYTHONPATH'] = os.pathsep.join(sys.path + [src_dir])
+    if env:
+        new_env.update(env)
+    if args:
+        new_argv.extend(args)
     p = subprocess.Popen(
-        [sys.executable, path],
+        new_argv,
         env=new_env,
         stderr=subprocess.STDOUT,
         stdin=subprocess.PIPE,
@@ -310,15 +324,18 @@ def run_python(path):
     return output
 
 
-def run_isolated(path, prefix='tests/isolated/'):
-    output = run_python(prefix + path).rstrip()
+def run_isolated(path, prefix='tests/isolated/', env=None, args=None):
+    output = run_python(prefix + path, env=env, args=args).rstrip()
     if output.startswith(b'skip'):
         parts = output.split(b':', 1)
         skip_args = []
         if len(parts) > 1:
             skip_args.append(parts[1])
         raise SkipTest(*skip_args)
-    assert output == b'pass', output
+    ok = output == b'pass'
+    if not ok:
+        sys.stderr.write('Isolated test {0} output:\n---\n{1}\n---\n'.format(path, output.decode()))
+    assert ok, 'Expected single line "pass" in stdout'
 
 
 certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')