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

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