[Jython-checkins] jython (merge default -> default): Merge trunk

frank.wierzbicki jython-checkins at python.org
Wed Mar 14 04:09:29 CET 2012


http://hg.python.org/jython/rev/8c4ff6487a0d
changeset:   6331:8c4ff6487a0d
parent:      6330:46f79d2ef0dd
parent:      6327:728b704d3f9f
user:        Jim Baker <jbaker at zyasoft.com>
date:        Mon Mar 12 15:49:25 2012 -0700
summary:
  Merge trunk

files:
  Lib/test/test_support.py |  52 ++++++++++++++++++++++++++++
  1 files changed, 52 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -8,6 +8,7 @@
 import socket
 import sys
 import os
+import platform
 import shutil
 import warnings
 import unittest
@@ -907,6 +908,57 @@
         return result
 
 
+def _id(obj):
+    return obj
+
+def requires_resource(resource):
+    if is_resource_enabled(resource):
+        return _id
+    else:
+        return unittest.skip("resource {0!r} is not enabled".format(resource))
+
+def cpython_only(test):
+    """
+    Decorator for tests only applicable on CPython.
+    """
+    return impl_detail(cpython=True)(test)
+
+def impl_detail(msg=None, **guards):
+    if check_impl_detail(**guards):
+        return _id
+    if msg is None:
+        guardnames, default = _parse_guards(guards)
+        if default:
+            msg = "implementation detail not available on {0}"
+        else:
+            msg = "implementation detail specific to {0}"
+        guardnames = sorted(guardnames.keys())
+        msg = msg.format(' or '.join(guardnames))
+    return unittest.skip(msg)
+
+def _parse_guards(guards):
+    # Returns a tuple ({platform_name: run_me}, default_value)
+    if not guards:
+        return ({'cpython': True}, False)
+    is_true = guards.values()[0]
+    assert guards.values() == [is_true] * len(guards)   # all True or all False
+    return (guards, not is_true)
+
+# Use the following check to guard CPython's implementation-specific tests --
+# or to run them only on the implementation(s) guarded by the arguments.
+def check_impl_detail(**guards):
+    """This function returns True or False depending on the host platform.
+       Examples:
+          if check_impl_detail():               # only on CPython (default)
+          if check_impl_detail(jython=True):    # only on Jython
+          if check_impl_detail(cpython=False):  # everywhere except on CPython
+    """
+    guards, default = _parse_guards(guards)
+    return guards.get(platform.python_implementation().lower(), default)
+
+
+
+
 def _run_suite(suite):
     """Run tests from a unittest.TestSuite-derived class."""
     if not junit_xml_dir:

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list