summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2024-04-03 12:19:49 (GMT)
committerGitHub <noreply@github.com>2024-04-03 12:19:49 (GMT)
commit33ee5cb3e92ea8798e7f1a2f3a13b92b39cee6d6 (patch)
treee9ae52885bb8f2c56a07b6b20b4ebb177ccb4ed7 /Lib/unittest
parent595bb496b0504429cf01a76fd1ada718d9dd25ca (diff)
downloadcpython-33ee5cb3e92ea8798e7f1a2f3a13b92b39cee6d6.zip
cpython-33ee5cb3e92ea8798e7f1a2f3a13b92b39cee6d6.tar.gz
cpython-33ee5cb3e92ea8798e7f1a2f3a13b92b39cee6d6.tar.bz2
GH-70647: Deprecate strptime day of month parsing without a year present to avoid leap-year bugs (GH-117107)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 001b640..36daa61 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -332,6 +332,23 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
self._raiseFailure("{} not triggered".format(exc_name))
+class _AssertNotWarnsContext(_AssertWarnsContext):
+
+ def __exit__(self, exc_type, exc_value, tb):
+ self.warnings_manager.__exit__(exc_type, exc_value, tb)
+ if exc_type is not None:
+ # let unexpected exceptions pass through
+ return
+ try:
+ exc_name = self.expected.__name__
+ except AttributeError:
+ exc_name = str(self.expected)
+ for m in self.warnings:
+ w = m.message
+ if isinstance(w, self.expected):
+ self._raiseFailure(f"{exc_name} triggered")
+
+
class _OrderedChainMap(collections.ChainMap):
def __iter__(self):
seen = set()
@@ -811,6 +828,11 @@ class TestCase(object):
context = _AssertWarnsContext(expected_warning, self)
return context.handle('assertWarns', args, kwargs)
+ def _assertNotWarns(self, expected_warning, *args, **kwargs):
+ """The opposite of assertWarns. Private due to low demand."""
+ context = _AssertNotWarnsContext(expected_warning, self)
+ return context.handle('_assertNotWarns', args, kwargs)
+
def assertLogs(self, logger=None, level=None):
"""Fail unless a log message of level *level* or higher is emitted
on *logger_name* or its children. If omitted, *level* defaults to