Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2..../unittest
File: case.py
"""Test case implementation"""
[0] Fix | Delete
[1] Fix | Delete
import collections
[2] Fix | Delete
import os
[3] Fix | Delete
import sys
[4] Fix | Delete
import functools
[5] Fix | Delete
import difflib
[6] Fix | Delete
import pprint
[7] Fix | Delete
import re
[8] Fix | Delete
import types
[9] Fix | Delete
import warnings
[10] Fix | Delete
[11] Fix | Delete
from . import result
[12] Fix | Delete
from .util import (
[13] Fix | Delete
strclass, safe_repr, unorderable_list_difference,
[14] Fix | Delete
_count_diff_all_purpose, _count_diff_hashable
[15] Fix | Delete
)
[16] Fix | Delete
[17] Fix | Delete
[18] Fix | Delete
__unittest = True
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
DIFF_OMITTED = ('\nDiff is %s characters long. '
[22] Fix | Delete
'Set self.maxDiff to None to see it.')
[23] Fix | Delete
[24] Fix | Delete
class SkipTest(Exception):
[25] Fix | Delete
"""
[26] Fix | Delete
Raise this exception in a test to skip it.
[27] Fix | Delete
[28] Fix | Delete
Usually you can use TestCase.skipTest() or one of the skipping decorators
[29] Fix | Delete
instead of raising this directly.
[30] Fix | Delete
"""
[31] Fix | Delete
pass
[32] Fix | Delete
[33] Fix | Delete
class _ExpectedFailure(Exception):
[34] Fix | Delete
"""
[35] Fix | Delete
Raise this when a test is expected to fail.
[36] Fix | Delete
[37] Fix | Delete
This is an implementation detail.
[38] Fix | Delete
"""
[39] Fix | Delete
[40] Fix | Delete
def __init__(self, exc_info):
[41] Fix | Delete
super(_ExpectedFailure, self).__init__()
[42] Fix | Delete
self.exc_info = exc_info
[43] Fix | Delete
[44] Fix | Delete
class _UnexpectedSuccess(Exception):
[45] Fix | Delete
"""
[46] Fix | Delete
The test was supposed to fail, but it didn't!
[47] Fix | Delete
"""
[48] Fix | Delete
pass
[49] Fix | Delete
[50] Fix | Delete
def _id(obj):
[51] Fix | Delete
return obj
[52] Fix | Delete
[53] Fix | Delete
def skip(reason):
[54] Fix | Delete
"""
[55] Fix | Delete
Unconditionally skip a test.
[56] Fix | Delete
"""
[57] Fix | Delete
def decorator(test_item):
[58] Fix | Delete
if not isinstance(test_item, (type, types.ClassType)):
[59] Fix | Delete
@functools.wraps(test_item)
[60] Fix | Delete
def skip_wrapper(*args, **kwargs):
[61] Fix | Delete
raise SkipTest(reason)
[62] Fix | Delete
test_item = skip_wrapper
[63] Fix | Delete
[64] Fix | Delete
test_item.__unittest_skip__ = True
[65] Fix | Delete
test_item.__unittest_skip_why__ = reason
[66] Fix | Delete
return test_item
[67] Fix | Delete
return decorator
[68] Fix | Delete
[69] Fix | Delete
def skipIf(condition, reason):
[70] Fix | Delete
"""
[71] Fix | Delete
Skip a test if the condition is true.
[72] Fix | Delete
"""
[73] Fix | Delete
if condition:
[74] Fix | Delete
return skip(reason)
[75] Fix | Delete
return _id
[76] Fix | Delete
[77] Fix | Delete
def skipUnless(condition, reason):
[78] Fix | Delete
"""
[79] Fix | Delete
Skip a test unless the condition is true.
[80] Fix | Delete
"""
[81] Fix | Delete
if not condition:
[82] Fix | Delete
return skip(reason)
[83] Fix | Delete
return _id
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
def expectedFailure(func):
[87] Fix | Delete
@functools.wraps(func)
[88] Fix | Delete
def wrapper(*args, **kwargs):
[89] Fix | Delete
try:
[90] Fix | Delete
func(*args, **kwargs)
[91] Fix | Delete
except Exception:
[92] Fix | Delete
raise _ExpectedFailure(sys.exc_info())
[93] Fix | Delete
raise _UnexpectedSuccess
[94] Fix | Delete
return wrapper
[95] Fix | Delete
[96] Fix | Delete
[97] Fix | Delete
# Non-standard/downstream-only hooks for handling issues with specific test
[98] Fix | Delete
# cases:
[99] Fix | Delete
[100] Fix | Delete
def _skipInRpmBuild(reason):
[101] Fix | Delete
"""
[102] Fix | Delete
Non-standard/downstream-only decorator for marking a specific unit test
[103] Fix | Delete
to be skipped when run within the %check of an rpmbuild.
[104] Fix | Delete
[105] Fix | Delete
Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
[106] Fix | Delete
the environment, and has no effect otherwise.
[107] Fix | Delete
"""
[108] Fix | Delete
if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
[109] Fix | Delete
return skip(reason)
[110] Fix | Delete
else:
[111] Fix | Delete
return _id
[112] Fix | Delete
[113] Fix | Delete
def _expectedFailureInRpmBuild(func):
[114] Fix | Delete
"""
[115] Fix | Delete
Non-standard/downstream-only decorator for marking a specific unit test
[116] Fix | Delete
as expected to fail within the %check of an rpmbuild.
[117] Fix | Delete
[118] Fix | Delete
Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
[119] Fix | Delete
the environment, and has no effect otherwise.
[120] Fix | Delete
"""
[121] Fix | Delete
@functools.wraps(func)
[122] Fix | Delete
def wrapper(*args, **kwargs):
[123] Fix | Delete
if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
[124] Fix | Delete
try:
[125] Fix | Delete
func(*args, **kwargs)
[126] Fix | Delete
except Exception:
[127] Fix | Delete
raise _ExpectedFailure(sys.exc_info())
[128] Fix | Delete
raise _UnexpectedSuccess
[129] Fix | Delete
else:
[130] Fix | Delete
# Call directly:
[131] Fix | Delete
func(*args, **kwargs)
[132] Fix | Delete
return wrapper
[133] Fix | Delete
[134] Fix | Delete
class _AssertRaisesContext(object):
[135] Fix | Delete
"""A context manager used to implement TestCase.assertRaises* methods."""
[136] Fix | Delete
[137] Fix | Delete
def __init__(self, expected, test_case, expected_regexp=None):
[138] Fix | Delete
self.expected = expected
[139] Fix | Delete
self.failureException = test_case.failureException
[140] Fix | Delete
self.expected_regexp = expected_regexp
[141] Fix | Delete
[142] Fix | Delete
def __enter__(self):
[143] Fix | Delete
return self
[144] Fix | Delete
[145] Fix | Delete
def __exit__(self, exc_type, exc_value, tb):
[146] Fix | Delete
if exc_type is None:
[147] Fix | Delete
try:
[148] Fix | Delete
exc_name = self.expected.__name__
[149] Fix | Delete
except AttributeError:
[150] Fix | Delete
exc_name = str(self.expected)
[151] Fix | Delete
raise self.failureException(
[152] Fix | Delete
"{0} not raised".format(exc_name))
[153] Fix | Delete
if not issubclass(exc_type, self.expected):
[154] Fix | Delete
# let unexpected exceptions pass through
[155] Fix | Delete
return False
[156] Fix | Delete
self.exception = exc_value # store for later retrieval
[157] Fix | Delete
if self.expected_regexp is None:
[158] Fix | Delete
return True
[159] Fix | Delete
[160] Fix | Delete
expected_regexp = self.expected_regexp
[161] Fix | Delete
if not expected_regexp.search(str(exc_value)):
[162] Fix | Delete
raise self.failureException('"%s" does not match "%s"' %
[163] Fix | Delete
(expected_regexp.pattern, str(exc_value)))
[164] Fix | Delete
return True
[165] Fix | Delete
[166] Fix | Delete
[167] Fix | Delete
class TestCase(object):
[168] Fix | Delete
"""A class whose instances are single test cases.
[169] Fix | Delete
[170] Fix | Delete
By default, the test code itself should be placed in a method named
[171] Fix | Delete
'runTest'.
[172] Fix | Delete
[173] Fix | Delete
If the fixture may be used for many test cases, create as
[174] Fix | Delete
many test methods as are needed. When instantiating such a TestCase
[175] Fix | Delete
subclass, specify in the constructor arguments the name of the test method
[176] Fix | Delete
that the instance is to execute.
[177] Fix | Delete
[178] Fix | Delete
Test authors should subclass TestCase for their own tests. Construction
[179] Fix | Delete
and deconstruction of the test's environment ('fixture') can be
[180] Fix | Delete
implemented by overriding the 'setUp' and 'tearDown' methods respectively.
[181] Fix | Delete
[182] Fix | Delete
If it is necessary to override the __init__ method, the base class
[183] Fix | Delete
__init__ method must always be called. It is important that subclasses
[184] Fix | Delete
should not change the signature of their __init__ method, since instances
[185] Fix | Delete
of the classes are instantiated automatically by parts of the framework
[186] Fix | Delete
in order to be run.
[187] Fix | Delete
[188] Fix | Delete
When subclassing TestCase, you can set these attributes:
[189] Fix | Delete
* failureException: determines which exception will be raised when
[190] Fix | Delete
the instance's assertion methods fail; test methods raising this
[191] Fix | Delete
exception will be deemed to have 'failed' rather than 'errored'.
[192] Fix | Delete
* longMessage: determines whether long messages (including repr of
[193] Fix | Delete
objects used in assert methods) will be printed on failure in *addition*
[194] Fix | Delete
to any explicit message passed.
[195] Fix | Delete
* maxDiff: sets the maximum length of a diff in failure messages
[196] Fix | Delete
by assert methods using difflib. It is looked up as an instance
[197] Fix | Delete
attribute so can be configured by individual tests if required.
[198] Fix | Delete
"""
[199] Fix | Delete
[200] Fix | Delete
failureException = AssertionError
[201] Fix | Delete
[202] Fix | Delete
longMessage = False
[203] Fix | Delete
[204] Fix | Delete
maxDiff = 80*8
[205] Fix | Delete
[206] Fix | Delete
# If a string is longer than _diffThreshold, use normal comparison instead
[207] Fix | Delete
# of difflib. See #11763.
[208] Fix | Delete
_diffThreshold = 2**16
[209] Fix | Delete
[210] Fix | Delete
# Attribute used by TestSuite for classSetUp
[211] Fix | Delete
[212] Fix | Delete
_classSetupFailed = False
[213] Fix | Delete
[214] Fix | Delete
def __init__(self, methodName='runTest'):
[215] Fix | Delete
"""Create an instance of the class that will use the named test
[216] Fix | Delete
method when executed. Raises a ValueError if the instance does
[217] Fix | Delete
not have a method with the specified name.
[218] Fix | Delete
"""
[219] Fix | Delete
self._testMethodName = methodName
[220] Fix | Delete
self._resultForDoCleanups = None
[221] Fix | Delete
try:
[222] Fix | Delete
testMethod = getattr(self, methodName)
[223] Fix | Delete
except AttributeError:
[224] Fix | Delete
raise ValueError("no such test method in %s: %s" %
[225] Fix | Delete
(self.__class__, methodName))
[226] Fix | Delete
self._testMethodDoc = testMethod.__doc__
[227] Fix | Delete
self._cleanups = []
[228] Fix | Delete
[229] Fix | Delete
# Map types to custom assertEqual functions that will compare
[230] Fix | Delete
# instances of said type in more detail to generate a more useful
[231] Fix | Delete
# error message.
[232] Fix | Delete
self._type_equality_funcs = {}
[233] Fix | Delete
self.addTypeEqualityFunc(dict, 'assertDictEqual')
[234] Fix | Delete
self.addTypeEqualityFunc(list, 'assertListEqual')
[235] Fix | Delete
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
[236] Fix | Delete
self.addTypeEqualityFunc(set, 'assertSetEqual')
[237] Fix | Delete
self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
[238] Fix | Delete
try:
[239] Fix | Delete
self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual')
[240] Fix | Delete
except NameError:
[241] Fix | Delete
# No unicode support in this build
[242] Fix | Delete
pass
[243] Fix | Delete
[244] Fix | Delete
def addTypeEqualityFunc(self, typeobj, function):
[245] Fix | Delete
"""Add a type specific assertEqual style function to compare a type.
[246] Fix | Delete
[247] Fix | Delete
This method is for use by TestCase subclasses that need to register
[248] Fix | Delete
their own type equality functions to provide nicer error messages.
[249] Fix | Delete
[250] Fix | Delete
Args:
[251] Fix | Delete
typeobj: The data type to call this function on when both values
[252] Fix | Delete
are of the same type in assertEqual().
[253] Fix | Delete
function: The callable taking two arguments and an optional
[254] Fix | Delete
msg= argument that raises self.failureException with a
[255] Fix | Delete
useful error message when the two arguments are not equal.
[256] Fix | Delete
"""
[257] Fix | Delete
self._type_equality_funcs[typeobj] = function
[258] Fix | Delete
[259] Fix | Delete
def addCleanup(self, function, *args, **kwargs):
[260] Fix | Delete
"""Add a function, with arguments, to be called when the test is
[261] Fix | Delete
completed. Functions added are called on a LIFO basis and are
[262] Fix | Delete
called after tearDown on test failure or success.
[263] Fix | Delete
[264] Fix | Delete
Cleanup items are called even if setUp fails (unlike tearDown)."""
[265] Fix | Delete
self._cleanups.append((function, args, kwargs))
[266] Fix | Delete
[267] Fix | Delete
def setUp(self):
[268] Fix | Delete
"Hook method for setting up the test fixture before exercising it."
[269] Fix | Delete
pass
[270] Fix | Delete
[271] Fix | Delete
def tearDown(self):
[272] Fix | Delete
"Hook method for deconstructing the test fixture after testing it."
[273] Fix | Delete
pass
[274] Fix | Delete
[275] Fix | Delete
@classmethod
[276] Fix | Delete
def setUpClass(cls):
[277] Fix | Delete
"Hook method for setting up class fixture before running tests in the class."
[278] Fix | Delete
[279] Fix | Delete
@classmethod
[280] Fix | Delete
def tearDownClass(cls):
[281] Fix | Delete
"Hook method for deconstructing the class fixture after running all tests in the class."
[282] Fix | Delete
[283] Fix | Delete
def countTestCases(self):
[284] Fix | Delete
return 1
[285] Fix | Delete
[286] Fix | Delete
def defaultTestResult(self):
[287] Fix | Delete
return result.TestResult()
[288] Fix | Delete
[289] Fix | Delete
def shortDescription(self):
[290] Fix | Delete
"""Returns a one-line description of the test, or None if no
[291] Fix | Delete
description has been provided.
[292] Fix | Delete
[293] Fix | Delete
The default implementation of this method returns the first line of
[294] Fix | Delete
the specified test method's docstring.
[295] Fix | Delete
"""
[296] Fix | Delete
doc = self._testMethodDoc
[297] Fix | Delete
return doc and doc.split("\n")[0].strip() or None
[298] Fix | Delete
[299] Fix | Delete
[300] Fix | Delete
def id(self):
[301] Fix | Delete
return "%s.%s" % (strclass(self.__class__), self._testMethodName)
[302] Fix | Delete
[303] Fix | Delete
def __eq__(self, other):
[304] Fix | Delete
if type(self) is not type(other):
[305] Fix | Delete
return NotImplemented
[306] Fix | Delete
[307] Fix | Delete
return self._testMethodName == other._testMethodName
[308] Fix | Delete
[309] Fix | Delete
def __ne__(self, other):
[310] Fix | Delete
return not self == other
[311] Fix | Delete
[312] Fix | Delete
def __hash__(self):
[313] Fix | Delete
return hash((type(self), self._testMethodName))
[314] Fix | Delete
[315] Fix | Delete
def __str__(self):
[316] Fix | Delete
return "%s (%s)" % (self._testMethodName, strclass(self.__class__))
[317] Fix | Delete
[318] Fix | Delete
def __repr__(self):
[319] Fix | Delete
return "<%s testMethod=%s>" % \
[320] Fix | Delete
(strclass(self.__class__), self._testMethodName)
[321] Fix | Delete
[322] Fix | Delete
def _addSkip(self, result, reason):
[323] Fix | Delete
addSkip = getattr(result, 'addSkip', None)
[324] Fix | Delete
if addSkip is not None:
[325] Fix | Delete
addSkip(self, reason)
[326] Fix | Delete
else:
[327] Fix | Delete
warnings.warn("TestResult has no addSkip method, skips not reported",
[328] Fix | Delete
RuntimeWarning, 2)
[329] Fix | Delete
result.addSuccess(self)
[330] Fix | Delete
[331] Fix | Delete
def run(self, result=None):
[332] Fix | Delete
orig_result = result
[333] Fix | Delete
if result is None:
[334] Fix | Delete
result = self.defaultTestResult()
[335] Fix | Delete
startTestRun = getattr(result, 'startTestRun', None)
[336] Fix | Delete
if startTestRun is not None:
[337] Fix | Delete
startTestRun()
[338] Fix | Delete
[339] Fix | Delete
self._resultForDoCleanups = result
[340] Fix | Delete
result.startTest(self)
[341] Fix | Delete
[342] Fix | Delete
testMethod = getattr(self, self._testMethodName)
[343] Fix | Delete
if (getattr(self.__class__, "__unittest_skip__", False) or
[344] Fix | Delete
getattr(testMethod, "__unittest_skip__", False)):
[345] Fix | Delete
# If the class or method was skipped.
[346] Fix | Delete
try:
[347] Fix | Delete
skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
[348] Fix | Delete
or getattr(testMethod, '__unittest_skip_why__', ''))
[349] Fix | Delete
self._addSkip(result, skip_why)
[350] Fix | Delete
finally:
[351] Fix | Delete
result.stopTest(self)
[352] Fix | Delete
return
[353] Fix | Delete
try:
[354] Fix | Delete
success = False
[355] Fix | Delete
try:
[356] Fix | Delete
self.setUp()
[357] Fix | Delete
except SkipTest as e:
[358] Fix | Delete
self._addSkip(result, str(e))
[359] Fix | Delete
except KeyboardInterrupt:
[360] Fix | Delete
raise
[361] Fix | Delete
except:
[362] Fix | Delete
result.addError(self, sys.exc_info())
[363] Fix | Delete
else:
[364] Fix | Delete
try:
[365] Fix | Delete
testMethod()
[366] Fix | Delete
except KeyboardInterrupt:
[367] Fix | Delete
raise
[368] Fix | Delete
except self.failureException:
[369] Fix | Delete
result.addFailure(self, sys.exc_info())
[370] Fix | Delete
except _ExpectedFailure as e:
[371] Fix | Delete
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
[372] Fix | Delete
if addExpectedFailure is not None:
[373] Fix | Delete
addExpectedFailure(self, e.exc_info)
[374] Fix | Delete
else:
[375] Fix | Delete
warnings.warn("TestResult has no addExpectedFailure method, reporting as passes",
[376] Fix | Delete
RuntimeWarning)
[377] Fix | Delete
result.addSuccess(self)
[378] Fix | Delete
except _UnexpectedSuccess:
[379] Fix | Delete
addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
[380] Fix | Delete
if addUnexpectedSuccess is not None:
[381] Fix | Delete
addUnexpectedSuccess(self)
[382] Fix | Delete
else:
[383] Fix | Delete
warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failures",
[384] Fix | Delete
RuntimeWarning)
[385] Fix | Delete
result.addFailure(self, sys.exc_info())
[386] Fix | Delete
except SkipTest as e:
[387] Fix | Delete
self._addSkip(result, str(e))
[388] Fix | Delete
except:
[389] Fix | Delete
result.addError(self, sys.exc_info())
[390] Fix | Delete
else:
[391] Fix | Delete
success = True
[392] Fix | Delete
[393] Fix | Delete
try:
[394] Fix | Delete
self.tearDown()
[395] Fix | Delete
except KeyboardInterrupt:
[396] Fix | Delete
raise
[397] Fix | Delete
except:
[398] Fix | Delete
result.addError(self, sys.exc_info())
[399] Fix | Delete
success = False
[400] Fix | Delete
[401] Fix | Delete
cleanUpSuccess = self.doCleanups()
[402] Fix | Delete
success = success and cleanUpSuccess
[403] Fix | Delete
if success:
[404] Fix | Delete
result.addSuccess(self)
[405] Fix | Delete
finally:
[406] Fix | Delete
result.stopTest(self)
[407] Fix | Delete
if orig_result is None:
[408] Fix | Delete
stopTestRun = getattr(result, 'stopTestRun', None)
[409] Fix | Delete
if stopTestRun is not None:
[410] Fix | Delete
stopTestRun()
[411] Fix | Delete
[412] Fix | Delete
def doCleanups(self):
[413] Fix | Delete
"""Execute all cleanup functions. Normally called for you after
[414] Fix | Delete
tearDown."""
[415] Fix | Delete
result = self._resultForDoCleanups
[416] Fix | Delete
ok = True
[417] Fix | Delete
while self._cleanups:
[418] Fix | Delete
function, args, kwargs = self._cleanups.pop(-1)
[419] Fix | Delete
try:
[420] Fix | Delete
function(*args, **kwargs)
[421] Fix | Delete
except KeyboardInterrupt:
[422] Fix | Delete
raise
[423] Fix | Delete
except:
[424] Fix | Delete
ok = False
[425] Fix | Delete
result.addError(self, sys.exc_info())
[426] Fix | Delete
return ok
[427] Fix | Delete
[428] Fix | Delete
def __call__(self, *args, **kwds):
[429] Fix | Delete
return self.run(*args, **kwds)
[430] Fix | Delete
[431] Fix | Delete
def debug(self):
[432] Fix | Delete
"""Run the test without collecting errors in a TestResult"""
[433] Fix | Delete
self.setUp()
[434] Fix | Delete
getattr(self, self._testMethodName)()
[435] Fix | Delete
self.tearDown()
[436] Fix | Delete
while self._cleanups:
[437] Fix | Delete
function, args, kwargs = self._cleanups.pop(-1)
[438] Fix | Delete
function(*args, **kwargs)
[439] Fix | Delete
[440] Fix | Delete
def skipTest(self, reason):
[441] Fix | Delete
"""Skip this test."""
[442] Fix | Delete
raise SkipTest(reason)
[443] Fix | Delete
[444] Fix | Delete
def fail(self, msg=None):
[445] Fix | Delete
"""Fail immediately, with the given message."""
[446] Fix | Delete
raise self.failureException(msg)
[447] Fix | Delete
[448] Fix | Delete
def assertFalse(self, expr, msg=None):
[449] Fix | Delete
"""Check that the expression is false."""
[450] Fix | Delete
if expr:
[451] Fix | Delete
msg = self._formatMessage(msg, "%s is not false" % safe_repr(expr))
[452] Fix | Delete
raise self.failureException(msg)
[453] Fix | Delete
[454] Fix | Delete
def assertTrue(self, expr, msg=None):
[455] Fix | Delete
"""Check that the expression is true."""
[456] Fix | Delete
if not expr:
[457] Fix | Delete
msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
[458] Fix | Delete
raise self.failureException(msg)
[459] Fix | Delete
[460] Fix | Delete
def _formatMessage(self, msg, standardMsg):
[461] Fix | Delete
"""Honour the longMessage attribute when generating failure messages.
[462] Fix | Delete
If longMessage is False this means:
[463] Fix | Delete
* Use only an explicit message if it is provided
[464] Fix | Delete
* Otherwise use the standard message for the assert
[465] Fix | Delete
[466] Fix | Delete
If longMessage is True:
[467] Fix | Delete
* Use the standard message
[468] Fix | Delete
* If an explicit message is provided, plus ' : ' and the explicit message
[469] Fix | Delete
"""
[470] Fix | Delete
if not self.longMessage:
[471] Fix | Delete
return msg or standardMsg
[472] Fix | Delete
if msg is None:
[473] Fix | Delete
return standardMsg
[474] Fix | Delete
try:
[475] Fix | Delete
# don't switch to '{}' formatting in Python 2.X
[476] Fix | Delete
# it changes the way unicode input is handled
[477] Fix | Delete
return '%s : %s' % (standardMsg, msg)
[478] Fix | Delete
except UnicodeDecodeError:
[479] Fix | Delete
return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
[480] Fix | Delete
[481] Fix | Delete
[482] Fix | Delete
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
[483] Fix | Delete
"""Fail unless an exception of class excClass is raised
[484] Fix | Delete
by callableObj when invoked with arguments args and keyword
[485] Fix | Delete
arguments kwargs. If a different type of exception is
[486] Fix | Delete
raised, it will not be caught, and the test case will be
[487] Fix | Delete
deemed to have suffered an error, exactly as for an
[488] Fix | Delete
unexpected exception.
[489] Fix | Delete
[490] Fix | Delete
If called with callableObj omitted or None, will return a
[491] Fix | Delete
context object used like this::
[492] Fix | Delete
[493] Fix | Delete
with self.assertRaises(SomeException):
[494] Fix | Delete
do_something()
[495] Fix | Delete
[496] Fix | Delete
The context manager keeps a reference to the exception as
[497] Fix | Delete
the 'exception' attribute. This allows you to inspect the
[498] Fix | Delete
exception after the assertion::
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function