Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../unittest
File: case.py
[500] Fix | Delete
def setUp(self):
[501] Fix | Delete
"Hook method for setting up the test fixture before exercising it."
[502] Fix | Delete
pass
[503] Fix | Delete
[504] Fix | Delete
def tearDown(self):
[505] Fix | Delete
"Hook method for deconstructing the test fixture after testing it."
[506] Fix | Delete
pass
[507] Fix | Delete
[508] Fix | Delete
@classmethod
[509] Fix | Delete
def setUpClass(cls):
[510] Fix | Delete
"Hook method for setting up class fixture before running tests in the class."
[511] Fix | Delete
[512] Fix | Delete
@classmethod
[513] Fix | Delete
def tearDownClass(cls):
[514] Fix | Delete
"Hook method for deconstructing the class fixture after running all tests in the class."
[515] Fix | Delete
[516] Fix | Delete
def countTestCases(self):
[517] Fix | Delete
return 1
[518] Fix | Delete
[519] Fix | Delete
def defaultTestResult(self):
[520] Fix | Delete
return result.TestResult()
[521] Fix | Delete
[522] Fix | Delete
def shortDescription(self):
[523] Fix | Delete
"""Returns a one-line description of the test, or None if no
[524] Fix | Delete
description has been provided.
[525] Fix | Delete
[526] Fix | Delete
The default implementation of this method returns the first line of
[527] Fix | Delete
the specified test method's docstring.
[528] Fix | Delete
"""
[529] Fix | Delete
doc = self._testMethodDoc
[530] Fix | Delete
return doc.strip().split("\n")[0].strip() if doc else None
[531] Fix | Delete
[532] Fix | Delete
[533] Fix | Delete
def id(self):
[534] Fix | Delete
return "%s.%s" % (strclass(self.__class__), self._testMethodName)
[535] Fix | Delete
[536] Fix | Delete
def __eq__(self, other):
[537] Fix | Delete
if type(self) is not type(other):
[538] Fix | Delete
return NotImplemented
[539] Fix | Delete
[540] Fix | Delete
return self._testMethodName == other._testMethodName
[541] Fix | Delete
[542] Fix | Delete
def __hash__(self):
[543] Fix | Delete
return hash((type(self), self._testMethodName))
[544] Fix | Delete
[545] Fix | Delete
def __str__(self):
[546] Fix | Delete
return "%s (%s)" % (self._testMethodName, strclass(self.__class__))
[547] Fix | Delete
[548] Fix | Delete
def __repr__(self):
[549] Fix | Delete
return "<%s testMethod=%s>" % \
[550] Fix | Delete
(strclass(self.__class__), self._testMethodName)
[551] Fix | Delete
[552] Fix | Delete
def _addSkip(self, result, test_case, reason):
[553] Fix | Delete
addSkip = getattr(result, 'addSkip', None)
[554] Fix | Delete
if addSkip is not None:
[555] Fix | Delete
addSkip(test_case, reason)
[556] Fix | Delete
else:
[557] Fix | Delete
warnings.warn("TestResult has no addSkip method, skips not reported",
[558] Fix | Delete
RuntimeWarning, 2)
[559] Fix | Delete
result.addSuccess(test_case)
[560] Fix | Delete
[561] Fix | Delete
@contextlib.contextmanager
[562] Fix | Delete
def subTest(self, msg=_subtest_msg_sentinel, **params):
[563] Fix | Delete
"""Return a context manager that will return the enclosed block
[564] Fix | Delete
of code in a subtest identified by the optional message and
[565] Fix | Delete
keyword parameters. A failure in the subtest marks the test
[566] Fix | Delete
case as failed but resumes execution at the end of the enclosed
[567] Fix | Delete
block, allowing further test code to be executed.
[568] Fix | Delete
"""
[569] Fix | Delete
if self._outcome is None or not self._outcome.result_supports_subtests:
[570] Fix | Delete
yield
[571] Fix | Delete
return
[572] Fix | Delete
parent = self._subtest
[573] Fix | Delete
if parent is None:
[574] Fix | Delete
params_map = _OrderedChainMap(params)
[575] Fix | Delete
else:
[576] Fix | Delete
params_map = parent.params.new_child(params)
[577] Fix | Delete
self._subtest = _SubTest(self, msg, params_map)
[578] Fix | Delete
try:
[579] Fix | Delete
with self._outcome.testPartExecutor(self._subtest, isTest=True):
[580] Fix | Delete
yield
[581] Fix | Delete
if not self._outcome.success:
[582] Fix | Delete
result = self._outcome.result
[583] Fix | Delete
if result is not None and result.failfast:
[584] Fix | Delete
raise _ShouldStop
[585] Fix | Delete
elif self._outcome.expectedFailure:
[586] Fix | Delete
# If the test is expecting a failure, we really want to
[587] Fix | Delete
# stop now and register the expected failure.
[588] Fix | Delete
raise _ShouldStop
[589] Fix | Delete
finally:
[590] Fix | Delete
self._subtest = parent
[591] Fix | Delete
[592] Fix | Delete
def _feedErrorsToResult(self, result, errors):
[593] Fix | Delete
for test, exc_info in errors:
[594] Fix | Delete
if isinstance(test, _SubTest):
[595] Fix | Delete
result.addSubTest(test.test_case, test, exc_info)
[596] Fix | Delete
elif exc_info is not None:
[597] Fix | Delete
if issubclass(exc_info[0], self.failureException):
[598] Fix | Delete
result.addFailure(test, exc_info)
[599] Fix | Delete
else:
[600] Fix | Delete
result.addError(test, exc_info)
[601] Fix | Delete
[602] Fix | Delete
def _addExpectedFailure(self, result, exc_info):
[603] Fix | Delete
try:
[604] Fix | Delete
addExpectedFailure = result.addExpectedFailure
[605] Fix | Delete
except AttributeError:
[606] Fix | Delete
warnings.warn("TestResult has no addExpectedFailure method, reporting as passes",
[607] Fix | Delete
RuntimeWarning)
[608] Fix | Delete
result.addSuccess(self)
[609] Fix | Delete
else:
[610] Fix | Delete
addExpectedFailure(self, exc_info)
[611] Fix | Delete
[612] Fix | Delete
def _addUnexpectedSuccess(self, result):
[613] Fix | Delete
try:
[614] Fix | Delete
addUnexpectedSuccess = result.addUnexpectedSuccess
[615] Fix | Delete
except AttributeError:
[616] Fix | Delete
warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failure",
[617] Fix | Delete
RuntimeWarning)
[618] Fix | Delete
# We need to pass an actual exception and traceback to addFailure,
[619] Fix | Delete
# otherwise the legacy result can choke.
[620] Fix | Delete
try:
[621] Fix | Delete
raise _UnexpectedSuccess from None
[622] Fix | Delete
except _UnexpectedSuccess:
[623] Fix | Delete
result.addFailure(self, sys.exc_info())
[624] Fix | Delete
else:
[625] Fix | Delete
addUnexpectedSuccess(self)
[626] Fix | Delete
[627] Fix | Delete
def _callSetUp(self):
[628] Fix | Delete
self.setUp()
[629] Fix | Delete
[630] Fix | Delete
def _callTestMethod(self, method):
[631] Fix | Delete
method()
[632] Fix | Delete
[633] Fix | Delete
def _callTearDown(self):
[634] Fix | Delete
self.tearDown()
[635] Fix | Delete
[636] Fix | Delete
def _callCleanup(self, function, /, *args, **kwargs):
[637] Fix | Delete
function(*args, **kwargs)
[638] Fix | Delete
[639] Fix | Delete
def run(self, result=None):
[640] Fix | Delete
orig_result = result
[641] Fix | Delete
if result is None:
[642] Fix | Delete
result = self.defaultTestResult()
[643] Fix | Delete
startTestRun = getattr(result, 'startTestRun', None)
[644] Fix | Delete
if startTestRun is not None:
[645] Fix | Delete
startTestRun()
[646] Fix | Delete
[647] Fix | Delete
result.startTest(self)
[648] Fix | Delete
[649] Fix | Delete
testMethod = getattr(self, self._testMethodName)
[650] Fix | Delete
if (getattr(self.__class__, "__unittest_skip__", False) or
[651] Fix | Delete
getattr(testMethod, "__unittest_skip__", False)):
[652] Fix | Delete
# If the class or method was skipped.
[653] Fix | Delete
try:
[654] Fix | Delete
skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
[655] Fix | Delete
or getattr(testMethod, '__unittest_skip_why__', ''))
[656] Fix | Delete
self._addSkip(result, self, skip_why)
[657] Fix | Delete
finally:
[658] Fix | Delete
result.stopTest(self)
[659] Fix | Delete
return
[660] Fix | Delete
expecting_failure_method = getattr(testMethod,
[661] Fix | Delete
"__unittest_expecting_failure__", False)
[662] Fix | Delete
expecting_failure_class = getattr(self,
[663] Fix | Delete
"__unittest_expecting_failure__", False)
[664] Fix | Delete
expecting_failure = expecting_failure_class or expecting_failure_method
[665] Fix | Delete
outcome = _Outcome(result)
[666] Fix | Delete
try:
[667] Fix | Delete
self._outcome = outcome
[668] Fix | Delete
[669] Fix | Delete
with outcome.testPartExecutor(self):
[670] Fix | Delete
self._callSetUp()
[671] Fix | Delete
if outcome.success:
[672] Fix | Delete
outcome.expecting_failure = expecting_failure
[673] Fix | Delete
with outcome.testPartExecutor(self, isTest=True):
[674] Fix | Delete
self._callTestMethod(testMethod)
[675] Fix | Delete
outcome.expecting_failure = False
[676] Fix | Delete
with outcome.testPartExecutor(self):
[677] Fix | Delete
self._callTearDown()
[678] Fix | Delete
[679] Fix | Delete
self.doCleanups()
[680] Fix | Delete
for test, reason in outcome.skipped:
[681] Fix | Delete
self._addSkip(result, test, reason)
[682] Fix | Delete
self._feedErrorsToResult(result, outcome.errors)
[683] Fix | Delete
if outcome.success:
[684] Fix | Delete
if expecting_failure:
[685] Fix | Delete
if outcome.expectedFailure:
[686] Fix | Delete
self._addExpectedFailure(result, outcome.expectedFailure)
[687] Fix | Delete
else:
[688] Fix | Delete
self._addUnexpectedSuccess(result)
[689] Fix | Delete
else:
[690] Fix | Delete
result.addSuccess(self)
[691] Fix | Delete
return result
[692] Fix | Delete
finally:
[693] Fix | Delete
result.stopTest(self)
[694] Fix | Delete
if orig_result is None:
[695] Fix | Delete
stopTestRun = getattr(result, 'stopTestRun', None)
[696] Fix | Delete
if stopTestRun is not None:
[697] Fix | Delete
stopTestRun()
[698] Fix | Delete
[699] Fix | Delete
# explicitly break reference cycles:
[700] Fix | Delete
# outcome.errors -> frame -> outcome -> outcome.errors
[701] Fix | Delete
# outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure
[702] Fix | Delete
outcome.errors.clear()
[703] Fix | Delete
outcome.expectedFailure = None
[704] Fix | Delete
[705] Fix | Delete
# clear the outcome, no more needed
[706] Fix | Delete
self._outcome = None
[707] Fix | Delete
[708] Fix | Delete
def doCleanups(self):
[709] Fix | Delete
"""Execute all cleanup functions. Normally called for you after
[710] Fix | Delete
tearDown."""
[711] Fix | Delete
outcome = self._outcome or _Outcome()
[712] Fix | Delete
while self._cleanups:
[713] Fix | Delete
function, args, kwargs = self._cleanups.pop()
[714] Fix | Delete
with outcome.testPartExecutor(self):
[715] Fix | Delete
self._callCleanup(function, *args, **kwargs)
[716] Fix | Delete
[717] Fix | Delete
# return this for backwards compatibility
[718] Fix | Delete
# even though we no longer use it internally
[719] Fix | Delete
return outcome.success
[720] Fix | Delete
[721] Fix | Delete
@classmethod
[722] Fix | Delete
def doClassCleanups(cls):
[723] Fix | Delete
"""Execute all class cleanup functions. Normally called for you after
[724] Fix | Delete
tearDownClass."""
[725] Fix | Delete
cls.tearDown_exceptions = []
[726] Fix | Delete
while cls._class_cleanups:
[727] Fix | Delete
function, args, kwargs = cls._class_cleanups.pop()
[728] Fix | Delete
try:
[729] Fix | Delete
function(*args, **kwargs)
[730] Fix | Delete
except Exception as exc:
[731] Fix | Delete
cls.tearDown_exceptions.append(sys.exc_info())
[732] Fix | Delete
[733] Fix | Delete
def __call__(self, *args, **kwds):
[734] Fix | Delete
return self.run(*args, **kwds)
[735] Fix | Delete
[736] Fix | Delete
def debug(self):
[737] Fix | Delete
"""Run the test without collecting errors in a TestResult"""
[738] Fix | Delete
self.setUp()
[739] Fix | Delete
getattr(self, self._testMethodName)()
[740] Fix | Delete
self.tearDown()
[741] Fix | Delete
while self._cleanups:
[742] Fix | Delete
function, args, kwargs = self._cleanups.pop(-1)
[743] Fix | Delete
function(*args, **kwargs)
[744] Fix | Delete
[745] Fix | Delete
def skipTest(self, reason):
[746] Fix | Delete
"""Skip this test."""
[747] Fix | Delete
raise SkipTest(reason)
[748] Fix | Delete
[749] Fix | Delete
def fail(self, msg=None):
[750] Fix | Delete
"""Fail immediately, with the given message."""
[751] Fix | Delete
raise self.failureException(msg)
[752] Fix | Delete
[753] Fix | Delete
def assertFalse(self, expr, msg=None):
[754] Fix | Delete
"""Check that the expression is false."""
[755] Fix | Delete
if expr:
[756] Fix | Delete
msg = self._formatMessage(msg, "%s is not false" % safe_repr(expr))
[757] Fix | Delete
raise self.failureException(msg)
[758] Fix | Delete
[759] Fix | Delete
def assertTrue(self, expr, msg=None):
[760] Fix | Delete
"""Check that the expression is true."""
[761] Fix | Delete
if not expr:
[762] Fix | Delete
msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
[763] Fix | Delete
raise self.failureException(msg)
[764] Fix | Delete
[765] Fix | Delete
def _formatMessage(self, msg, standardMsg):
[766] Fix | Delete
"""Honour the longMessage attribute when generating failure messages.
[767] Fix | Delete
If longMessage is False this means:
[768] Fix | Delete
* Use only an explicit message if it is provided
[769] Fix | Delete
* Otherwise use the standard message for the assert
[770] Fix | Delete
[771] Fix | Delete
If longMessage is True:
[772] Fix | Delete
* Use the standard message
[773] Fix | Delete
* If an explicit message is provided, plus ' : ' and the explicit message
[774] Fix | Delete
"""
[775] Fix | Delete
if not self.longMessage:
[776] Fix | Delete
return msg or standardMsg
[777] Fix | Delete
if msg is None:
[778] Fix | Delete
return standardMsg
[779] Fix | Delete
try:
[780] Fix | Delete
# don't switch to '{}' formatting in Python 2.X
[781] Fix | Delete
# it changes the way unicode input is handled
[782] Fix | Delete
return '%s : %s' % (standardMsg, msg)
[783] Fix | Delete
except UnicodeDecodeError:
[784] Fix | Delete
return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
[785] Fix | Delete
[786] Fix | Delete
def assertRaises(self, expected_exception, *args, **kwargs):
[787] Fix | Delete
"""Fail unless an exception of class expected_exception is raised
[788] Fix | Delete
by the callable when invoked with specified positional and
[789] Fix | Delete
keyword arguments. If a different type of exception is
[790] Fix | Delete
raised, it will not be caught, and the test case will be
[791] Fix | Delete
deemed to have suffered an error, exactly as for an
[792] Fix | Delete
unexpected exception.
[793] Fix | Delete
[794] Fix | Delete
If called with the callable and arguments omitted, will return a
[795] Fix | Delete
context object used like this::
[796] Fix | Delete
[797] Fix | Delete
with self.assertRaises(SomeException):
[798] Fix | Delete
do_something()
[799] Fix | Delete
[800] Fix | Delete
An optional keyword argument 'msg' can be provided when assertRaises
[801] Fix | Delete
is used as a context object.
[802] Fix | Delete
[803] Fix | Delete
The context manager keeps a reference to the exception as
[804] Fix | Delete
the 'exception' attribute. This allows you to inspect the
[805] Fix | Delete
exception after the assertion::
[806] Fix | Delete
[807] Fix | Delete
with self.assertRaises(SomeException) as cm:
[808] Fix | Delete
do_something()
[809] Fix | Delete
the_exception = cm.exception
[810] Fix | Delete
self.assertEqual(the_exception.error_code, 3)
[811] Fix | Delete
"""
[812] Fix | Delete
context = _AssertRaisesContext(expected_exception, self)
[813] Fix | Delete
try:
[814] Fix | Delete
return context.handle('assertRaises', args, kwargs)
[815] Fix | Delete
finally:
[816] Fix | Delete
# bpo-23890: manually break a reference cycle
[817] Fix | Delete
context = None
[818] Fix | Delete
[819] Fix | Delete
def assertWarns(self, expected_warning, *args, **kwargs):
[820] Fix | Delete
"""Fail unless a warning of class warnClass is triggered
[821] Fix | Delete
by the callable when invoked with specified positional and
[822] Fix | Delete
keyword arguments. If a different type of warning is
[823] Fix | Delete
triggered, it will not be handled: depending on the other
[824] Fix | Delete
warning filtering rules in effect, it might be silenced, printed
[825] Fix | Delete
out, or raised as an exception.
[826] Fix | Delete
[827] Fix | Delete
If called with the callable and arguments omitted, will return a
[828] Fix | Delete
context object used like this::
[829] Fix | Delete
[830] Fix | Delete
with self.assertWarns(SomeWarning):
[831] Fix | Delete
do_something()
[832] Fix | Delete
[833] Fix | Delete
An optional keyword argument 'msg' can be provided when assertWarns
[834] Fix | Delete
is used as a context object.
[835] Fix | Delete
[836] Fix | Delete
The context manager keeps a reference to the first matching
[837] Fix | Delete
warning as the 'warning' attribute; similarly, the 'filename'
[838] Fix | Delete
and 'lineno' attributes give you information about the line
[839] Fix | Delete
of Python code from which the warning was triggered.
[840] Fix | Delete
This allows you to inspect the warning after the assertion::
[841] Fix | Delete
[842] Fix | Delete
with self.assertWarns(SomeWarning) as cm:
[843] Fix | Delete
do_something()
[844] Fix | Delete
the_warning = cm.warning
[845] Fix | Delete
self.assertEqual(the_warning.some_attribute, 147)
[846] Fix | Delete
"""
[847] Fix | Delete
context = _AssertWarnsContext(expected_warning, self)
[848] Fix | Delete
return context.handle('assertWarns', args, kwargs)
[849] Fix | Delete
[850] Fix | Delete
def assertLogs(self, logger=None, level=None):
[851] Fix | Delete
"""Fail unless a log message of level *level* or higher is emitted
[852] Fix | Delete
on *logger_name* or its children. If omitted, *level* defaults to
[853] Fix | Delete
INFO and *logger* defaults to the root logger.
[854] Fix | Delete
[855] Fix | Delete
This method must be used as a context manager, and will yield
[856] Fix | Delete
a recording object with two attributes: `output` and `records`.
[857] Fix | Delete
At the end of the context manager, the `output` attribute will
[858] Fix | Delete
be a list of the matching formatted log messages and the
[859] Fix | Delete
`records` attribute will be a list of the corresponding LogRecord
[860] Fix | Delete
objects.
[861] Fix | Delete
[862] Fix | Delete
Example::
[863] Fix | Delete
[864] Fix | Delete
with self.assertLogs('foo', level='INFO') as cm:
[865] Fix | Delete
logging.getLogger('foo').info('first message')
[866] Fix | Delete
logging.getLogger('foo.bar').error('second message')
[867] Fix | Delete
self.assertEqual(cm.output, ['INFO:foo:first message',
[868] Fix | Delete
'ERROR:foo.bar:second message'])
[869] Fix | Delete
"""
[870] Fix | Delete
return _AssertLogsContext(self, logger, level)
[871] Fix | Delete
[872] Fix | Delete
def _getAssertEqualityFunc(self, first, second):
[873] Fix | Delete
"""Get a detailed comparison function for the types of the two args.
[874] Fix | Delete
[875] Fix | Delete
Returns: A callable accepting (first, second, msg=None) that will
[876] Fix | Delete
raise a failure exception if first != second with a useful human
[877] Fix | Delete
readable error message for those types.
[878] Fix | Delete
"""
[879] Fix | Delete
#
[880] Fix | Delete
# NOTE(gregory.p.smith): I considered isinstance(first, type(second))
[881] Fix | Delete
# and vice versa. I opted for the conservative approach in case
[882] Fix | Delete
# subclasses are not intended to be compared in detail to their super
[883] Fix | Delete
# class instances using a type equality func. This means testing
[884] Fix | Delete
# subtypes won't automagically use the detailed comparison. Callers
[885] Fix | Delete
# should use their type specific assertSpamEqual method to compare
[886] Fix | Delete
# subclasses if the detailed comparison is desired and appropriate.
[887] Fix | Delete
# See the discussion in http://bugs.python.org/issue2578.
[888] Fix | Delete
#
[889] Fix | Delete
if type(first) is type(second):
[890] Fix | Delete
asserter = self._type_equality_funcs.get(type(first))
[891] Fix | Delete
if asserter is not None:
[892] Fix | Delete
if isinstance(asserter, str):
[893] Fix | Delete
asserter = getattr(self, asserter)
[894] Fix | Delete
return asserter
[895] Fix | Delete
[896] Fix | Delete
return self._baseAssertEqual
[897] Fix | Delete
[898] Fix | Delete
def _baseAssertEqual(self, first, second, msg=None):
[899] Fix | Delete
"""The default assertEqual implementation, not type specific."""
[900] Fix | Delete
if not first == second:
[901] Fix | Delete
standardMsg = '%s != %s' % _common_shorten_repr(first, second)
[902] Fix | Delete
msg = self._formatMessage(msg, standardMsg)
[903] Fix | Delete
raise self.failureException(msg)
[904] Fix | Delete
[905] Fix | Delete
def assertEqual(self, first, second, msg=None):
[906] Fix | Delete
"""Fail if the two objects are unequal as determined by the '=='
[907] Fix | Delete
operator.
[908] Fix | Delete
"""
[909] Fix | Delete
assertion_func = self._getAssertEqualityFunc(first, second)
[910] Fix | Delete
assertion_func(first, second, msg=msg)
[911] Fix | Delete
[912] Fix | Delete
def assertNotEqual(self, first, second, msg=None):
[913] Fix | Delete
"""Fail if the two objects are equal as determined by the '!='
[914] Fix | Delete
operator.
[915] Fix | Delete
"""
[916] Fix | Delete
if not first != second:
[917] Fix | Delete
msg = self._formatMessage(msg, '%s == %s' % (safe_repr(first),
[918] Fix | Delete
safe_repr(second)))
[919] Fix | Delete
raise self.failureException(msg)
[920] Fix | Delete
[921] Fix | Delete
def assertAlmostEqual(self, first, second, places=None, msg=None,
[922] Fix | Delete
delta=None):
[923] Fix | Delete
"""Fail if the two objects are unequal as determined by their
[924] Fix | Delete
difference rounded to the given number of decimal places
[925] Fix | Delete
(default 7) and comparing to zero, or by comparing that the
[926] Fix | Delete
difference between the two objects is more than the given
[927] Fix | Delete
delta.
[928] Fix | Delete
[929] Fix | Delete
Note that decimal places (from zero) are usually not the same
[930] Fix | Delete
as significant digits (measured from the most significant digit).
[931] Fix | Delete
[932] Fix | Delete
If the two objects compare equal then they will automatically
[933] Fix | Delete
compare almost equal.
[934] Fix | Delete
"""
[935] Fix | Delete
if first == second:
[936] Fix | Delete
# shortcut
[937] Fix | Delete
return
[938] Fix | Delete
if delta is not None and places is not None:
[939] Fix | Delete
raise TypeError("specify delta or places not both")
[940] Fix | Delete
[941] Fix | Delete
diff = abs(first - second)
[942] Fix | Delete
if delta is not None:
[943] Fix | Delete
if diff <= delta:
[944] Fix | Delete
return
[945] Fix | Delete
[946] Fix | Delete
standardMsg = '%s != %s within %s delta (%s difference)' % (
[947] Fix | Delete
safe_repr(first),
[948] Fix | Delete
safe_repr(second),
[949] Fix | Delete
safe_repr(delta),
[950] Fix | Delete
safe_repr(diff))
[951] Fix | Delete
else:
[952] Fix | Delete
if places is None:
[953] Fix | Delete
places = 7
[954] Fix | Delete
[955] Fix | Delete
if round(diff, places) == 0:
[956] Fix | Delete
return
[957] Fix | Delete
[958] Fix | Delete
standardMsg = '%s != %s within %r places (%s difference)' % (
[959] Fix | Delete
safe_repr(first),
[960] Fix | Delete
safe_repr(second),
[961] Fix | Delete
places,
[962] Fix | Delete
safe_repr(diff))
[963] Fix | Delete
msg = self._formatMessage(msg, standardMsg)
[964] Fix | Delete
raise self.failureException(msg)
[965] Fix | Delete
[966] Fix | Delete
def assertNotAlmostEqual(self, first, second, places=None, msg=None,
[967] Fix | Delete
delta=None):
[968] Fix | Delete
"""Fail if the two objects are equal as determined by their
[969] Fix | Delete
difference rounded to the given number of decimal places
[970] Fix | Delete
(default 7) and comparing to zero, or by comparing that the
[971] Fix | Delete
difference between the two objects is less than the given delta.
[972] Fix | Delete
[973] Fix | Delete
Note that decimal places (from zero) are usually not the same
[974] Fix | Delete
as significant digits (measured from the most significant digit).
[975] Fix | Delete
[976] Fix | Delete
Objects that are equal automatically fail.
[977] Fix | Delete
"""
[978] Fix | Delete
if delta is not None and places is not None:
[979] Fix | Delete
raise TypeError("specify delta or places not both")
[980] Fix | Delete
diff = abs(first - second)
[981] Fix | Delete
if delta is not None:
[982] Fix | Delete
if not (first == second) and diff > delta:
[983] Fix | Delete
return
[984] Fix | Delete
standardMsg = '%s == %s within %s delta (%s difference)' % (
[985] Fix | Delete
safe_repr(first),
[986] Fix | Delete
safe_repr(second),
[987] Fix | Delete
safe_repr(delta),
[988] Fix | Delete
safe_repr(diff))
[989] Fix | Delete
else:
[990] Fix | Delete
if places is None:
[991] Fix | Delete
places = 7
[992] Fix | Delete
if not (first == second) and round(diff, places) != 0:
[993] Fix | Delete
return
[994] Fix | Delete
standardMsg = '%s == %s within %r places' % (safe_repr(first),
[995] Fix | Delete
safe_repr(second),
[996] Fix | Delete
places)
[997] Fix | Delete
[998] Fix | Delete
msg = self._formatMessage(msg, standardMsg)
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function