summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/__main__.py18
-rw-r--r--Lib/unittest/test/test_assertions.py4
-rw-r--r--Lib/unittest/test/test_break.py4
-rw-r--r--Lib/unittest/test/test_case.py149
-rw-r--r--Lib/unittest/test/test_discovery.py104
-rw-r--r--Lib/unittest/test/test_functiontestcase.py4
-rw-r--r--Lib/unittest/test/test_loader.py6
-rw-r--r--Lib/unittest/test/test_result.py4
-rw-r--r--Lib/unittest/test/test_runner.py4
-rw-r--r--Lib/unittest/test/test_setups.py1
-rw-r--r--Lib/unittest/test/test_skipping.py4
-rw-r--r--Lib/unittest/test/testmock/__main__.py18
-rw-r--r--Lib/unittest/test/testmock/testcallable.py4
-rw-r--r--Lib/unittest/test/testmock/testhelpers.py18
-rw-r--r--Lib/unittest/test/testmock/testmagicmethods.py8
-rw-r--r--Lib/unittest/test/testmock/testmock.py11
-rw-r--r--Lib/unittest/test/testmock/testpatch.py1
-rw-r--r--Lib/unittest/test/testmock/testsentinel.py2
18 files changed, 328 insertions, 36 deletions
diff --git a/Lib/unittest/test/__main__.py b/Lib/unittest/test/__main__.py
new file mode 100644
index 0000000..44d0591
--- /dev/null
+++ b/Lib/unittest/test/__main__.py
@@ -0,0 +1,18 @@
+import os
+import unittest
+
+
+def load_tests(loader, standard_tests, pattern):
+ # top level directory cached on loader instance
+ this_dir = os.path.dirname(__file__)
+ pattern = pattern or "test_*.py"
+ # We are inside unittest.test, so the top-level is two notches up
+ top_level_dir = os.path.dirname(os.path.dirname(this_dir))
+ package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
+ top_level_dir=top_level_dir)
+ standard_tests.addTests(package_tests)
+ return standard_tests
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py
index 7931cad..af08d5a 100644
--- a/Lib/unittest/test/test_assertions.py
+++ b/Lib/unittest/test/test_assertions.py
@@ -361,3 +361,7 @@ class TestLongMessage(unittest.TestCase):
['^"regex" does not match "foo"$', '^oops$',
'^"regex" does not match "foo"$',
'^"regex" does not match "foo" : oops$'])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_break.py b/Lib/unittest/test/test_break.py
index 75532f4..0bf1a22 100644
--- a/Lib/unittest/test/test_break.py
+++ b/Lib/unittest/test/test_break.py
@@ -282,3 +282,7 @@ class TestBreakSignalIgnored(TestBreak):
"if threads have been used")
class TestBreakSignalDefault(TestBreak):
int_handler = signal.SIG_DFL
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 4987250..4b93179 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -1,8 +1,10 @@
+import contextlib
import difflib
import pprint
import pickle
import re
import sys
+import logging
import warnings
import weakref
import inspect
@@ -16,6 +18,12 @@ from .support import (
TestEquality, TestHashing, LoggingResult, LegacyLoggingResult,
ResultWithNoStartTestRunStopTestRun
)
+from test.support import captured_stderr
+
+
+log_foo = logging.getLogger('foo')
+log_foobar = logging.getLogger('foo.bar')
+log_quux = logging.getLogger('quux')
class Test(object):
@@ -399,7 +407,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
def test(self):
pass
- self.assertTrue(Foo('test').failureException is AssertionError)
+ self.assertIs(Foo('test').failureException, AssertionError)
# "This class attribute gives the exception raised by the test() method.
# If a test framework needs to use a specialized exception, possibly to
@@ -417,7 +425,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException = RuntimeError
- self.assertTrue(Foo('test').failureException is RuntimeError)
+ self.assertIs(Foo('test').failureException, RuntimeError)
Foo('test').run(result)
@@ -440,7 +448,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException = RuntimeError
- self.assertTrue(Foo('test').failureException is RuntimeError)
+ self.assertIs(Foo('test').failureException, RuntimeError)
Foo('test').run(result)
@@ -752,7 +760,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0]
else:
self.fail('assertSequenceEqual did not fail.')
- self.assertTrue(len(msg) < len(diff))
+ self.assertLess(len(msg), len(diff))
self.assertIn(omitted, msg)
self.maxDiff = len(diff) * 2
@@ -762,7 +770,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0]
else:
self.fail('assertSequenceEqual did not fail.')
- self.assertTrue(len(msg) > len(diff))
+ self.assertGreater(len(msg), len(diff))
self.assertNotIn(omitted, msg)
self.maxDiff = None
@@ -772,7 +780,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0]
else:
self.fail('assertSequenceEqual did not fail.')
- self.assertTrue(len(msg) > len(diff))
+ self.assertGreater(len(msg), len(diff))
self.assertNotIn(omitted, msg)
def testTruncateMessage(self):
@@ -821,18 +829,18 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
# set a lower threshold value and add a cleanup to restore it
old_threshold = self._diffThreshold
- self._diffThreshold = 2**8
+ self._diffThreshold = 2**5
self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold))
# under the threshold: diff marker (^) in error message
- s = 'x' * (2**7)
+ s = 'x' * (2**4)
with self.assertRaises(self.failureException) as cm:
self.assertEqual(s + 'a', s + 'b')
self.assertIn('^', str(cm.exception))
self.assertEqual(s + 'a', s + 'a')
# over the threshold: diff not used and marker (^) not in error message
- s = 'x' * (2**9)
+ s = 'x' * (2**6)
# if the path that uses difflib is taken, _truncateMessage will be
# called -- replace it with explodingTruncation to verify that this
# doesn't happen
@@ -849,6 +857,37 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
self.assertEqual(str(cm.exception), '%r != %r' % (s1, s2))
self.assertEqual(s + 'a', s + 'a')
+ def testAssertEqual_shorten(self):
+ # set a lower threshold value and add a cleanup to restore it
+ old_threshold = self._diffThreshold
+ self._diffThreshold = 0
+ self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold))
+
+ s = 'x' * 100
+ s1, s2 = s + 'a', s + 'b'
+ with self.assertRaises(self.failureException) as cm:
+ self.assertEqual(s1, s2)
+ c = 'xxxx[35 chars]' + 'x' * 61
+ self.assertEqual(str(cm.exception), "'%sa' != '%sb'" % (c, c))
+ self.assertEqual(s + 'a', s + 'a')
+
+ p = 'y' * 50
+ s1, s2 = s + 'a' + p, s + 'b' + p
+ with self.assertRaises(self.failureException) as cm:
+ self.assertEqual(s1, s2)
+ c = 'xxxx[85 chars]xxxxxxxxxxx'
+ #print()
+ #print(str(cm.exception))
+ self.assertEqual(str(cm.exception), "'%sa%s' != '%sb%s'" % (c, p, c, p))
+
+ p = 'y' * 100
+ s1, s2 = s + 'a' + p, s + 'b' + p
+ with self.assertRaises(self.failureException) as cm:
+ self.assertEqual(s1, s2)
+ c = 'xxxx[91 chars]xxxxx'
+ d = 'y' * 40 + '[56 chars]yyyy'
+ self.assertEqual(str(cm.exception), "'%sa%s' != '%sb%s'" % (c, d, c, d))
+
def testAssertCountEqual(self):
a = object()
self.assertCountEqual([1, 2, 3], [3, 2, 1])
@@ -1251,6 +1290,94 @@ test case
with self.assertWarnsRegex(RuntimeWarning, "o+"):
_runtime_warn("barz")
+ @contextlib.contextmanager
+ def assertNoStderr(self):
+ with captured_stderr() as buf:
+ yield
+ self.assertEqual(buf.getvalue(), "")
+
+ def assertLogRecords(self, records, matches):
+ self.assertEqual(len(records), len(matches))
+ for rec, match in zip(records, matches):
+ self.assertIsInstance(rec, logging.LogRecord)
+ for k, v in match.items():
+ self.assertEqual(getattr(rec, k), v)
+
+ def testAssertLogsDefaults(self):
+ # defaults: root logger, level INFO
+ with self.assertNoStderr():
+ with self.assertLogs() as cm:
+ log_foo.info("1")
+ log_foobar.debug("2")
+ self.assertEqual(cm.output, ["INFO:foo:1"])
+ self.assertLogRecords(cm.records, [{'name': 'foo'}])
+
+ def testAssertLogsTwoMatchingMessages(self):
+ # Same, but with two matching log messages
+ with self.assertNoStderr():
+ with self.assertLogs() as cm:
+ log_foo.info("1")
+ log_foobar.debug("2")
+ log_quux.warning("3")
+ self.assertEqual(cm.output, ["INFO:foo:1", "WARNING:quux:3"])
+ self.assertLogRecords(cm.records,
+ [{'name': 'foo'}, {'name': 'quux'}])
+
+ def checkAssertLogsPerLevel(self, level):
+ # Check level filtering
+ with self.assertNoStderr():
+ with self.assertLogs(level=level) as cm:
+ log_foo.warning("1")
+ log_foobar.error("2")
+ log_quux.critical("3")
+ self.assertEqual(cm.output, ["ERROR:foo.bar:2", "CRITICAL:quux:3"])
+ self.assertLogRecords(cm.records,
+ [{'name': 'foo.bar'}, {'name': 'quux'}])
+
+ def testAssertLogsPerLevel(self):
+ self.checkAssertLogsPerLevel(logging.ERROR)
+ self.checkAssertLogsPerLevel('ERROR')
+
+ def checkAssertLogsPerLogger(self, logger):
+ # Check per-logger fitering
+ with self.assertNoStderr():
+ with self.assertLogs(level='DEBUG') as outer_cm:
+ with self.assertLogs(logger, level='DEBUG') as cm:
+ log_foo.info("1")
+ log_foobar.debug("2")
+ log_quux.warning("3")
+ self.assertEqual(cm.output, ["INFO:foo:1", "DEBUG:foo.bar:2"])
+ self.assertLogRecords(cm.records,
+ [{'name': 'foo'}, {'name': 'foo.bar'}])
+ # The outer catchall caught the quux log
+ self.assertEqual(outer_cm.output, ["WARNING:quux:3"])
+
+ def testAssertLogsPerLogger(self):
+ self.checkAssertLogsPerLogger(logging.getLogger('foo'))
+ self.checkAssertLogsPerLogger('foo')
+
+ def testAssertLogsFailureNoLogs(self):
+ # Failure due to no logs
+ with self.assertNoStderr():
+ with self.assertRaises(self.failureException):
+ with self.assertLogs():
+ pass
+
+ def testAssertLogsFailureLevelTooHigh(self):
+ # Failure due to level too high
+ with self.assertNoStderr():
+ with self.assertRaises(self.failureException):
+ with self.assertLogs(level='WARNING'):
+ log_foo.info("1")
+
+ def testAssertLogsFailureMismatchingLogger(self):
+ # Failure due to mismatching logger (and the logged message is
+ # passed through)
+ with self.assertLogs('quux', level='ERROR'):
+ with self.assertRaises(self.failureException):
+ with self.assertLogs('foo'):
+ log_quux.error("1")
+
def testDeprecatedMethodNames(self):
"""
Test that the deprecated methods raise a DeprecationWarning. See #9424.
@@ -1405,3 +1532,7 @@ test case
with support.disable_gc():
del case
self.assertFalse(wr())
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py
index 11ec9ed..6b7b128 100644
--- a/Lib/unittest/test/test_discovery.py
+++ b/Lib/unittest/test/test_discovery.py
@@ -1,6 +1,8 @@
import os
import re
import sys
+import types
+import builtins
from test import support
import unittest
@@ -173,7 +175,7 @@ class TestDiscovery(unittest.TestCase):
self.addCleanup(restore_isdir)
_find_tests_args = []
- def _find_tests(start_dir, pattern):
+ def _find_tests(start_dir, pattern, namespace=None):
_find_tests_args.append((start_dir, pattern))
return ['tests']
loader._find_tests = _find_tests
@@ -366,7 +368,7 @@ class TestDiscovery(unittest.TestCase):
self.assertTrue(program.failfast)
self.assertTrue(program.catchbreak)
- def test_detect_module_clash(self):
+ def setup_module_clash(self):
class Module(object):
__file__ = 'bar/foo.py'
sys.modules['foo'] = Module
@@ -393,7 +395,10 @@ class TestDiscovery(unittest.TestCase):
os.listdir = listdir
os.path.isfile = isfile
os.path.isdir = isdir
+ return full_path
+ def test_detect_module_clash(self):
+ full_path = self.setup_module_clash()
loader = unittest.TestLoader()
mod_dir = os.path.abspath('bar')
@@ -406,6 +411,25 @@ class TestDiscovery(unittest.TestCase):
)
self.assertEqual(sys.path[0], full_path)
+ def test_module_symlink_ok(self):
+ full_path = self.setup_module_clash()
+
+ original_realpath = os.path.realpath
+
+ mod_dir = os.path.abspath('bar')
+ expected_dir = os.path.abspath('foo')
+
+ def cleanup():
+ os.path.realpath = original_realpath
+ self.addCleanup(cleanup)
+
+ def realpath(path):
+ if path == os.path.join(mod_dir, 'foo.py'):
+ return os.path.join(expected_dir, 'foo.py')
+ return path
+ os.path.realpath = realpath
+ loader = unittest.TestLoader()
+ loader.discover(start_dir='foo', pattern='foo.py')
def test_discovery_from_dotted_path(self):
loader = unittest.TestLoader()
@@ -414,7 +438,7 @@ class TestDiscovery(unittest.TestCase):
expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))
self.wasRun = False
- def _find_tests(start_dir, pattern):
+ def _find_tests(start_dir, pattern, namespace=None):
self.wasRun = True
self.assertEqual(start_dir, expectedPath)
return tests
@@ -424,5 +448,79 @@ class TestDiscovery(unittest.TestCase):
self.assertEqual(suite._tests, tests)
+ def test_discovery_from_dotted_path_builtin_modules(self):
+
+ loader = unittest.TestLoader()
+
+ listdir = os.listdir
+ os.listdir = lambda _: ['test_this_does_not_exist.py']
+ isfile = os.path.isfile
+ isdir = os.path.isdir
+ os.path.isdir = lambda _: False
+ orig_sys_path = sys.path[:]
+ def restore():
+ os.path.isfile = isfile
+ os.path.isdir = isdir
+ os.listdir = listdir
+ sys.path[:] = orig_sys_path
+ self.addCleanup(restore)
+
+ with self.assertRaises(TypeError) as cm:
+ loader.discover('sys')
+ self.assertEqual(str(cm.exception),
+ 'Can not use builtin modules '
+ 'as dotted module names')
+
+ def test_discovery_from_dotted_namespace_packages(self):
+ loader = unittest.TestLoader()
+
+ orig_import = __import__
+ package = types.ModuleType('package')
+ package.__path__ = ['/a', '/b']
+ package.__spec__ = types.SimpleNamespace(
+ loader=None,
+ submodule_search_locations=['/a', '/b']
+ )
+
+ def _import(packagename, *args, **kwargs):
+ sys.modules[packagename] = package
+ return package
+
+ def cleanup():
+ builtins.__import__ = orig_import
+ self.addCleanup(cleanup)
+ builtins.__import__ = _import
+
+ _find_tests_args = []
+ def _find_tests(start_dir, pattern, namespace=None):
+ _find_tests_args.append((start_dir, pattern))
+ return ['%s/tests' % start_dir]
+
+ loader._find_tests = _find_tests
+ loader.suiteClass = list
+ suite = loader.discover('package')
+ self.assertEqual(suite, ['/a/tests', '/b/tests'])
+
+ def test_discovery_failed_discovery(self):
+ loader = unittest.TestLoader()
+ package = types.ModuleType('package')
+ orig_import = __import__
+
+ def _import(packagename, *args, **kwargs):
+ sys.modules[packagename] = package
+ return package
+
+ def cleanup():
+ builtins.__import__ = orig_import
+ self.addCleanup(cleanup)
+ builtins.__import__ = _import
+
+ with self.assertRaises(TypeError) as cm:
+ loader.discover('package')
+ self.assertEqual(str(cm.exception),
+ 'don\'t know how to discover from {!r}'
+ .format(package))
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/unittest/test/test_functiontestcase.py b/Lib/unittest/test/test_functiontestcase.py
index 9ce5ee3..d7fe07a 100644
--- a/Lib/unittest/test/test_functiontestcase.py
+++ b/Lib/unittest/test/test_functiontestcase.py
@@ -142,3 +142,7 @@ class Test_FunctionTestCase(unittest.TestCase):
test = unittest.FunctionTestCase(lambda: None, description=desc)
self.assertEqual(test.shortDescription(), "this tests foo")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py
index f1f8ecd..b62a1b5 100644
--- a/Lib/unittest/test/test_loader.py
+++ b/Lib/unittest/test/test_loader.py
@@ -1305,4 +1305,8 @@ class Test_TestLoader(unittest.TestCase):
# "The default value is the TestSuite class"
def test_suiteClass__default_value(self):
loader = unittest.TestLoader()
- self.assertTrue(loader.suiteClass is unittest.TestSuite)
+ self.assertIs(loader.suiteClass, unittest.TestSuite)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py
index 6dd9bb0..489fe17 100644
--- a/Lib/unittest/test/test_result.py
+++ b/Lib/unittest/test/test_result.py
@@ -176,7 +176,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.failures[0]
- self.assertTrue(test_case is test)
+ self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str)
# "addError(test, err)"
@@ -224,7 +224,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.errors[0]
- self.assertTrue(test_case is test)
+ self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str)
def test_addSubTest(self):
diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py
index 5a91f1b..ef1c1af9 100644
--- a/Lib/unittest/test/test_runner.py
+++ b/Lib/unittest/test/test_runner.py
@@ -339,3 +339,7 @@ class Test_TextTestRunner(unittest.TestCase):
f = io.StringIO()
runner = unittest.TextTestRunner(f)
self.assertTrue(runner.stream.stream is f)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/test_setups.py b/Lib/unittest/test/test_setups.py
index bcd69a8..392f95e 100644
--- a/Lib/unittest/test/test_setups.py
+++ b/Lib/unittest/test/test_setups.py
@@ -501,5 +501,6 @@ class TestSetups(unittest.TestCase):
with self.assertRaisesRegex(Exception, msg):
suite.debug()
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
index 3556932..e18caa4 100644
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -221,3 +221,7 @@ class Test_TestSkipping(unittest.TestCase):
suite = unittest.TestSuite([test])
suite.run(result)
self.assertEqual(result.skipped, [(test, "testing")])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/testmock/__main__.py b/Lib/unittest/test/testmock/__main__.py
new file mode 100644
index 0000000..45c633a
--- /dev/null
+++ b/Lib/unittest/test/testmock/__main__.py
@@ -0,0 +1,18 @@
+import os
+import unittest
+
+
+def load_tests(loader, standard_tests, pattern):
+ # top level directory cached on loader instance
+ this_dir = os.path.dirname(__file__)
+ pattern = pattern or "test*.py"
+ # We are inside unittest.test.testmock, so the top-level is three notches up
+ top_level_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir)))
+ package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
+ top_level_dir=top_level_dir)
+ standard_tests.addTests(package_tests)
+ return standard_tests
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/Lib/unittest/test/testmock/testcallable.py b/Lib/unittest/test/testmock/testcallable.py
index 7b2dd00..5390a4e 100644
--- a/Lib/unittest/test/testmock/testcallable.py
+++ b/Lib/unittest/test/testmock/testcallable.py
@@ -145,3 +145,7 @@ class TestCallable(unittest.TestCase):
mock.wibble.assert_called_once_with()
self.assertRaises(TypeError, mock.wibble, 'some', 'args')
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py
index 8b2e96d..1dbc0b6 100644
--- a/Lib/unittest/test/testmock/testhelpers.py
+++ b/Lib/unittest/test/testmock/testhelpers.py
@@ -177,7 +177,7 @@ class CallTest(unittest.TestCase):
args = _Call(((1, 2, 3), {}))
self.assertEqual(args, call(1, 2, 3))
self.assertEqual(call(1, 2, 3), args)
- self.assertTrue(call(1, 2, 3) in [args])
+ self.assertIn(call(1, 2, 3), [args])
def test_call_ne(self):
@@ -812,7 +812,7 @@ class SpecSignatureTest(unittest.TestCase):
mock_property = foo.foo
# no spec on properties
- self.assertTrue(isinstance(mock_property, MagicMock))
+ self.assertIsInstance(mock_property, MagicMock)
mock_property(1, 2, 3)
mock_property.abc(4, 5, 6)
mock_property.assert_called_once_with(1, 2, 3)
@@ -845,19 +845,19 @@ class TestCallList(unittest.TestCase):
mock(b=6)
for kall in call(1, 2), call(a=3), call(3, 4), call(b=6):
- self.assertTrue(kall in mock.call_args_list)
+ self.assertIn(kall, mock.call_args_list)
calls = [call(a=3), call(3, 4)]
- self.assertTrue(calls in mock.call_args_list)
+ self.assertIn(calls, mock.call_args_list)
calls = [call(1, 2), call(a=3)]
- self.assertTrue(calls in mock.call_args_list)
+ self.assertIn(calls, mock.call_args_list)
calls = [call(3, 4), call(b=6)]
- self.assertTrue(calls in mock.call_args_list)
+ self.assertIn(calls, mock.call_args_list)
calls = [call(3, 4)]
- self.assertTrue(calls in mock.call_args_list)
+ self.assertIn(calls, mock.call_args_list)
- self.assertFalse(call('fish') in mock.call_args_list)
- self.assertFalse([call('fish')] in mock.call_args_list)
+ self.assertNotIn(call('fish'), mock.call_args_list)
+ self.assertNotIn([call('fish')], mock.call_args_list)
def test_call_list_str(self):
diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py
index 2bcf088..5ff158d 100644
--- a/Lib/unittest/test/testmock/testmagicmethods.py
+++ b/Lib/unittest/test/testmock/testmagicmethods.py
@@ -37,12 +37,12 @@ class TestMockingMagicMethods(unittest.TestCase):
return self, 'fish'
mock.__getitem__ = f
- self.assertFalse(mock.__getitem__ is f)
+ self.assertIsNot(mock.__getitem__, f)
self.assertEqual(mock['foo'], (mock, 'fish'))
self.assertEqual(mock.__getitem__('foo'), (mock, 'fish'))
mock.__getitem__ = mock
- self.assertTrue(mock.__getitem__ is mock)
+ self.assertIs(mock.__getitem__, mock)
def test_magic_methods_isolated_between_mocks(self):
@@ -212,8 +212,8 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(len(mock), 6)
mock.__contains__ = lambda s, o: o == 3
- self.assertTrue(3 in mock)
- self.assertFalse(6 in mock)
+ self.assertIn(3, mock)
+ self.assertNotIn(6, mock)
mock.__iter__ = lambda s: iter('foobarbaz')
self.assertEqual(list(mock), list('foobarbaz'))
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 904ef4e..20cc654 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -64,7 +64,7 @@ class MockTest(unittest.TestCase):
"method_calls not initialised correctly")
# Can't use hasattr for this test as it always returns True on a mock
- self.assertFalse('_items' in mock.__dict__,
+ self.assertNotIn('_items', mock.__dict__,
"default mock should not have '_items' attribute")
self.assertIsNone(mock._mock_parent,
@@ -565,19 +565,19 @@ class MockTest(unittest.TestCase):
pass
mock = Mock(spec=X)
- self.assertTrue(isinstance(mock, X))
+ self.assertIsInstance(mock, X)
mock = Mock(spec=X())
- self.assertTrue(isinstance(mock, X))
+ self.assertIsInstance(mock, X)
self.assertIs(mock.__class__, X)
self.assertEqual(Mock().__class__.__name__, 'Mock')
mock = Mock(spec_set=X)
- self.assertTrue(isinstance(mock, X))
+ self.assertIsInstance(mock, X)
mock = Mock(spec_set=X())
- self.assertTrue(isinstance(mock, X))
+ self.assertIsInstance(mock, X)
def test_setting_attribute_with_spec_set(self):
@@ -1386,6 +1386,5 @@ class MockTest(unittest.TestCase):
mock.foo
-
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py
index c1091b4..c1bc34f 100644
--- a/Lib/unittest/test/testmock/testpatch.py
+++ b/Lib/unittest/test/testmock/testpatch.py
@@ -1780,6 +1780,5 @@ class PatchTest(unittest.TestCase):
self.assertIs(os.path, path)
-
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/unittest/test/testmock/testsentinel.py b/Lib/unittest/test/testmock/testsentinel.py
index bfda68e..3fb5acb 100644
--- a/Lib/unittest/test/testmock/testsentinel.py
+++ b/Lib/unittest/test/testmock/testsentinel.py
@@ -17,7 +17,7 @@ class SentinelTest(unittest.TestCase):
def testDEFAULT(self):
- self.assertTrue(DEFAULT is sentinel.DEFAULT)
+ self.assertIs(DEFAULT, sentinel.DEFAULT)
def testBases(self):
# If this doesn't raise an AttributeError then help(mock) is broken