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

e32ce18
diff -up Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/case.py
e32ce18
--- Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest	2011-09-03 12:16:44.000000000 -0400
e32ce18
+++ Python-3.2.2/Lib/unittest/case.py	2011-09-09 06:35:16.365568382 -0400
e32ce18
@@ -3,6 +3,7 @@
e32ce18
 import sys
e32ce18
 import functools
e32ce18
 import difflib
e32ce18
+import os
e32ce18
 import logging
e32ce18
 import pprint
e32ce18
 import re
e32ce18
@@ -101,6 +102,43 @@ def expectedFailure(func):
e32ce18
         raise self.test_case.failureException(msg)
e32ce18
 
e32ce18
 
e32ce18
+# Non-standard/downstream-only hooks for handling issues with specific test
e32ce18
+# cases:
e32ce18
+
e32ce18
+def _skipInRpmBuild(reason):
e32ce18
+    """
e32ce18
+    Non-standard/downstream-only decorator for marking a specific unit test
e32ce18
+    to be skipped when run within the %check of an rpmbuild.
e32ce18
+
e32ce18
+    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
e32ce18
+    the environment, and has no effect otherwise.
e32ce18
+    """
e32ce18
+    if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
e32ce18
+        return skip(reason)
e32ce18
+    else:
e32ce18
+        return _id
e32ce18
+
e32ce18
+def _expectedFailureInRpmBuild(func):
e32ce18
+    """
e32ce18
+    Non-standard/downstream-only decorator for marking a specific unit test
e32ce18
+    as expected to fail within the %check of an rpmbuild.
e32ce18
+
e32ce18
+    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
e32ce18
+    the environment, and has no effect otherwise.
e32ce18
+    """
e32ce18
+    @functools.wraps(func)
e32ce18
+    def wrapper(*args, **kwargs):
e32ce18
+        if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
e32ce18
+            try:
e32ce18
+                func(*args, **kwargs)
e32ce18
+            except Exception:
e32ce18
+                raise _ExpectedFailure(sys.exc_info())
e32ce18
+            raise _UnexpectedSuccess
e32ce18
+        else:
e32ce18
+            # Call directly:
e32ce18
+            func(*args, **kwargs)
e32ce18
+    return wrapper
e32ce18
+
e32ce18
 class _AssertRaisesBaseContext(_BaseTestCaseContext):
e32ce18
 
e32ce18
     def __init__(self, expected, test_case, callable_obj=None,
e32ce18
diff -up Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/__init__.py
e32ce18
--- Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest	2011-09-03 12:16:44.000000000 -0400
e32ce18
+++ Python-3.2.2/Lib/unittest/__init__.py	2011-09-09 06:35:16.366568382 -0400
e32ce18
@@ -57,7 +57,8 @@ __unittest = True
e32ce18
 
e32ce18
 from .result import TestResult
e32ce18
 from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
e32ce18
-                   skipUnless, expectedFailure)
e32ce18
+                   skipUnless, expectedFailure,
e32ce18
+                   _skipInRpmBuild, _expectedFailureInRpmBuild)
e32ce18
 from .suite import BaseTestSuite, TestSuite
e32ce18
 from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
e32ce18
                      findTestCases)