]>
Commit | Line | Data |
---|---|---|
bf250edf MT |
1 | diff -up Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/case.py |
2 | --- Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest 2011-09-03 12:16:44.000000000 -0400 | |
3 | +++ Python-3.2.2/Lib/unittest/case.py 2011-09-09 06:35:16.365568382 -0400 | |
4 | @@ -3,6 +3,7 @@ | |
5 | import sys | |
6 | import functools | |
7 | import difflib | |
8 | +import os | |
9 | import pprint | |
10 | import re | |
11 | import warnings | |
12 | @@ -101,6 +102,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 _AssertRaisesBaseContext(object): | |
54 | ||
55 | def __init__(self, expected, test_case, callable_obj=None, | |
56 | diff -up Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/__init__.py | |
57 | --- Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest 2011-09-03 12:16:44.000000000 -0400 | |
58 | +++ Python-3.2.2/Lib/unittest/__init__.py 2011-09-09 06:35:16.366568382 -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) |