churchyard / rpms / python2

Forked from rpms/python2 3 years ago
Clone
866e92
diff -up Python-2.7.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest Python-2.7.2/Lib/unittest/case.py
866e92
--- Python-2.7.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest	2011-09-08 14:45:47.677169191 -0400
866e92
+++ Python-2.7.2/Lib/unittest/case.py	2011-09-08 16:01:36.287858159 -0400
866e92
@@ -1,6 +1,7 @@
866e92
 """Test case implementation"""
866e92
 
866e92
 import collections
866e92
+import os
866e92
 import sys
866e92
 import functools
866e92
 import difflib
866e92
@@ -94,6 +95,43 @@ def expectedFailure(func):
866e92
     return wrapper
866e92
 
866e92
 
866e92
+# Non-standard/downstream-only hooks for handling issues with specific test
866e92
+# cases:
866e92
+
866e92
+def _skipInRpmBuild(reason):
866e92
+    """
866e92
+    Non-standard/downstream-only decorator for marking a specific unit test
866e92
+    to be skipped when run within the %check of an rpmbuild.
866e92
+
866e92
+    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
866e92
+    the environment, and has no effect otherwise.
866e92
+    """
866e92
+    if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
866e92
+        return skip(reason)
866e92
+    else:
866e92
+        return _id
866e92
+
866e92
+def _expectedFailureInRpmBuild(func):
866e92
+    """
866e92
+    Non-standard/downstream-only decorator for marking a specific unit test
866e92
+    as expected to fail within the %check of an rpmbuild.
866e92
+
866e92
+    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
866e92
+    the environment, and has no effect otherwise.
866e92
+    """
866e92
+    @functools.wraps(func)
866e92
+    def wrapper(*args, **kwargs):
866e92
+        if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
866e92
+            try:
866e92
+                func(*args, **kwargs)
866e92
+            except Exception:
866e92
+                raise _ExpectedFailure(sys.exc_info())
866e92
+            raise _UnexpectedSuccess
866e92
+        else:
866e92
+            # Call directly:
866e92
+            func(*args, **kwargs)
866e92
+    return wrapper
866e92
+
866e92
 class _AssertRaisesContext(object):
866e92
     """A context manager used to implement TestCase.assertRaises* methods."""
866e92
 
866e92
diff -up Python-2.7.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest Python-2.7.2/Lib/unittest/__init__.py
866e92
--- Python-2.7.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest	2011-09-08 14:59:39.534112310 -0400
866e92
+++ Python-2.7.2/Lib/unittest/__init__.py	2011-09-08 15:07:09.191081562 -0400
866e92
@@ -57,7 +57,8 @@ __unittest = True
866e92
 
866e92
 from .result import TestResult
866e92
 from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
866e92
-                   skipUnless, expectedFailure)
866e92
+                   skipUnless, expectedFailure,
866e92
+                   _skipInRpmBuild, _expectedFailureInRpmBuild)
866e92
 from .suite import BaseTestSuite, TestSuite
866e92
 from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
866e92
                      findTestCases)