Blame 00132-add-rpmbuild-hooks-to-unittest.patch

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