An interpreted, interactive, object-oriented programming language
CentOS Sources
2017-08-01 71084d584ff953f5463757ec6536406320560b4d
commit | author | age
6e8c2f 1 diff -up Python-2.7.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest Python-2.7.2/Lib/unittest/case.py
CB 2 --- Python-2.7.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest    2011-09-08 14:45:47.677169191 -0400
3 +++ Python-2.7.2/Lib/unittest/case.py    2011-09-08 16:01:36.287858159 -0400
4 @@ -1,6 +1,7 @@
5  """Test case implementation"""
6  
7  import collections
8 +import os
9  import sys
10  import functools
11  import difflib
12 @@ -94,6 +95,43 @@ def expectedFailure(func):
13      return wrapper
14  
15  
16 +# Non-standard/downstream-only hooks for handling issues with specific test
17 +# cases:
18 +
19 +def _skipInRpmBuild(reason):
20 +    """
21 +    Non-standard/downstream-only decorator for marking a specific unit test
22 +    to be skipped when run within the %check of an rpmbuild.
23 +
24 +    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
25 +    the environment, and has no effect otherwise.
26 +    """
27 +    if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
28 +        return skip(reason)
29 +    else:
30 +        return _id
31 +
32 +def _expectedFailureInRpmBuild(func):
33 +    """
34 +    Non-standard/downstream-only decorator for marking a specific unit test
35 +    as expected to fail within the %check of an rpmbuild.
36 +
37 +    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
38 +    the environment, and has no effect otherwise.
39 +    """
40 +    @functools.wraps(func)
41 +    def wrapper(*args, **kwargs):
42 +        if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
43 +            try:
44 +                func(*args, **kwargs)
45 +            except Exception:
46 +                raise _ExpectedFailure(sys.exc_info())
47 +            raise _UnexpectedSuccess
48 +        else:
49 +            # Call directly:
50 +            func(*args, **kwargs)
51 +    return wrapper
52 +
53  class _AssertRaisesContext(object):
54      """A context manager used to implement TestCase.assertRaises* methods."""
55  
56 diff -up Python-2.7.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest Python-2.7.2/Lib/unittest/__init__.py
57 --- Python-2.7.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest    2011-09-08 14:59:39.534112310 -0400
58 +++ Python-2.7.2/Lib/unittest/__init__.py    2011-09-08 15:07:09.191081562 -0400
59 @@ -57,7 +57,8 @@ __unittest = True
60  
61  from .result import TestResult
62  from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
63 -                   skipUnless, expectedFailure)
64 +                   skipUnless, expectedFailure,
65 +                   _skipInRpmBuild, _expectedFailureInRpmBuild)
66  from .suite import BaseTestSuite, TestSuite
67  from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
68                       findTestCases)