From 577473fe687b38c8f01b0c372d6d2563680045b3 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 19 Jan 2010 00:09:57 +0000 Subject: use assert[Not]In where appropriate A patch from Dave Malcolm. --- Lib/test/test_bigmem.py | 10 +++--- Lib/test/test_builtin.py | 28 ++++++++--------- Lib/test/test_bytes.py | 18 +++++------ Lib/test/test_cgi.py | 2 +- Lib/test/test_cmd_line.py | 12 ++++---- Lib/test/test_cmd_line_script.py | 8 ++--- Lib/test/test_collections.py | 11 ++++--- Lib/test/test_compile.py | 8 ++--- Lib/test/test_contains.py | 32 ++++++++++---------- Lib/test/test_copyreg.py | 4 +-- Lib/test/test_csv.py | 2 +- Lib/test/test_datetime.py | 4 +-- Lib/test/test_dbm.py | 6 ++-- Lib/test/test_dbm_dumb.py | 4 +-- Lib/test/test_dbm_gnu.py | 4 +-- Lib/test/test_dbm_ndbm.py | 2 +- Lib/test/test_decimal.py | 4 +-- Lib/test/test_defaultdict.py | 16 +++++----- Lib/test/test_deque.py | 6 ++-- Lib/test/test_descr.py | 30 +++++++++--------- Lib/test/test_dict.py | 8 +++++ Lib/test/test_dictviews.py | 22 +++++++------- Lib/test/test_exceptions.py | 4 +-- Lib/test/test_float.py | 5 +++ Lib/test/test_funcattrs.py | 4 +-- Lib/test/test_glob.py | 2 +- Lib/test/test_http_cookiejar.py | 54 +++++++++++++++++---------------- Lib/test/test_import.py | 4 +-- Lib/test/test_inspect.py | 50 +++++++++++++++--------------- Lib/test/test_ioctl.py | 4 +-- Lib/test/test_iter.py | 20 ++++++------ Lib/test/test_mmap.py | 2 +- Lib/test/test_multiprocessing.py | 16 +++++----- Lib/test/test_os.py | 2 +- Lib/test/test_peepholer.py | 62 +++++++++++++++++++------------------- Lib/test/test_pep352.py | 2 +- Lib/test/test_poplib.py | 2 +- Lib/test/test_posix.py | 2 +- Lib/test/test_posixpath.py | 8 ++--- Lib/test/test_pwd.py | 4 +-- Lib/test/test_pyclbr.py | 1 + Lib/test/test_pydoc.py | 6 ++-- Lib/test/test_raise.py | 4 +-- Lib/test/test_random.py | 4 +-- Lib/test/test_range.py | 40 ++++++++++++------------ Lib/test/test_reprlib.py | 2 +- Lib/test/test_runpy.py | 20 ++++++------ Lib/test/test_sax.py | 6 ++-- Lib/test/test_scope.py | 8 ++--- Lib/test/test_set.py | 62 +++++++++++++++++++------------------- Lib/test/test_site.py | 2 +- Lib/test/test_socket.py | 2 +- Lib/test/test_structseq.py | 4 +-- Lib/test/test_subprocess.py | 6 ++-- Lib/test/test_sys.py | 14 ++++----- Lib/test/test_tarfile.py | 2 +- Lib/test/test_telnetlib.py | 6 ++-- Lib/test/test_tempfile.py | 4 +-- Lib/test/test_threading.py | 2 +- Lib/test/test_threading_local.py | 2 +- Lib/test/test_traceback.py | 20 ++++++------ Lib/test/test_types.py | 4 +-- Lib/test/test_unicode.py | 52 ++++++++++++++++---------------- Lib/test/test_unicode_file.py | 2 +- Lib/test/test_unicodedata.py | 2 +- Lib/test/test_unittest.py | 4 +-- Lib/test/test_urllib2.py | 12 ++++---- Lib/test/test_userdict.py | 8 ++--- Lib/test/test_warnings.py | 2 +- Lib/test/test_weakref.py | 26 ++++++++-------- Lib/test/test_weakset.py | 46 ++++++++++++++-------------- Lib/test/test_wsgiref.py | 10 +++--- Lib/test/test_zipfile.py | 42 +++++++++++++------------- Lib/test/test_zipimport.py | 2 +- Lib/test/test_zipimport_support.py | 8 ++--- 75 files changed, 471 insertions(+), 454 deletions(-) diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 030ada5..843abb9 100644 --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -519,12 +519,12 @@ class BaseStrTest: edge = _('-') * (size // 2) s = _('').join([edge, SUBSTR, edge]) del edge - self.assertTrue(SUBSTR in s) + self.assertIn(SUBSTR, s) self.assertFalse(SUBSTR * 2 in s) - self.assertTrue(_('-') in s) + self.assertIn(_('-'), s) self.assertFalse(_('a') in s) s += _('a') - self.assertTrue(_('a') in s) + self.assertIn(_('a'), s) @bigmemtest(minsize=_2G + 10, memuse=2) def test_compare(self, size): @@ -768,7 +768,7 @@ class TupleTest(unittest.TestCase): def test_contains(self, size): t = (1, 2, 3, 4, 5) * size self.assertEquals(len(t), size * 5) - self.assertTrue(5 in t) + self.assertIn(5, t) self.assertFalse((1, 2, 3, 4, 5) in t) self.assertFalse(0 in t) @@ -917,7 +917,7 @@ class ListTest(unittest.TestCase): def test_contains(self, size): l = [1, 2, 3, 4, 5] * size self.assertEquals(len(l), size * 5) - self.assertTrue(5 in l) + self.assertIn(5, l) self.assertFalse([1, 2, 3, 4, 5] in l) self.assertFalse(0 in l) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 4ac9246..b4bdf11 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -248,11 +248,11 @@ class BuiltinTest(unittest.TestCase): # dir() - local scope local_var = 1 - self.assertTrue('local_var' in dir()) + self.assertIn('local_var', dir()) # dir(module) import sys - self.assertTrue('exit' in dir(sys)) + self.assertIn('exit', dir(sys)) # dir(module_with_invalid__dict__) import types @@ -262,8 +262,8 @@ class BuiltinTest(unittest.TestCase): self.assertRaises(TypeError, dir, f) # dir(type) - self.assertTrue("strip" in dir(str)) - self.assertTrue("__mro__" not in dir(str)) + self.assertIn("strip", dir(str)) + self.assertNotIn("__mro__", dir(str)) # dir(obj) class Foo(object): @@ -272,13 +272,13 @@ class BuiltinTest(unittest.TestCase): self.y = 8 self.z = 9 f = Foo() - self.assertTrue("y" in dir(f)) + self.assertIn("y", dir(f)) # dir(obj_no__dict__) class Foo(object): __slots__ = [] f = Foo() - self.assertTrue("__repr__" in dir(f)) + self.assertIn("__repr__", dir(f)) # dir(obj_no__class__with__dict__) # (an ugly trick to cause getattr(f, "__class__") to fail) @@ -287,8 +287,8 @@ class BuiltinTest(unittest.TestCase): def __init__(self): self.bar = "wow" f = Foo() - self.assertTrue("__repr__" not in dir(f)) - self.assertTrue("bar" in dir(f)) + self.assertNotIn("__repr__", dir(f)) + self.assertIn("bar", dir(f)) # dir(obj_using __dir__) class Foo(object): @@ -914,18 +914,18 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2]) seq = list(range(a, b, c)) - self.assertTrue(a in seq) - self.assertTrue(b not in seq) + self.assertIn(a, seq) + self.assertNotIn(b, seq) self.assertEqual(len(seq), 2) seq = list(range(b, a, -c)) - self.assertTrue(b in seq) - self.assertTrue(a not in seq) + self.assertIn(b, seq) + self.assertNotIn(a, seq) self.assertEqual(len(seq), 2) seq = list(range(-a, -b, -c)) - self.assertTrue(-a in seq) - self.assertTrue(-b not in seq) + self.assertIn(-a, seq) + self.assertNotIn(-b, seq) self.assertEqual(len(seq), 2) self.assertRaises(TypeError, range) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 2813d96..f05bd96 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -229,8 +229,8 @@ class BaseBytesTest(unittest.TestCase): def test_contains(self): b = self.type2test(b"abc") - self.assertTrue(ord('a') in b) - self.assertTrue(int(ord('a')) in b) + self.assertIn(ord('a'), b) + self.assertIn(int(ord('a')), b) self.assertFalse(200 in b) self.assertFalse(200 in b) self.assertRaises(ValueError, lambda: 300 in b) @@ -239,13 +239,13 @@ class BaseBytesTest(unittest.TestCase): self.assertRaises(TypeError, lambda: float(ord('a')) in b) self.assertRaises(TypeError, lambda: "a" in b) for f in bytes, bytearray: - self.assertTrue(f(b"") in b) - self.assertTrue(f(b"a") in b) - self.assertTrue(f(b"b") in b) - self.assertTrue(f(b"c") in b) - self.assertTrue(f(b"ab") in b) - self.assertTrue(f(b"bc") in b) - self.assertTrue(f(b"abc") in b) + self.assertIn(f(b""), b) + self.assertIn(f(b"a"), b) + self.assertIn(f(b"b"), b) + self.assertIn(f(b"c"), b) + self.assertIn(f(b"ab"), b) + self.assertIn(f(b"bc"), b) + self.assertIn(f(b"abc"), b) self.assertFalse(f(b"ac") in b) self.assertFalse(f(b"d") in b) self.assertFalse(f(b"dab") in b) diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index ef7dfa5..a77abf0 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -143,7 +143,7 @@ class CgiTests(unittest.TestCase): # test individual fields for key in expect.keys(): expect_val = expect[key] - self.assertTrue(key in fs) + self.assertIn(key, fs) if len(expect_val) > 1: self.assertEqual(fs.getvalue(key), expect_val) else: diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 852a7aa..b03a0ba 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -49,7 +49,7 @@ class CmdLineTest(unittest.TestCase): def verify_valid_flag(self, cmd_line): data = self.start_python(cmd_line) self.assertTrue(data == b'' or data.endswith(b'\n')) - self.assertTrue(b'Traceback' not in data) + self.assertNotIn(b'Traceback', data) def test_optimize(self): self.verify_valid_flag('-O') @@ -65,7 +65,7 @@ class CmdLineTest(unittest.TestCase): self.verify_valid_flag('-S') def test_usage(self): - self.assertTrue(b'usage' in self.start_python('-h')) + self.assertIn(b'usage', self.start_python('-h')) def test_version(self): version = ('Python %d.%d' % sys.version_info[:2]).encode("ascii") @@ -77,10 +77,10 @@ class CmdLineTest(unittest.TestCase): # codec), a recursion loop can occur. data, rc = self.start_python_and_exit_code('-v') self.assertEqual(rc, 0) - self.assertTrue(b'stack overflow' not in data) + self.assertNotIn(b'stack overflow', data) data, rc = self.start_python_and_exit_code('-vv') self.assertEqual(rc, 0) - self.assertTrue(b'stack overflow' not in data) + self.assertNotIn(b'stack overflow', data) def test_run_module(self): # Test expected operation of the '-m' switch @@ -166,8 +166,8 @@ class CmdLineTest(unittest.TestCase): p = _spawn_python_with_env('-S', '-c', 'import sys; print(sys.path)') stdout, _ = p.communicate() - self.assertTrue(path1.encode('ascii') in stdout) - self.assertTrue(path2.encode('ascii') in stdout) + self.assertIn(path1.encode('ascii'), stdout) + self.assertIn(path2.encode('ascii'), stdout) def test_main(): diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index e6d6ffb..bb3a74f 100644 --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -80,9 +80,9 @@ class CmdLineTest(unittest.TestCase): print(printed_file) print(printed_package) print(printed_argv0) - self.assertTrue(printed_file.encode('utf-8') in data) - self.assertTrue(printed_package.encode('utf-8') in data) - self.assertTrue(printed_argv0.encode('utf-8') in data) + self.assertIn(printed_file.encode('utf-8'), data) + self.assertIn(printed_package.encode('utf-8'), data) + self.assertIn(printed_argv0.encode('utf-8'), data) def _check_import_error(self, script_name, expected_msg, *cmd_line_switches): @@ -92,7 +92,7 @@ class CmdLineTest(unittest.TestCase): print('Output from test script %r:' % script_name) print(data) print('Expected output: %r' % expected_msg) - self.assertTrue(expected_msg.encode('utf-8') in data) + self.assertIn(expected_msg.encode('utf-8'), data) def test_basic_script(self): with temp_dir() as script_dir: diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index ded8b70..1c3d4fe 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -44,9 +44,9 @@ class TestNamedTuple(unittest.TestCase): namedtuple('_', 'a b c') # Test leading underscores in a typename nt = namedtuple('nt', 'the quick brown fox') # check unicode input - self.assertTrue("u'" not in repr(nt._fields)) + self.assertNotIn("u'", repr(nt._fields)) nt = namedtuple('nt', ('the', 'quick')) # check unicode input - self.assertTrue("u'" not in repr(nt._fields)) + self.assertNotIn("u'", repr(nt._fields)) self.assertRaises(TypeError, Point._make, [11]) # catch too few args self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args @@ -75,8 +75,8 @@ class TestNamedTuple(unittest.TestCase): self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals()) # wrong keyword argument self.assertRaises(TypeError, eval, 'Point(x=1)', locals()) # missing keyword argument self.assertEqual(repr(p), 'Point(x=11, y=22)') - self.assertTrue('__dict__' not in dir(p)) # verify instance has no dict - self.assertTrue('__weakref__' not in dir(p)) + self.assertNotIn('__dict__', dir(p)) # verify instance has no dict + self.assertNotIn('__weakref__', dir(p)) self.assertEqual(p, Point._make([11, 22])) # test _make classmethod self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method @@ -598,6 +598,7 @@ class TestCounter(unittest.TestCase): c = Counter(a=10, b=-2, c=0) for elem in c: self.assertTrue(elem in c) + self.assertIn(elem, c) def test_multiset_operations(self): # Verify that adding a zero counter will strip zeros and negatives @@ -697,7 +698,7 @@ class TestOrderedDict(unittest.TestCase): pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] od = OrderedDict(pairs) del od['a'] - self.assertTrue('a' not in od) + self.assertNotIn('a', od) with self.assertRaises(KeyError): del od['a'] self.assertEqual(list(od.items()), pairs[:2] + pairs[3:]) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 563a7ee..af4572f 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -389,10 +389,10 @@ if 1: import __mangled_mod import __package__.module - self.assertTrue("_A__mangled" in A.f.__code__.co_varnames) - self.assertTrue("__not_mangled__" in A.f.__code__.co_varnames) - self.assertTrue("_A__mangled_mod" in A.f.__code__.co_varnames) - self.assertTrue("__package__" in A.f.__code__.co_varnames) + self.assertIn("_A__mangled", A.f.__code__.co_varnames) + self.assertIn("__not_mangled__", A.f.__code__.co_varnames) + self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames) + self.assertIn("__package__", A.f.__code__.co_varnames) def test_compile_ast(self): fname = __file__ diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py index 622dfd4..a667a16 100644 --- a/Lib/test/test_contains.py +++ b/Lib/test/test_contains.py @@ -20,19 +20,19 @@ class TestContains(unittest.TestCase): a = base_set(1) b = myset(1) c = seq(1) - self.assertTrue(1 in b) - self.assertTrue(0 not in b) - self.assertTrue(1 in c) - self.assertTrue(0 not in c) + self.assertIn(1, b) + self.assertNotIn(0, b) + self.assertIn(1, c) + self.assertNotIn(0, c) self.assertRaises(TypeError, lambda: 1 in a) self.assertRaises(TypeError, lambda: 1 not in a) # test char in string - self.assertTrue('c' in 'abc') - self.assertTrue('d' not in 'abc') + self.assertIn('c', 'abc') + self.assertNotIn('d', 'abc') - self.assertTrue('' in '') - self.assertTrue('' in 'abc') + self.assertIn('', '') + self.assertIn('', 'abc') self.assertRaises(TypeError, lambda: None in 'abc') @@ -40,15 +40,15 @@ class TestContains(unittest.TestCase): # a collection of tests on builtin sequence types a = range(10) for i in a: - self.assertTrue(i in a) - self.assertTrue(16 not in a) - self.assertTrue(a not in a) + self.assertIn(i, a) + self.assertNotIn(16, a) + self.assertNotIn(a, a) a = tuple(a) for i in a: - self.assertTrue(i in a) - self.assertTrue(16 not in a) - self.assertTrue(a not in a) + self.assertIn(i, a) + self.assertNotIn(16, a) + self.assertNotIn(a, a) class Deviant1: """Behaves strangely when compared @@ -64,7 +64,7 @@ class TestContains(unittest.TestCase): self.aList.remove(14) return 0 - self.assertTrue(Deviant1() not in Deviant1.aList) + self.assertNotIn(Deviant1(), Deviant1.aList) def test_nonreflexive(self): # containment and equality tests involving elements that are @@ -81,7 +81,7 @@ class TestContains(unittest.TestCase): for constructor in constructors: container = constructor(values) for elem in container: - self.assertTrue(elem in container) + self.assertIn(elem, container) self.assertTrue(container == constructor(values)) self.assertTrue(container == container) diff --git a/Lib/test/test_copyreg.py b/Lib/test/test_copyreg.py index 4fb89d0..8359e28 100644 --- a/Lib/test/test_copyreg.py +++ b/Lib/test/test_copyreg.py @@ -54,7 +54,7 @@ class CopyRegTestCase(unittest.TestCase): self.assertTrue(copyreg._extension_registry[mod, func] == code) self.assertTrue(copyreg._inverted_registry[code] == (mod, func)) # Shouldn't be in the cache. - self.assertTrue(code not in copyreg._extension_cache) + self.assertNotIn(code, copyreg._extension_cache) # Redundant registration should be OK. copyreg.add_extension(mod, func, code) # shouldn't blow up # Conflicting code. @@ -81,7 +81,7 @@ class CopyRegTestCase(unittest.TestCase): e.restore() # Shouldn't be there anymore. - self.assertTrue((mod, func) not in copyreg._extension_registry) + self.assertNotIn((mod, func), copyreg._extension_registry) # The code *may* be in copyreg._extension_registry, though, if # we happened to pick on a registered code. So don't check for # that. diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 75d1a91..29e54f7 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -811,7 +811,7 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back # given that all three lines in sample3 are equal, # I think that any character could have been 'guessed' as the # delimiter, depending on dictionary order - self.assertTrue(dialect.delimiter in self.sample3) + self.assertIn(dialect.delimiter, self.sample3) dialect = sniffer.sniff(self.sample3, delimiters="?,") self.assertEqual(dialect.delimiter, "?") dialect = sniffer.sniff(self.sample3, delimiters="/,") diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index 74736bc..01a031a 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -139,10 +139,10 @@ class HarmlessMixedComparison: self.assertFalse(() == me) self.assertTrue(() != me) - self.assertTrue(me in [1, 20, [], me]) + self.assertIn(me, [1, 20, [], me]) self.assertFalse(me not in [1, 20, [], me]) - self.assertTrue([] in [me, 1, 20, []]) + self.assertIn([], [me, 1, 20, []]) self.assertFalse([] not in [me, 1, 20, []]) def test_harmful_mixed_comparison(self): diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index 818be45..2008776 100644 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -131,7 +131,7 @@ class WhichDBTestCase(unittest.TestCase): f = module.open(_fname, 'w') f[b"1"] = b"1" # and test that we can find it - self.assertTrue(b"1" in f) + self.assertIn(b"1", f) # and read it self.assertTrue(f[b"1"] == b"1") f.close() @@ -154,9 +154,9 @@ class WhichDBTestCase(unittest.TestCase): self.d[k] = v self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a)) for k, v in a: - self.assertTrue(k in self.d) + self.assertIn(k, self.d) self.assertEqual(self.d[k], v) - self.assertTrue(b'xxx' not in self.d) + self.assertNotIn(b'xxx', self.d) self.assertRaises(KeyError, lambda: self.d[b'xxx']) self.d.close() diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index 956eec6..7a1a16e 100644 --- a/Lib/test/test_dbm_dumb.py +++ b/Lib/test/test_dbm_dumb.py @@ -93,7 +93,7 @@ class DumbDBMTestCase(unittest.TestCase): def test_write_contains(self): f = dumbdbm.open(_fname) f[b'1'] = b'hello' - self.assertTrue(b'1' in f) + self.assertIn(b'1', f) f.close() def test_write_write_read(self): @@ -118,7 +118,7 @@ class DumbDBMTestCase(unittest.TestCase): f['1'] = 'a' f.close() f = dumbdbm.open(_fname, 'r') - self.assertTrue('\u00fc' in f) + self.assertIn('\u00fc', f) self.assertEqual(f['\u00fc'.encode('utf-8')], self._dict['\u00fc'.encode('utf-8')]) self.assertEqual(f[b'1'], b'a') diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py index 2173b92..dad56e6 100755 --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -24,11 +24,11 @@ class TestGdbm(unittest.TestCase): self.g[b'bytes'] = b'data' key_set = set(self.g.keys()) self.assertEqual(key_set, set([b'a', b'bytes', b'12345678910'])) - self.assertTrue(b'a' in self.g) + self.assertIn(b'a', self.g) self.assertEqual(self.g[b'bytes'], b'data') key = self.g.firstkey() while key: - self.assertTrue(key in key_set) + self.assertIn(key, key_set) key_set.remove(key) key = self.g.nextkey(key) self.assertRaises(KeyError, lambda: self.g['xxx']) diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py index 141d4b3..00dcbd2 100755 --- a/Lib/test/test_dbm_ndbm.py +++ b/Lib/test/test_dbm_ndbm.py @@ -24,7 +24,7 @@ class DbmTestCase(unittest.TestCase): self.d[b'bytes'] = b'data' self.d['12345678910'] = '019237410982340912840198242' self.d.keys() - self.assertTrue(b'a' in self.d) + self.assertIn(b'a', self.d) self.assertEqual(self.d[b'bytes'], b'data') self.d.close() diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 59757f7..cafcf0b 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -1673,8 +1673,8 @@ class ContextAPItests(unittest.TestCase): self.assertEqual(v1, v2) def test_equality_with_other_types(self): - self.assertTrue(Decimal(10) in ['a', 1.0, Decimal(10), (1,2), {}]) - self.assertTrue(Decimal(10) not in ['a', 1.0, (1,2), {}]) + self.assertIn(Decimal(10), ['a', 1.0, Decimal(10), (1,2), {}]) + self.assertNotIn(Decimal(10), ['a', 1.0, (1,2), {}]) def test_copy(self): # All copies should be deep diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index e5a9bd5..da2608a 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -32,14 +32,14 @@ class TestDefaultDict(unittest.TestCase): self.assertEqual(d2["foo"], 1) self.assertEqual(d2["bar"], 2) self.assertEqual(d2[42], []) - self.assertTrue("foo" in d2) - self.assertTrue("foo" in d2.keys()) - self.assertTrue("bar" in d2) - self.assertTrue("bar" in d2.keys()) - self.assertTrue(42 in d2) - self.assertTrue(42 in d2.keys()) - self.assertTrue(12 not in d2) - self.assertTrue(12 not in d2.keys()) + self.assertIn("foo", d2) + self.assertIn("foo", d2.keys()) + self.assertIn("bar", d2) + self.assertIn("bar", d2.keys()) + self.assertIn(42, d2) + self.assertIn(42, d2.keys()) + self.assertNotIn(12, d2) + self.assertNotIn(12, d2.keys()) d2.default_factory = None self.assertEqual(d2.default_factory, None) try: diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 8120e8b..874c343 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -199,9 +199,9 @@ class TestBasic(unittest.TestCase): self.assertEqual(len(d), n-i) j = random.randrange(-len(d), len(d)) val = d[j] - self.assertTrue(val in d) + self.assertIn(val, d) del d[j] - self.assertTrue(val not in d) + self.assertNotIn(val, d) self.assertEqual(len(d), 0) def test_reverse(self): @@ -328,7 +328,7 @@ class TestBasic(unittest.TestCase): e = eval(repr(d)) self.assertEqual(list(d), list(e)) d.append(d) - self.assertTrue('...' in repr(d)) + self.assertIn('...', repr(d)) def test_print(self): d = deque(range(200)) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 8e45bcf..57b69e6 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -500,7 +500,7 @@ class ClassPropertiesAndMethods(unittest.TestCase): return 42 self.assertEqual(C.name, 'C') self.assertEqual(C.bases, ()) - self.assertTrue('spam' in C.dict) + self.assertIn('spam', C.dict) c = C() self.assertEqual(c.spam(), 42) @@ -1651,9 +1651,9 @@ order (MRO) for bases """ # depending on whether this test is run standalone or from a framework. self.assertTrue(str(c1).find('C object at ') >= 0) self.assertEqual(str(c1), repr(c1)) - self.assertTrue(-1 not in c1) + self.assertNotIn(-1, c1) for i in range(10): - self.assertTrue(i in c1) + self.assertIn(i, c1) self.assertFalse(10 in c1) # Test the default behavior for dynamic classes class D(object): @@ -1674,9 +1674,9 @@ order (MRO) for bases """ # depending on whether this test is run standalone or from a framework. self.assertTrue(str(d1).find('D object at ') >= 0) self.assertEqual(str(d1), repr(d1)) - self.assertTrue(-1 not in d1) + self.assertNotIn(-1, d1) for i in range(10): - self.assertTrue(i in d1) + self.assertIn(i, d1) self.assertFalse(10 in d1) # Test overridden behavior class Proxy(object): @@ -1723,7 +1723,7 @@ order (MRO) for bases """ p10 = Proxy(range(10)) self.assertFalse(-1 in p10) for i in range(10): - self.assertTrue(i in p10) + self.assertIn(i, p10) self.assertFalse(10 in p10) def test_weakrefs(self): @@ -1784,10 +1784,10 @@ order (MRO) for bases """ self.assertTrue(isinstance(raw, property)) attrs = dir(raw) - self.assertTrue("__doc__" in attrs) - self.assertTrue("fget" in attrs) - self.assertTrue("fset" in attrs) - self.assertTrue("fdel" in attrs) + self.assertIn("__doc__", attrs) + self.assertIn("fget", attrs) + self.assertIn("fset", attrs) + self.assertIn("fdel", attrs) self.assertEqual(raw.__doc__, "I'm the x property.") self.assertTrue(raw.fget is C.__dict__['getx']) @@ -2012,12 +2012,12 @@ order (MRO) for bases """ c = C() self.assertEqual(interesting(dir(c)), cstuff) - ## self.assertTrue('__self__' in dir(C.Cmethod)) + ## self.assertIn('__self__', dir(C.Cmethod)) c.cdata = 2 c.cmethod = lambda self: 0 self.assertEqual(interesting(dir(c)), cstuff + ['cdata', 'cmethod']) - ## self.assertTrue('__self__' in dir(c.Cmethod)) + ## self.assertIn('__self__', dir(c.Cmethod)) class A(C): Adata = 1 @@ -2025,13 +2025,13 @@ order (MRO) for bases """ astuff = ['Adata', 'Amethod'] + cstuff self.assertEqual(interesting(dir(A)), astuff) - ## self.assertTrue('__self__' in dir(A.Amethod)) + ## self.assertIn('__self__', dir(A.Amethod)) a = A() self.assertEqual(interesting(dir(a)), astuff) a.adata = 42 a.amethod = lambda self: 3 self.assertEqual(interesting(dir(a)), astuff + ['adata', 'amethod']) - ## self.assertTrue('__self__' in dir(a.Amethod)) + ## self.assertIn('__self__', dir(a.Amethod)) # Try a module subclass. import sys @@ -2583,7 +2583,7 @@ order (MRO) for bases """ self.assertEqual(d[cistr('one')], 1) self.assertEqual(d[cistr('tWo')], 2) self.assertEqual(d[cistr('THrEE')], 3) - self.assertTrue(cistr('ONe') in d) + self.assertIn(cistr('ONe'), d) self.assertEqual(d.get(cistr('thrEE')), 3) def test_classic_comparisons(self): diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 8984334..919fce8 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -35,7 +35,9 @@ class DictTest(unittest.TestCase): d = {'a': 1, 'b': 2} k = d.keys() self.assertTrue('a' in d) + self.assertIn('a', d) self.assertTrue('b' in d) + self.assertIn('b', d) self.assertRaises(TypeError, d.keys, None) self.assertEqual(repr(dict(a=1).keys()), "dict_keys(['a'])") @@ -60,10 +62,14 @@ class DictTest(unittest.TestCase): d = {} self.assertTrue(not ('a' in d)) self.assertTrue('a' not in d) + self.assertNotIn('a', d) d = {'a': 1, 'b': 2} self.assertTrue('a' in d) + self.assertIn('a', d) self.assertTrue('b' in d) + self.assertIn('b', d) self.assertTrue('c' not in d) + self.assertNotIn('c', d) self.assertRaises(TypeError, d.__contains__) @@ -519,7 +525,9 @@ class DictTest(unittest.TestCase): self.assertEqual(d[1], 2) self.assertEqual(d[3], 4) self.assertTrue(2 not in d) + self.assertNotIn(2, d) self.assertTrue(2 not in d.keys()) + self.assertNotIn(2, d.keys()) self.assertEqual(d[2], 42) class E(dict): def __missing__(self, key): diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py index 4fee755..4d12647 100644 --- a/Lib/test/test_dictviews.py +++ b/Lib/test/test_dictviews.py @@ -24,10 +24,10 @@ class DictSetTest(unittest.TestCase): self.assertNotEqual(keys, {1, "b"}) self.assertNotEqual(keys, {1}) self.assertNotEqual(keys, 42) - self.assertTrue(1 in keys) - self.assertTrue("a" in keys) - self.assertTrue(10 not in keys) - self.assertTrue("Z" not in keys) + self.assertIn(1, keys) + self.assertIn("a", keys) + self.assertNotIn(10, keys) + self.assertNotIn("Z", keys) self.assertEqual(d.keys(), d.keys()) e = {1: 11, "a": "def"} self.assertEqual(d.keys(), e.keys()) @@ -44,13 +44,13 @@ class DictSetTest(unittest.TestCase): self.assertNotEqual(items, {(1, 10), ("a", "def")}) self.assertNotEqual(items, {(1, 10)}) self.assertNotEqual(items, 42) - self.assertTrue((1, 10) in items) - self.assertTrue(("a", "ABC") in items) - self.assertTrue((1, 11) not in items) - self.assertTrue(1 not in items) - self.assertTrue(() not in items) - self.assertTrue((1,) not in items) - self.assertTrue((1, 2, 3) not in items) + self.assertIn((1, 10), items) + self.assertIn(("a", "ABC"), items) + self.assertNotIn((1, 11), items) + self.assertNotIn(1, items) + self.assertNotIn((), items) + self.assertNotIn((1,), items) + self.assertNotIn((1, 2, 3), items) self.assertEqual(d.items(), d.items()) e = d.copy() self.assertEqual(d.items(), e.items()) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 5be6757..c3be3f3 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -337,7 +337,7 @@ class ExceptionTests(unittest.TestCase): try: Exception().__traceback__ = 5 except TypeError as e: - self.assertTrue("__traceback__ must be a traceback" in str(e)) + self.assertIn("__traceback__ must be a traceback", str(e)) else: self.fail("No exception raised") @@ -597,7 +597,7 @@ class ExceptionTests(unittest.TestCase): return sys.exc_info() e, v, tb = g() self.assertTrue(isinstance(v, RuntimeError), type(v)) - self.assertTrue("maximum recursion depth exceeded" in str(v), str(v)) + self.assertIn("maximum recursion depth exceeded", str(v)) def test_MemoryError(self): diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index fd0f410..db397ce 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -213,11 +213,16 @@ class GeneralFloatCases(unittest.TestCase): def test_float_containment(self): floats = (INF, -INF, 0.0, 1.0, NAN) for f in floats: + self.assertIn(f, [f]) self.assertTrue(f in [f], "'%r' not in []" % f) + self.assertIn(f, (f,)) self.assertTrue(f in (f,), "'%r' not in ()" % f) + self.assertIn(f, {f}) self.assertTrue(f in {f}, "'%r' not in set()" % f) + self.assertIn(f, {f: None}) self.assertTrue(f in {f: None}, "'%r' not in {}" % f) self.assertEqual([f].count(f), 1, "[].count('%r') != 1" % f) + self.assertIn(f, floats) self.assertTrue(f in floats, "'%r' not in container" % f) for f in floats: diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index d1d03a3..4ddd254 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -35,11 +35,11 @@ class FunctionPropertiesTest(FuncAttrsTest): def test_dir_includes_correct_attrs(self): self.b.known_attr = 7 - self.assertTrue('known_attr' in dir(self.b), + self.assertIn('known_attr', dir(self.b), "set attributes not in dir listing of method") # Test on underlying function object of method self.F.a.known_attr = 7 - self.assertTrue('known_attr' in dir(self.fi.a), "set attribute on function " + self.assertIn('known_attr', dir(self.fi.a), "set attribute on function " "implementations, should show up in next dir") def test_duplicate_function_equality(self): diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index adaea18..5a3be94 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -96,7 +96,7 @@ class GlobTests(unittest.TestCase): res = glob.glob(self.tempdir + '*' + os.sep) self.assertEqual(len(res), 1) # either of these results are reasonable - self.assertTrue(res[0] in [self.tempdir, self.tempdir + os.sep]) + self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) def test_glob_broken_symlinks(self): if hasattr(os, 'symlink'): diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py index e5f7143..f244b2b 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -441,8 +441,8 @@ class CookieTests(TestCase): interact_netscape(c, "http://www.acme.com/", 'version=eggs; spam=eggs') cookies = c._cookies["www.acme.com"]["/"] - self.assertTrue('expires' in cookies) - self.assertTrue('version' in cookies) + self.assertIn('expires', cookies) + self.assertIn('version', cookies) def test_expires(self): # if expires is in future, keep cookie... @@ -457,7 +457,8 @@ class CookieTests(TestCase): now) h = interact_netscape(c, "http://www.acme.com/") self.assertEquals(len(c), 1) - self.assertTrue('spam="bar"' in h and "foo" not in h) + self.assertIn('spam="bar"', h) + self.assertNotIn("foo", h) # max-age takes precedence over expires, and zero max-age is request to # delete both new cookie and any old matching cookie @@ -478,7 +479,7 @@ class CookieTests(TestCase): self.assertEquals(len(c), 2) c.clear_session_cookies() self.assertEquals(len(c), 1) - self.assertTrue('spam="bar"' in h) + self.assertIn('spam="bar"', h) # XXX RFC 2965 expiry rules (some apply to V0 too) @@ -488,39 +489,39 @@ class CookieTests(TestCase): c = CookieJar(pol) interact_2965(c, "http://www.acme.com/", 'spam="bar"; Version="1"') - self.assertTrue("/" in c._cookies["www.acme.com"]) + self.assertIn("/", c._cookies["www.acme.com"]) c = CookieJar(pol) interact_2965(c, "http://www.acme.com/blah", 'eggs="bar"; Version="1"') - self.assertTrue("/" in c._cookies["www.acme.com"]) + self.assertIn("/", c._cookies["www.acme.com"]) c = CookieJar(pol) interact_2965(c, "http://www.acme.com/blah/rhubarb", 'eggs="bar"; Version="1"') - self.assertTrue("/blah/" in c._cookies["www.acme.com"]) + self.assertIn("/blah/", c._cookies["www.acme.com"]) c = CookieJar(pol) interact_2965(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"; Version="1"') - self.assertTrue("/blah/rhubarb/" in c._cookies["www.acme.com"]) + self.assertIn("/blah/rhubarb/", c._cookies["www.acme.com"]) # Netscape c = CookieJar() interact_netscape(c, "http://www.acme.com/", 'spam="bar"') - self.assertTrue("/" in c._cookies["www.acme.com"]) + self.assertIn("/", c._cookies["www.acme.com"]) c = CookieJar() interact_netscape(c, "http://www.acme.com/blah", 'eggs="bar"') - self.assertTrue("/" in c._cookies["www.acme.com"]) + self.assertIn("/", c._cookies["www.acme.com"]) c = CookieJar() interact_netscape(c, "http://www.acme.com/blah/rhubarb", 'eggs="bar"') - self.assertTrue("/blah" in c._cookies["www.acme.com"]) + self.assertIn("/blah", c._cookies["www.acme.com"]) c = CookieJar() interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"') - self.assertTrue("/blah/rhubarb" in c._cookies["www.acme.com"]) + self.assertIn("/blah/rhubarb", c._cookies["www.acme.com"]) def test_escape_path(self): cases = [ @@ -877,21 +878,21 @@ class CookieTests(TestCase): url = "http://foo.bar.com/" interact_2965(c, url, "spam=eggs; Version=1") h = interact_2965(c, url) - self.assertTrue("Domain" not in h, + self.assertNotIn("Domain", h, "absent domain returned with domain present") c = CookieJar(pol) url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Domain=.bar.com') h = interact_2965(c, url) - self.assertTrue('$Domain=".bar.com"' in h, "domain not returned") + self.assertIn('$Domain=".bar.com"', h, "domain not returned") c = CookieJar(pol) url = "http://foo.bar.com/" # note missing initial dot in Domain interact_2965(c, url, 'spam=eggs; Version=1; Domain=bar.com') h = interact_2965(c, url) - self.assertTrue('$Domain="bar.com"' in h, "domain not returned") + self.assertIn('$Domain="bar.com"', h, "domain not returned") def test_path_mirror(self): pol = DefaultCookiePolicy(rfc2965=True) @@ -907,7 +908,7 @@ class CookieTests(TestCase): url = "http://foo.bar.com/" interact_2965(c, url, 'spam=eggs; Version=1; Path=/') h = interact_2965(c, url) - self.assertTrue('$Path="/"' in h, "path not returned") + self.assertIn('$Path="/"', h, "path not returned") def test_port_mirror(self): pol = DefaultCookiePolicy(rfc2965=True) @@ -1449,7 +1450,8 @@ class LWPCookieTests(TestCase): c, "http://www.acme.com/foo%2f%25/<<%0anew\345/\346\370\345", 'bar=baz; path="/foo/"; version=1'); version_re = re.compile(r'^\$version=\"?1\"?', re.I) - self.assertTrue("foo=bar" in cookie and version_re.search(cookie)) + self.assertIn("foo=bar", cookie) + self.assertTrue(version_re.search(cookie)) cookie = interact_2965( c, "http://www.acme.com/foo/%25/<<%0anew\345/\346\370\345") @@ -1493,11 +1495,11 @@ class LWPCookieTests(TestCase): new_c = save_and_restore(c, True) self.assertEquals(len(new_c), 6) # none discarded - self.assertTrue("name='foo1', value='bar'" in repr(new_c)) + self.assertIn("name='foo1', value='bar'", repr(new_c)) new_c = save_and_restore(c, False) self.assertEquals(len(new_c), 4) # 2 of them discarded on save - self.assertTrue("name='foo1', value='bar'" in repr(new_c)) + self.assertIn("name='foo1', value='bar'", repr(new_c)) def test_netscape_misc(self): # Some additional Netscape cookies tests. @@ -1519,9 +1521,8 @@ class LWPCookieTests(TestCase): req = urllib.request.Request("http://foo.bar.acme.com/foo") c.add_cookie_header(req) - self.assertTrue( - "PART_NUMBER=3,4" in req.get_header("Cookie") and - "Customer=WILE_E_COYOTE" in req.get_header("Cookie")) + self.assertIn("PART_NUMBER=3,4", req.get_header("Cookie")) + self.assertIn("Customer=WILE_E_COYOTE",req.get_header("Cookie")) def test_intranet_domains_2965(self): # Test handling of local intranet hostnames without a dot. @@ -1530,11 +1531,12 @@ class LWPCookieTests(TestCase): "foo1=bar; PORT; Discard; Version=1;") cookie = interact_2965(c, "http://example/", 'foo2=bar; domain=".local"; Version=1') - self.assertTrue("foo1=bar" in cookie) + self.assertIn("foo1=bar", cookie) interact_2965(c, "http://example/", 'foo3=bar; Version=1') cookie = interact_2965(c, "http://example/") - self.assertTrue("foo2=bar" in cookie and len(c) == 3) + self.assertIn("foo2=bar", cookie) + self.assertEquals(len(c), 3) def test_intranet_domains_ns(self): c = CookieJar(DefaultCookiePolicy(rfc2965 = False)) @@ -1542,10 +1544,10 @@ class LWPCookieTests(TestCase): cookie = interact_netscape(c, "http://example/", 'foo2=bar; domain=.local') self.assertEquals(len(c), 2) - self.assertTrue("foo1=bar" in cookie) + self.assertIn("foo1=bar", cookie) cookie = interact_netscape(c, "http://example/") - self.assertTrue("foo2=bar" in cookie) + self.assertIn("foo2=bar", cookie) self.assertEquals(len(c), 2) def test_empty_path(self): diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 23967cb..3f398fe 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -209,7 +209,7 @@ class ImportTest(unittest.TestCase): sys.path.insert(0, os.curdir) try: mod = __import__(TESTFN) - self.assertTrue(TESTFN in sys.modules, "expected module in sys.modules") + self.assertIn(TESTFN, sys.modules) self.assertEquals(mod.a, 1, "module has wrong attribute values") self.assertEquals(mod.b, 2, "module has wrong attribute values") @@ -253,7 +253,7 @@ class ImportTest(unittest.TestCase): del sys.modules[TESTFN] mod = __import__(TESTFN) ext = mod.__file__[-4:] - self.assertTrue(ext in ('.pyc', '.pyo'), ext) + self.assertIn(ext, ('.pyc', '.pyo')) finally: sys.path.pop(0) remove_files(TESTFN) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 9dba30d..d7e5e38 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -117,8 +117,8 @@ class TestPredicates(IsTestBase): x = C() x.a = 42 members = dict(inspect.getmembers(x)) - self.assertTrue('a' in members) - self.assertTrue('b' not in members) + self.assertIn('a', members) + self.assertNotIn('b', members) def test_isabstract(self): from abc import ABCMeta, abstractmethod @@ -471,25 +471,25 @@ class TestClassesAndFunctions(unittest.TestCase): datablob = '1' attrs = attrs_wo_objs(A) - self.assertTrue(('s', 'static method', A) in attrs, 'missing static method') - self.assertTrue(('c', 'class method', A) in attrs, 'missing class method') - self.assertTrue(('p', 'property', A) in attrs, 'missing property') + self.assertIn(('s', 'static method', A), attrs, 'missing static method') + self.assertIn(('c', 'class method', A), attrs, 'missing class method') + self.assertIn(('p', 'property', A), attrs, 'missing property') self.assertTrue(('m', 'method', A) in attrs, 'missing plain method: %r' % attrs) - self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method') - self.assertTrue(('datablob', 'data', A) in attrs, 'missing data') + self.assertIn(('m1', 'method', A), attrs, 'missing plain method') + self.assertIn(('datablob', 'data', A), attrs, 'missing data') class B(A): def m(self): pass attrs = attrs_wo_objs(B) - self.assertTrue(('s', 'static method', A) in attrs, 'missing static method') - self.assertTrue(('c', 'class method', A) in attrs, 'missing class method') - self.assertTrue(('p', 'property', A) in attrs, 'missing property') - self.assertTrue(('m', 'method', B) in attrs, 'missing plain method') - self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method') - self.assertTrue(('datablob', 'data', A) in attrs, 'missing data') + self.assertIn(('s', 'static method', A), attrs, 'missing static method') + self.assertIn(('c', 'class method', A), attrs, 'missing class method') + self.assertIn(('p', 'property', A), attrs, 'missing property') + self.assertIn(('m', 'method', B), attrs, 'missing plain method') + self.assertIn(('m1', 'method', A), attrs, 'missing plain method') + self.assertIn(('datablob', 'data', A), attrs, 'missing data') class C(A): @@ -498,24 +498,24 @@ class TestClassesAndFunctions(unittest.TestCase): def c(self): pass attrs = attrs_wo_objs(C) - self.assertTrue(('s', 'static method', A) in attrs, 'missing static method') - self.assertTrue(('c', 'method', C) in attrs, 'missing plain method') - self.assertTrue(('p', 'property', A) in attrs, 'missing property') - self.assertTrue(('m', 'method', C) in attrs, 'missing plain method') - self.assertTrue(('m1', 'method', A) in attrs, 'missing plain method') - self.assertTrue(('datablob', 'data', A) in attrs, 'missing data') + self.assertIn(('s', 'static method', A), attrs, 'missing static method') + self.assertIn(('c', 'method', C), attrs, 'missing plain method') + self.assertIn(('p', 'property', A), attrs, 'missing property') + self.assertIn(('m', 'method', C), attrs, 'missing plain method') + self.assertIn(('m1', 'method', A), attrs, 'missing plain method') + self.assertIn(('datablob', 'data', A), attrs, 'missing data') class D(B, C): def m1(self): pass attrs = attrs_wo_objs(D) - self.assertTrue(('s', 'static method', A) in attrs, 'missing static method') - self.assertTrue(('c', 'method', C) in attrs, 'missing plain method') - self.assertTrue(('p', 'property', A) in attrs, 'missing property') - self.assertTrue(('m', 'method', B) in attrs, 'missing plain method') - self.assertTrue(('m1', 'method', D) in attrs, 'missing plain method') - self.assertTrue(('datablob', 'data', A) in attrs, 'missing data') + self.assertIn(('s', 'static method', A), attrs, 'missing static method') + self.assertIn(('c', 'method', C), attrs, 'missing plain method') + self.assertIn(('p', 'property', A), attrs, 'missing property') + self.assertIn(('m', 'method', B), attrs, 'missing plain method') + self.assertIn(('m1', 'method', D), attrs, 'missing plain method') + self.assertIn(('datablob', 'data', A), attrs, 'missing data') def test_main(): run_unittest(TestDecorators, TestRetrievingSourceCode, TestOneliners, diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py index 50597ca..47e5911 100644 --- a/Lib/test/test_ioctl.py +++ b/Lib/test/test_ioctl.py @@ -24,7 +24,7 @@ class IoctlTests(unittest.TestCase): tty = open("/dev/tty", "r") r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") rpgrp = struct.unpack("i", r)[0] - self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids)) + self.assertIn(rpgrp, ids) def test_ioctl_mutate(self): import array @@ -34,7 +34,7 @@ class IoctlTests(unittest.TestCase): r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) rpgrp = buf[0] self.assertEquals(r, 0) - self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids)) + self.assertIn(rpgrp, ids) def test_ioctl_signed_unsigned_code_param(self): if not pty: diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index a826598..3642c44 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -542,23 +542,23 @@ class TestCase(unittest.TestCase): def test_in_and_not_in(self): for sc5 in IteratingSequenceClass(5), SequenceClass(5): for i in range(5): - self.assertTrue(i in sc5) + self.assertIn(i, sc5) for i in "abc", -1, 5, 42.42, (3, 4), [], {1: 1}, 3-12j, sc5: - self.assertTrue(i not in sc5) + self.assertNotIn(i, sc5) self.assertRaises(TypeError, lambda: 3 in 12) self.assertRaises(TypeError, lambda: 3 not in map) d = {"one": 1, "two": 2, "three": 3, 1j: 2j} for k in d: - self.assertTrue(k in d) - self.assertTrue(k not in d.values()) + self.assertIn(k, d) + self.assertNotIn(k, d.values()) for v in d.values(): - self.assertTrue(v in d.values()) - self.assertTrue(v not in d) + self.assertIn(v, d.values()) + self.assertNotIn(v, d) for k, v in d.items(): - self.assertTrue((k, v) in d.items()) - self.assertTrue((v, k) not in d.items()) + self.assertIn((k, v), d.items()) + self.assertNotIn((v, k), d.items()) f = open(TESTFN, "w") try: @@ -569,9 +569,9 @@ class TestCase(unittest.TestCase): try: for chunk in "abc": f.seek(0, 0) - self.assertTrue(chunk not in f) + self.assertNotIn(chunk, f) f.seek(0, 0) - self.assertTrue((chunk + "\n") in f) + self.assertIn((chunk + "\n"), f) finally: f.close() try: diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index eae4157..c27b898 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -502,7 +502,7 @@ class MmapTests(unittest.TestCase): def test_error(self): self.assertTrue(issubclass(mmap.error, EnvironmentError)) - self.assertTrue("mmap.error" in str(mmap.error)) + self.assertIn("mmap.error", str(mmap.error)) def test_io_methods(self): data = b"0123456789" diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 66b2a2f..5b5119b 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -163,7 +163,7 @@ class _TestProcess(BaseTestCase): self.assertEquals(p.authkey, current.authkey) self.assertEquals(p.is_alive(), False) self.assertEquals(p.daemon, True) - self.assertTrue(p not in self.active_children()) + self.assertNotIn(p, self.active_children()) self.assertTrue(type(self.active_children()) is list) self.assertEqual(p.exitcode, None) @@ -171,7 +171,7 @@ class _TestProcess(BaseTestCase): self.assertEquals(p.exitcode, None) self.assertEquals(p.is_alive(), True) - self.assertTrue(p in self.active_children()) + self.assertIn(p, self.active_children()) self.assertEquals(q.get(), args[1:]) self.assertEquals(q.get(), kwargs) @@ -184,7 +184,7 @@ class _TestProcess(BaseTestCase): self.assertEquals(p.exitcode, 0) self.assertEquals(p.is_alive(), False) - self.assertTrue(p not in self.active_children()) + self.assertNotIn(p, self.active_children()) def _test_terminate(self): time.sleep(1000) @@ -198,7 +198,7 @@ class _TestProcess(BaseTestCase): p.start() self.assertEqual(p.is_alive(), True) - self.assertTrue(p in self.active_children()) + self.assertIn(p, self.active_children()) self.assertEqual(p.exitcode, None) p.terminate() @@ -208,7 +208,7 @@ class _TestProcess(BaseTestCase): self.assertTimingAlmostEqual(join.elapsed, 0.0) self.assertEqual(p.is_alive(), False) - self.assertTrue(p not in self.active_children()) + self.assertNotIn(p, self.active_children()) p.join() @@ -227,13 +227,13 @@ class _TestProcess(BaseTestCase): self.assertEqual(type(self.active_children()), list) p = self.Process(target=time.sleep, args=(DELTA,)) - self.assertTrue(p not in self.active_children()) + self.assertNotIn(p, self.active_children()) p.start() - self.assertTrue(p in self.active_children()) + self.assertIn(p, self.active_children()) p.join() - self.assertTrue(p not in self.active_children()) + self.assertNotIn(p, self.active_children()) def _test_recursion(self, wconn, id): from multiprocessing import forking diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 907f943..cdbc998 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -228,7 +228,7 @@ class StatAttributeTests(unittest.TestCase): def trunc(x): return x self.assertEquals(trunc(getattr(result, attr)), result[getattr(stat, name)]) - self.assertTrue(attr in members) + self.assertIn(attr, members) try: result[200] diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index fcd7ccc..531b425 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -26,9 +26,9 @@ class TestTranforms(unittest.TestCase): del x asm = disassemble(unot) for elem in ('UNARY_NOT', 'POP_JUMP_IF_FALSE'): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('POP_JUMP_IF_TRUE',): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_elim_inversion_of_is_or_in(self): for line, elem in ( @@ -38,7 +38,7 @@ class TestTranforms(unittest.TestCase): ('not a not in b', '(in)',), ): asm = dis_single(line) - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_global_as_constant(self): # LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False @@ -55,14 +55,14 @@ class TestTranforms(unittest.TestCase): for func, name in ((f, 'None'), (g, 'True'), (h, 'False')): asm = disassemble(func) for elem in ('LOAD_GLOBAL',): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('LOAD_CONST', '('+name+')'): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def f(): 'Adding a docstring made this test fail in Py2.5.0' return None - self.assertTrue('LOAD_CONST' in disassemble(f)) - self.assertTrue('LOAD_GLOBAL' not in disassemble(f)) + self.assertIn('LOAD_CONST', disassemble(f)) + self.assertNotIn('LOAD_GLOBAL', disassemble(f)) def test_while_one(self): # Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx @@ -72,9 +72,9 @@ class TestTranforms(unittest.TestCase): return list asm = disassemble(f) for elem in ('LOAD_CONST', 'POP_JUMP_IF_FALSE'): - self.assertTrue(elem not in asm) + self.assertNotIn(elem, asm) for elem in ('JUMP_ABSOLUTE',): - self.assertTrue(elem in asm) + self.assertIn(elem, asm) def test_pack_unpack(self): for line, elem in ( @@ -83,9 +83,9 @@ class TestTranforms(unittest.TestCase): ('a, b, c = a, b, c', 'ROT_THREE',), ): asm = dis_single(line) - self.assertTrue(elem in asm) - self.assertTrue('BUILD_TUPLE' not in asm) - self.assertTrue('UNPACK_TUPLE' not in asm) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) + self.assertNotIn('UNPACK_TUPLE', asm) def test_folding_of_tuples_of_constants(self): for line, elem in ( @@ -96,8 +96,8 @@ class TestTranforms(unittest.TestCase): ('((1, 2), 3, 4)', '(((1, 2), 3, 4))'), ): asm = dis_single(line) - self.assertTrue(elem in asm) - self.assertTrue('BUILD_TUPLE' not in asm) + self.assertIn(elem, asm) + self.assertNotIn('BUILD_TUPLE', asm) # Bug 1053819: Tuple of constants misidentified when presented with: # . . . opcode_with_arg 100 unary_opcode BUILD_TUPLE 1 . . . @@ -183,17 +183,17 @@ class TestTranforms(unittest.TestCase): ('a = 13 | 7', '(15)'), # binary or ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('BINARY_' not in asm) + self.assertIn(elem, asm, asm) + self.assertNotIn('BINARY_', asm) # Verify that unfoldables are skipped asm = dis_single('a=2+"b"') - self.assertTrue('(2)' in asm) - self.assertTrue("('b')" in asm) + self.assertIn('(2)', asm) + self.assertIn("('b')", asm) # Verify that large sequences do not result from folding asm = dis_single('a="x"*1000') - self.assertTrue('(1000)' in asm) + self.assertIn('(1000)', asm) def test_folding_of_unaryops_on_constants(self): for line, elem in ( @@ -202,8 +202,8 @@ class TestTranforms(unittest.TestCase): ('+1', '(1)'), # unary positive ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('UNARY_' not in asm) + self.assertIn(elem, asm, asm) + self.assertNotIn('UNARY_', asm) # Verify that unfoldables are skipped for line, elem in ( @@ -211,16 +211,16 @@ class TestTranforms(unittest.TestCase): ('~"abc"', "('abc')"), # unary invert ): asm = dis_single(line) - self.assertTrue(elem in asm, asm) - self.assertTrue('UNARY_' in asm) + self.assertIn(elem, asm, asm) + self.assertIn('UNARY_', asm) def test_elim_extra_return(self): # RETURN LOAD_CONST None RETURN --> RETURN def f(x): return x asm = disassemble(f) - self.assertTrue('LOAD_CONST' not in asm) - self.assertTrue('(None)' not in asm) + self.assertNotIn('LOAD_CONST', asm) + self.assertNotIn('(None)', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 1) def test_elim_jump_to_return(self): @@ -228,8 +228,8 @@ class TestTranforms(unittest.TestCase): def f(cond, true_value, false_value): return true_value if cond else false_value asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) - self.assertTrue('JUMP_ABSOLUTE' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) def test_elim_jump_after_return1(self): @@ -244,8 +244,8 @@ class TestTranforms(unittest.TestCase): return 5 return 6 asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) - self.assertTrue('JUMP_ABSOLUTE' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) + self.assertNotIn('JUMP_ABSOLUTE', asm) self.assertEqual(asm.split().count('RETURN_VALUE'), 6) def test_elim_jump_after_return2(self): @@ -254,7 +254,7 @@ class TestTranforms(unittest.TestCase): while 1: if cond1: return 4 asm = disassemble(f) - self.assertTrue('JUMP_FORWARD' not in asm) + self.assertNotIn('JUMP_FORWARD', asm) # There should be one jump for the while loop. self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) @@ -265,7 +265,7 @@ class TestTranforms(unittest.TestCase): pass return g asm = disassemble(f) - self.assertTrue('BINARY_ADD' not in asm) + self.assertNotIn('BINARY_ADD', asm) def test_main(verbose=None): diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py index b9645d5..a2b4ec8 100644 --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -73,7 +73,7 @@ class ExceptionClassTests(unittest.TestCase): self.verify_instance_interface(exc()) except TypeError: pass - self.assertTrue(exc_name in exc_set) + self.assertIn(exc_name, exc_set) exc_set.discard(exc_name) last_exc = exc last_depth = depth diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py index 520c20f..27e3a9f 100644 --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -258,7 +258,7 @@ if hasattr(poplib, 'POP3_SSL'): self.client = poplib.POP3_SSL(self.server.host, self.server.port) def test__all__(self): - self.assertTrue('POP3_SSL' in poplib.__all__) + self.assertIn('POP3_SSL', poplib.__all__) class TestTimeouts(TestCase): diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 701d1ea..87c63ad 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -251,7 +251,7 @@ class PosixTester(unittest.TestCase): def test_lsdir(self): if hasattr(posix, 'lsdir'): - self.assertTrue(support.TESTFN in posix.lsdir(os.curdir)) + self.assertIn(support.TESTFN, posix.lsdir(os.curdir)) def test_access(self): if hasattr(posix, 'access'): diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 0efe3ff..9d037e1 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -481,14 +481,14 @@ class PosixPathTest(unittest.TestCase): self.assertRaises(TypeError, posixpath.normpath) def test_abspath(self): - self.assertTrue("foo" in posixpath.abspath("foo")) - self.assertTrue(b"foo" in posixpath.abspath(b"foo")) + self.assertIn("foo", posixpath.abspath("foo")) + self.assertIn(b"foo", posixpath.abspath(b"foo")) self.assertRaises(TypeError, posixpath.abspath) def test_realpath(self): - self.assertTrue("foo" in realpath("foo")) - self.assertTrue(b"foo" in realpath(b"foo")) + self.assertIn("foo", realpath("foo")) + self.assertIn(b"foo", realpath(b"foo")) self.assertRaises(TypeError, posixpath.realpath) if hasattr(os, "symlink"): diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index 406578a..51be9e5 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -43,8 +43,8 @@ class PwdTest(unittest.TestCase): for e in entries: if not e[0] or e[0] == '+': continue # skip NIS entries etc. - self.assertTrue(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name]) - self.assertTrue(pwd.getpwuid(e.pw_uid) in entriesbyuid[e.pw_uid]) + self.assertIn(pwd.getpwnam(e.pw_name), entriesbyname[e.pw_name]) + self.assertIn(pwd.getpwuid(e.pw_uid), entriesbyuid[e.pw_uid]) def test_errors(self): self.assertRaises(TypeError, pwd.getpwuid) diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index d81234c..06f3338 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -40,6 +40,7 @@ class PyclbrTest(TestCase): if key in ignore: return if key not in obj: print("***",key, file=sys.stderr) + self.assertIn(key, obj) self.assertTrue(key in obj, "%r in %r" % (key, obj)) def assertEqualsOrIgnored(self, a, b, ignore): diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 56d125b..3bcd592 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -313,7 +313,7 @@ class TestDescriptions(unittest.TestCase): # Check that pydocfodder module can be described from test import pydocfodder doc = pydoc.render_doc(pydocfodder) - self.assertTrue("pydocfodder" in doc) + self.assertIn("pydocfodder", doc) def test_classic_class(self): class C: "Classic class" @@ -321,7 +321,7 @@ class TestDescriptions(unittest.TestCase): self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s' % __name__ - self.assertTrue(expected in pydoc.render_doc(c)) + self.assertIn(expected, pydoc.render_doc(c)) def test_class(self): class C(object): "New-style class" @@ -330,7 +330,7 @@ class TestDescriptions(unittest.TestCase): self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s object' % __name__ - self.assertTrue(expected in pydoc.render_doc(c)) + self.assertIn(expected, pydoc.render_doc(c)) def test_main(): diff --git a/Lib/test/test_raise.py b/Lib/test/test_raise.py index ff4800b..033df3b 100644 --- a/Lib/test/test_raise.py +++ b/Lib/test/test_raise.py @@ -28,7 +28,7 @@ class TestRaise(unittest.TestCase): try: raise except RuntimeError as e: - self.assertTrue("No active exception" in str(e)) + self.assertIn("No active exception", str(e)) else: self.fail("No exception raised") @@ -127,7 +127,7 @@ class TestCause(unittest.TestCase): try: raise IndexError from 5 except TypeError as e: - self.assertTrue("exception cause" in str(e)) + self.assertIn("exception cause", str(e)) else: self.fail("No exception raised") diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index df07b76..b64a8f7 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -211,7 +211,7 @@ class SystemRandom_TestBasicOps(TestBasicOps): n += n - 1 # check 1 below the next power of two k = int(1.00001 + _log(n, 2)) - self.assertTrue(k in [numbits, numbits+1]) + self.assertIn(k, [numbits, numbits+1]) self.assertTrue(2**k > n > 2**(k-2)) n -= n >> 15 # check a little farther below the next power of two @@ -367,7 +367,7 @@ class MersenneTwister_TestBasicOps(TestBasicOps): n += n - 1 # check 1 below the next power of two k = int(1.00001 + _log(n, 2)) - self.assertTrue(k in [numbits, numbits+1]) + self.assertIn(k, [numbits, numbits+1]) self.assertTrue(2**k > n > 2**(k-2)) n -= n >> 15 # check a little farther below the next power of two diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index 126868a..d9bf5a0 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -59,18 +59,18 @@ class RangeTest(unittest.TestCase): self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2]) seq = list(range(a, b, c)) - self.assertTrue(a in seq) - self.assertTrue(b not in seq) + self.assertIn(a, seq) + self.assertNotIn(b, seq) self.assertEqual(len(seq), 2) seq = list(range(b, a, -c)) - self.assertTrue(b in seq) - self.assertTrue(a not in seq) + self.assertIn(b, seq) + self.assertNotIn(a, seq) self.assertEqual(len(seq), 2) seq = list(range(-a, -b, -c)) - self.assertTrue(-a in seq) - self.assertTrue(-b not in seq) + self.assertIn(-a, seq) + self.assertNotIn(-b, seq) self.assertEqual(len(seq), 2) self.assertRaises(TypeError, range) @@ -114,13 +114,13 @@ class RangeTest(unittest.TestCase): def test_types(self): # Non-integer objects *equal* to any of the range's items are supposed # to be contained in the range. - self.assertTrue(1.0 in range(3)) - self.assertTrue(True in range(3)) - self.assertTrue(1+0j in range(3)) + self.assertIn(1.0, range(3)) + self.assertIn(True, range(3)) + self.assertIn(1+0j, range(3)) class C1: def __eq__(self, other): return True - self.assertTrue(C1() in range(3)) + self.assertIn(C1(), range(3)) # Objects are never coerced into other types for comparison. class C2: @@ -128,32 +128,32 @@ class RangeTest(unittest.TestCase): def __index__(self): return 1 self.assertFalse(C2() in range(3)) # ..except if explicitly told so. - self.assertTrue(int(C2()) in range(3)) + self.assertIn(int(C2()), range(3)) # Check that the range.__contains__ optimization is only # used for ints, not for instances of subclasses of int. class C3(int): def __eq__(self, other): return True - self.assertTrue(C3(11) in range(10)) - self.assertTrue(C3(11) in list(range(10))) + self.assertIn(C3(11), range(10)) + self.assertIn(C3(11), list(range(10))) def test_strided_limits(self): r = range(0, 101, 2) - self.assertTrue(0 in r) + self.assertIn(0, r) self.assertFalse(1 in r) - self.assertTrue(2 in r) + self.assertIn(2, r) self.assertFalse(99 in r) - self.assertTrue(100 in r) + self.assertIn(100, r) self.assertFalse(101 in r) r = range(0, -20, -1) - self.assertTrue(0 in r) - self.assertTrue(-1 in r) - self.assertTrue(-19 in r) + self.assertIn(0, r) + self.assertIn(-1, r) + self.assertIn(-19, r) self.assertFalse(-20 in r) r = range(0, -20, -2) - self.assertTrue(-18 in r) + self.assertIn(-18, r) self.assertFalse(-19 in r) self.assertFalse(-20 in r) diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py index 12e207b..627482c 100644 --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -125,7 +125,7 @@ class ReprTests(unittest.TestCase): s = r(ClassWithFailingRepr) self.assertTrue(s.startswith("")) - self.assertTrue(s.find("...") in [12, 13]) + self.assertIn(s.find("..."), [12, 13]) def test_lambda(self): self.assertTrue(repr(lambda x: x).startswith( diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index 0542194..995c891 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -165,14 +165,14 @@ class RunModuleTest(unittest.TestCase): try: if verbose: print("Running from source:", mod_name) d1 = run_module(mod_name) # Read from source - self.assertTrue("x" in d1) + self.assertIn("x", d1) self.assertEqual(d1["x"], 1) del d1 # Ensure __loader__ entry doesn't keep file open __import__(mod_name) os.remove(mod_fname) if verbose: print("Running from compiled:", mod_name) d2 = run_module(mod_name) # Read from bytecode - self.assertTrue("x" in d2) + self.assertIn("x", d2) self.assertEqual(d2["x"], 1) del d2 # Ensure __loader__ entry doesn't keep file open finally: @@ -187,14 +187,14 @@ class RunModuleTest(unittest.TestCase): try: if verbose: print("Running from source:", pkg_name) d1 = run_module(pkg_name) # Read from source - self.assertTrue("x" in d1) + self.assertIn("x", d1) self.assertTrue(d1["x"] == 1) del d1 # Ensure __loader__ entry doesn't keep file open __import__(mod_name) os.remove(mod_fname) if verbose: print("Running from compiled:", pkg_name) d2 = run_module(pkg_name) # Read from bytecode - self.assertTrue("x" in d2) + self.assertIn("x", d2) self.assertTrue(d2["x"] == 1) del d2 # Ensure __loader__ entry doesn't keep file open finally: @@ -239,19 +239,19 @@ from ..uncle.cousin import nephew pkg_name = mod_name.rpartition('.')[0] if verbose: print("Running from source:", mod_name) d1 = run_module(mod_name, run_name=run_name) # Read from source - self.assertTrue("__package__" in d1) + self.assertIn("__package__", d1) self.assertTrue(d1["__package__"] == pkg_name) - self.assertTrue("sibling" in d1) - self.assertTrue("nephew" in d1) + self.assertIn("sibling", d1) + self.assertIn("nephew", d1) del d1 # Ensure __loader__ entry doesn't keep file open __import__(mod_name) os.remove(mod_fname) if verbose: print("Running from compiled:", mod_name) d2 = run_module(mod_name, run_name=run_name) # Read from bytecode - self.assertTrue("__package__" in d2) + self.assertIn("__package__", d2) self.assertTrue(d2["__package__"] == pkg_name) - self.assertTrue("sibling" in d2) - self.assertTrue("nephew" in d2) + self.assertIn("sibling", d2) + self.assertIn("nephew", d2) del d2 # Ensure __loader__ entry doesn't keep file open finally: self._del_pkg(pkg_dir, depth, mod_name) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index a45d1f3..c920ad3 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -59,7 +59,7 @@ class XmlTestBase(unittest.TestCase): self.assertEquals(attrs.getNames(), ["attr"]) self.assertEquals(attrs.getQNames(), ["attr"]) self.assertEquals(len(attrs), 1) - self.assertTrue("attr" in attrs) + self.assertIn("attr", attrs) self.assertEquals(list(attrs.keys()), ["attr"]) self.assertEquals(attrs.get("attr"), "val") self.assertEquals(attrs.get("attr", 25), "val") @@ -436,7 +436,7 @@ class ExpatReaderTest(XmlTestBase): self.assertTrue((attrs.getQNames() == [] or attrs.getQNames() == ["ns:attr"])) self.assertEquals(len(attrs), 1) - self.assertTrue((ns_uri, "attr") in attrs) + self.assertIn((ns_uri, "attr"), attrs) self.assertEquals(attrs.get((ns_uri, "attr")), "val") self.assertEquals(attrs.get((ns_uri, "attr"), 25), "val") self.assertEquals(list(attrs.items()), [((ns_uri, "attr"), "val")]) @@ -626,7 +626,7 @@ class XmlReaderTest(XmlTestBase): self.assertEquals(attrs.getNames(), [(ns_uri, "attr")]) self.assertEquals(attrs.getQNames(), ["ns:attr"]) self.assertEquals(len(attrs), 1) - self.assertTrue((ns_uri, "attr") in attrs) + self.assertIn((ns_uri, "attr"), attrs) self.assertEquals(list(attrs.keys()), [(ns_uri, "attr")]) self.assertEquals(attrs.get((ns_uri, "attr")), "val") self.assertEquals(attrs.get((ns_uri, "attr"), 25), "val") diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index ef56b88..ffe68c8 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -447,7 +447,7 @@ self.assertTrue(X.passed) return g d = f(2)(4) - self.assertTrue('h' in d) + self.assertIn('h', d) del d['h'] self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6}) @@ -481,8 +481,8 @@ self.assertTrue(X.passed) return C varnames = f(1).z - self.assertTrue("x" not in varnames) - self.assertTrue("y" in varnames) + self.assertNotIn("x", varnames) + self.assertIn("y", varnames) def testLocalsClass_WithTrace(self): # Issue23728: after the trace function returns, the locals() @@ -660,7 +660,7 @@ result2 = h() c = f(0) self.assertEqual(c.get(), 1) - self.assertTrue("x" not in c.__class__.__dict__) + self.assertNotIn("x", c.__class__.__dict__) def testNonLocalGenerator(self): diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 2b43a16..26977d9 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -65,7 +65,7 @@ class TestJointOps(unittest.TestCase): self.assertEqual(c in self.s, c in self.d) self.assertRaises(TypeError, self.s.__contains__, [[]]) s = self.thetype([frozenset(self.letters)]) - self.assertTrue(self.thetype(self.letters) in s) + self.assertIn(self.thetype(self.letters), s) def test_union(self): u = self.s.union(self.otherword) @@ -269,7 +269,7 @@ class TestJointOps(unittest.TestCase): s=H() f=set() f.add(s) - self.assertTrue(s in f) + self.assertIn(s, f) f.remove(s) f.add(s) f.discard(s) @@ -379,7 +379,7 @@ class TestSet(TestJointOps): def test_add(self): self.s.add('Q') - self.assertTrue('Q' in self.s) + self.assertIn('Q', self.s) dup = self.s.copy() self.s.add('Q') self.assertEqual(self.s, dup) @@ -387,13 +387,13 @@ class TestSet(TestJointOps): def test_remove(self): self.s.remove('a') - self.assertTrue('a' not in self.s) + self.assertNotIn('a', self.s) self.assertRaises(KeyError, self.s.remove, 'Q') self.assertRaises(TypeError, self.s.remove, []) s = self.thetype([frozenset(self.word)]) - self.assertTrue(self.thetype(self.word) in s) + self.assertIn(self.thetype(self.word), s) s.remove(self.thetype(self.word)) - self.assertTrue(self.thetype(self.word) not in s) + self.assertNotIn(self.thetype(self.word), s) self.assertRaises(KeyError, self.s.remove, self.thetype(self.word)) def test_remove_keyerror_unpacking(self): @@ -420,26 +420,26 @@ class TestSet(TestJointOps): def test_discard(self): self.s.discard('a') - self.assertTrue('a' not in self.s) + self.assertNotIn('a', self.s) self.s.discard('Q') self.assertRaises(TypeError, self.s.discard, []) s = self.thetype([frozenset(self.word)]) - self.assertTrue(self.thetype(self.word) in s) + self.assertIn(self.thetype(self.word), s) s.discard(self.thetype(self.word)) - self.assertTrue(self.thetype(self.word) not in s) + self.assertNotIn(self.thetype(self.word), s) s.discard(self.thetype(self.word)) def test_pop(self): for i in range(len(self.s)): elem = self.s.pop() - self.assertTrue(elem not in self.s) + self.assertNotIn(elem, self.s) self.assertRaises(KeyError, self.s.pop) def test_update(self): retval = self.s.update(self.otherword) self.assertEqual(retval, None) for c in (self.word + self.otherword): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) self.assertRaises(PassThru, self.s.update, check_pass_thru()) self.assertRaises(TypeError, self.s.update, [[]]) for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')): @@ -457,16 +457,16 @@ class TestSet(TestJointOps): def test_ior(self): self.s |= set(self.otherword) for c in (self.word + self.otherword): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) def test_intersection_update(self): retval = self.s.intersection_update(self.otherword) self.assertEqual(retval, None) for c in (self.word + self.otherword): if c in self.otherword and c in self.word: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru()) self.assertRaises(TypeError, self.s.intersection_update, [[]]) for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')): @@ -484,18 +484,18 @@ class TestSet(TestJointOps): self.s &= set(self.otherword) for c in (self.word + self.otherword): if c in self.otherword and c in self.word: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_difference_update(self): retval = self.s.difference_update(self.otherword) self.assertEqual(retval, None) for c in (self.word + self.otherword): if c in self.word and c not in self.otherword: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(PassThru, self.s.difference_update, check_pass_thru()) self.assertRaises(TypeError, self.s.difference_update, [[]]) self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) @@ -521,18 +521,18 @@ class TestSet(TestJointOps): self.s -= set(self.otherword) for c in (self.word + self.otherword): if c in self.word and c not in self.otherword: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_symmetric_difference_update(self): retval = self.s.symmetric_difference_update(self.otherword) self.assertEqual(retval, None) for c in (self.word + self.otherword): if (c in self.word) ^ (c in self.otherword): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru()) self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')): @@ -545,9 +545,9 @@ class TestSet(TestJointOps): self.s ^= set(self.otherword) for c in (self.word + self.otherword): if (c in self.word) ^ (c in self.otherword): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_inplace_on_self(self): t = self.s.copy() @@ -814,7 +814,7 @@ class TestBasicOps(unittest.TestCase): def test_iteration(self): for v in self.set: - self.assertTrue(v in self.values) + self.assertIn(v, self.values) setiter = iter(self.set) # note: __length_hint__ is an internal undocumented API, # don't rely on it in your own programs @@ -849,10 +849,10 @@ class TestBasicOpsSingleton(TestBasicOps): self.repr = "{3}" def test_in(self): - self.assertTrue(3 in self.set) + self.assertIn(3, self.set) def test_not_in(self): - self.assertTrue(2 not in self.set) + self.assertNotIn(2, self.set) #------------------------------------------------------------------------------ @@ -866,10 +866,10 @@ class TestBasicOpsTuple(TestBasicOps): self.repr = "{(0, 'zero')}" def test_in(self): - self.assertTrue((0, "zero") in self.set) + self.assertIn((0, "zero"), self.set) def test_not_in(self): - self.assertTrue(9 not in self.set) + self.assertNotIn(9, self.set) #------------------------------------------------------------------------------ @@ -1186,7 +1186,7 @@ class TestMutate(unittest.TestCase): popped[self.set.pop()] = None self.assertEqual(len(popped), len(self.values)) for v in self.values: - self.assertTrue(v in popped) + self.assertIn(v, popped) def test_update_empty_tuple(self): self.set.update(()) @@ -1760,7 +1760,7 @@ class TestGraphs(unittest.TestCase): edge = vertex # Cuboctahedron vertices are edges in Cube self.assertEqual(len(edge), 2) # Two cube vertices define an edge for cubevert in edge: - self.assertTrue(cubevert in g) + self.assertIn(cubevert, g) #============================================================================== diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index fd8e1fa..f785319 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -270,7 +270,7 @@ class ImportSideEffectTests(unittest.TestCase): site.removeduppaths() seen_paths = set() for path in sys.path: - self.assertTrue(path not in seen_paths) + self.assertNotIn(path, seen_paths) seen_paths.add(path) def test_add_build_dir(self): diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 4326e65..4dc34ce 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -502,7 +502,7 @@ class GeneralModuleTests(unittest.TestCase): # it reasonable to get the host's addr in addition to 0.0.0.0. # At least for eCos. This is required for the S/390 to pass. my_ip_addr = socket.gethostbyname(socket.gethostname()) - self.assertTrue(name[0] in ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) + self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) self.assertEqual(name[1], port) def testGetSockOpt(self): diff --git a/Lib/test/test_structseq.py b/Lib/test/test_structseq.py index 7adca53..6e57e22 100644 --- a/Lib/test/test_structseq.py +++ b/Lib/test/test_structseq.py @@ -50,8 +50,8 @@ class StructSeqTest(unittest.TestCase): def test_contains(self): t1 = time.gmtime() for item in t1: - self.assertTrue(item in t1) - self.assertTrue(-42 not in t1) + self.assertIn(item, t1) + self.assertNotIn(-42, t1) def test_hash(self): t1 = time.gmtime() diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 265859a..dbde4fd 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -77,7 +77,7 @@ class ProcessTestCase(unittest.TestCase): # check_output() function with zero return code output = subprocess.check_output( [sys.executable, "-c", "print('BDFL')"]) - self.assertTrue(b'BDFL' in output) + self.assertIn(b'BDFL', output) def test_check_output_nonzero(self): # check_call() function with non-zero return code @@ -94,7 +94,7 @@ class ProcessTestCase(unittest.TestCase): output = subprocess.check_output( [sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"], stderr=subprocess.STDOUT) - self.assertTrue(b'BDFL' in output) + self.assertIn(b'BDFL', output) def test_check_output_stdout_arg(self): # check_output() function stderr redirected to stdout @@ -103,7 +103,7 @@ class ProcessTestCase(unittest.TestCase): [sys.executable, "-c", "print('will not be run')"], stdout=sys.stdout) except ValueError as e: - self.assertTrue('stdout' in e.args[0]) + self.assertIn('stdout', e.args[0]) else: self.fail("Expected ValueError when stdout arg supplied.") diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 585b6ec..e28c4b0 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -318,8 +318,8 @@ class SysModuleTest(unittest.TestCase): d = sys._current_frames() main_id = _thread.get_ident() - self.assertTrue(main_id in d) - self.assertTrue(thread_id in d) + self.assertIn(main_id, d) + self.assertIn(thread_id, d) # Verify that the captured main-thread frame is _this_ frame. frame = d.pop(main_id) @@ -341,7 +341,7 @@ class SysModuleTest(unittest.TestCase): # And the next record must be for g456(). filename, lineno, funcname, sourceline = stack[i+1] self.assertEqual(funcname, "g456") - self.assertTrue(sourceline in ["leave_g.wait()", "entered_g.set()"]) + self.assertIn(sourceline, ["leave_g.wait()", "entered_g.set()"]) # Reap the spawned thread. leave_g.set() @@ -353,13 +353,13 @@ class SysModuleTest(unittest.TestCase): # "thread id" 0. d = sys._current_frames() self.assertEqual(len(d), 1) - self.assertTrue(0 in d) + self.assertIn(0, d) self.assertTrue(d[0] is sys._getframe()) def test_attributes(self): self.assertTrue(isinstance(sys.api_version, int)) self.assertTrue(isinstance(sys.argv, list)) - self.assertTrue(sys.byteorder in ("little", "big")) + self.assertIn(sys.byteorder, ("little", "big")) self.assertTrue(isinstance(sys.builtin_module_names, tuple)) self.assertTrue(isinstance(sys.copyright, str)) self.assertTrue(isinstance(sys.exec_prefix, str)) @@ -383,7 +383,7 @@ class SysModuleTest(unittest.TestCase): self.assertTrue(isinstance(vi[0], int)) self.assertTrue(isinstance(vi[1], int)) self.assertTrue(isinstance(vi[2], int)) - self.assertTrue(vi[3] in ("alpha", "beta", "candidate", "final")) + self.assertIn(vi[3], ("alpha", "beta", "candidate", "final")) self.assertTrue(isinstance(vi[4], int)) self.assertTrue(isinstance(vi.major, int)) self.assertTrue(isinstance(vi.minor, int)) @@ -398,7 +398,7 @@ class SysModuleTest(unittest.TestCase): self.assertEqual(vi[4], vi.serial) self.assertTrue(vi > (1,0,0)) self.assertIsInstance(sys.float_repr_style, str) - self.assertTrue(sys.float_repr_style in ('short', 'legacy')) + self.assertIn(sys.float_repr_style, ('short', 'legacy')) def test_43581(self): # Can't use sys.stdout, as this is a StringIO object when diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index dfa5553..792f2b9 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -485,7 +485,7 @@ class MemberReadTest(ReadTest): def test_find_ustar_longname(self): name = "ustar/" + "12345/" * 39 + "1234567/longname" - self.assertTrue(name in self.tar.getnames()) + self.assertIn(name, self.tar.getnames()) def test_find_regtype_oldv7(self): tarinfo = self.tar.getmember("misc/regtype-old-v7") diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py index d57fda1..4cb013e 100644 --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -284,7 +284,7 @@ class OptionTests(TestCase): txt = telnet.read_all() cmd = nego.seen self.assertTrue(len(cmd) > 0) # we expect at least one command - self.assertTrue(cmd[:1] in self.cmds) + self.assertIn(cmd[:1], self.cmds) self.assertEqual(cmd[1:2], tl.NOOPT) self.assertEqual(data_len, len(txt + cmd)) nego.sb_getter = None # break the nego => telnet cycle @@ -331,7 +331,7 @@ class OptionTests(TestCase): telnet = test_telnet([a]) telnet.set_debuglevel(1) txt = telnet.read_all() - self.assertTrue(b in telnet._messages) + self.assertIn(b, telnet._messages) return def test_debuglevel_write(self): @@ -339,7 +339,7 @@ class OptionTests(TestCase): telnet.set_debuglevel(1) telnet.write(b'xxx') expected = "send b'xxx'\n" - self.assertTrue(expected in telnet._messages) + self.assertIn(expected, telnet._messages) def test_main(verbose=None): support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests) diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 403dd93..d296fac 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -160,14 +160,14 @@ class test__candidate_tempdir_list(TC): for envname in 'TMPDIR', 'TEMP', 'TMP': dirname = os.getenv(envname) if not dirname: raise ValueError - self.assertTrue(dirname in cand) + self.assertIn(dirname, cand) try: dirname = os.getcwd() except (AttributeError, os.error): dirname = os.curdir - self.assertTrue(dirname in cand) + self.assertIn(dirname, cand) # Not practical to try to verify the presence of OS-specific # paths in this list. diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 0b37059..0d43d42 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -153,7 +153,7 @@ class ThreadTests(BaseTestCase): tid = _thread.start_new_thread(f, (mutex,)) # Wait for the thread to finish. mutex.acquire() - self.assertTrue(tid in threading._active) + self.assertIn(tid, threading._active) self.assertTrue(isinstance(threading._active[tid], threading._DummyThread)) del threading._active[tid] diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py index 726117f..f72119b 100644 --- a/Lib/test/test_threading_local.py +++ b/Lib/test/test_threading_local.py @@ -40,7 +40,7 @@ class ThreadingLocalTest(unittest.TestCase): local.someothervar = None gc.collect() deadlist = [weak for weak in weaklist if weak() is None] - self.assertTrue(len(deadlist) in (n-1, n), (n, len(deadlist))) + self.assertIn(len(deadlist), (n-1, n), (n, len(deadlist))) def test_derived(self): # Issue 3088: if there is a threads switch inside the __init__ diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 17413db..e4681c0 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -41,12 +41,12 @@ class SyntaxTracebackCases(unittest.TestCase): SyntaxError) self.assertEqual(len(err), 4) self.assertTrue(err[1].strip() == "return x!") - self.assertTrue("^" in err[2]) # third line has caret + self.assertIn("^", err[2]) # third line has caret self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right place err = self.get_exception_format(self.syntax_error_with_caret_2, SyntaxError) - self.assertTrue("^" in err[2]) # third line has caret + self.assertIn("^", err[2]) # third line has caret self.assertTrue(err[2].count('\n') == 1) # and no additional newline self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place @@ -64,7 +64,7 @@ class SyntaxTracebackCases(unittest.TestCase): IndentationError) self.assertEqual(len(err), 4) self.assertEqual(err[1].strip(), "print(2)") - self.assertTrue("^" in err[2]) + self.assertIn("^", err[2]) self.assertEqual(err[1].find(")"), err[2].find("^")) def test_base_exception(self): @@ -210,7 +210,7 @@ class BaseExceptionReportingTests: def check_zero_div(self, msg): lines = msg.splitlines() self.assertTrue(lines[-3].startswith(' File')) - self.assertTrue('1/0 # In zero_div' in lines[-2], lines[-2]) + self.assertIn('1/0 # In zero_div', lines[-2]) self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1]) def test_simple(self): @@ -222,7 +222,7 @@ class BaseExceptionReportingTests: self.assertEquals(len(lines), 4) self.assertTrue(lines[0].startswith('Traceback')) self.assertTrue(lines[1].startswith(' File')) - self.assertTrue('1/0 # Marker' in lines[2]) + self.assertIn('1/0 # Marker', lines[2]) self.assertTrue(lines[3].startswith('ZeroDivisionError')) def test_cause(self): @@ -237,7 +237,7 @@ class BaseExceptionReportingTests: self.assertEquals(len(blocks), 3) self.assertEquals(blocks[1], cause_message) self.check_zero_div(blocks[0]) - self.assertTrue('inner_raise() # Marker' in blocks[2]) + self.assertIn('inner_raise() # Marker', blocks[2]) def test_context(self): def inner_raise(): @@ -251,7 +251,7 @@ class BaseExceptionReportingTests: self.assertEquals(len(blocks), 3) self.assertEquals(blocks[1], context_message) self.check_zero_div(blocks[0]) - self.assertTrue('inner_raise() # Marker' in blocks[2]) + self.assertIn('inner_raise() # Marker', blocks[2]) def test_cause_and_context(self): # When both a cause and a context are set, only the cause should be @@ -289,11 +289,11 @@ class BaseExceptionReportingTests: self.assertEquals(len(blocks), 3) self.assertEquals(blocks[1], cause_message) # The first block is the KeyError raised from the ZeroDivisionError - self.assertTrue('raise KeyError from e' in blocks[0]) - self.assertTrue('1/0' not in blocks[0]) + self.assertIn('raise KeyError from e', blocks[0]) + self.assertNotIn('1/0', blocks[0]) # The second block (apart from the boundary) is the ZeroDivisionError # re-raised from the KeyError - self.assertTrue('inner_raise() # Marker' in blocks[2]) + self.assertIn('inner_raise() # Marker', blocks[2]) self.check_zero_div(blocks[2]) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index c6aa4eb..5df1f42 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -434,13 +434,13 @@ class TypesTests(unittest.TestCase): result = f.__format__(fmt) self.assertEqual(len(result), 98) self.assertEqual(result[-7], '.') - self.assertTrue(result[:12] in ('112340000000', '112339999999')) + self.assertIn(result[:12], ('112340000000', '112339999999')) f = 1.1234e200 for fmt in 'f', 'F': result = f.__format__(fmt) self.assertEqual(len(result), 208) self.assertEqual(result[-7], '.') - self.assertTrue(result[:12] in ('112340000000', '112339999999')) + self.assertIn(result[:12], ('112340000000', '112339999999')) test( 1.0, 'e', '1.000000e+00') diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 66368f4..ef9aa9e 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -436,32 +436,32 @@ class UnicodeTest( def test_contains(self): # Testing Unicode contains method - self.assertTrue('a' in 'abdb') - self.assertTrue('a' in 'bdab') - self.assertTrue('a' in 'bdaba') - self.assertTrue('a' in 'bdba') - self.assertTrue('a' not in 'bdb') - self.assertTrue('a' in 'bdba') - self.assertTrue('a' in ('a',1,None)) - self.assertTrue('a' in (1,None,'a')) - self.assertTrue('a' in ('a',1,None)) - self.assertTrue('a' in (1,None,'a')) - self.assertTrue('a' not in ('x',1,'y')) - self.assertTrue('a' not in ('x',1,None)) - self.assertTrue('abcd' not in 'abcxxxx') - self.assertTrue('ab' in 'abcd') - self.assertTrue('ab' in 'abc') - self.assertTrue('ab' in (1,None,'ab')) - self.assertTrue('' in 'abc') - self.assertTrue('' in '') - self.assertTrue('' in 'abc') - self.assertTrue('\0' not in 'abc') - self.assertTrue('\0' in '\0abc') - self.assertTrue('\0' in 'abc\0') - self.assertTrue('a' in '\0abc') - self.assertTrue('asdf' in 'asdf') - self.assertTrue('asdf' not in 'asd') - self.assertTrue('asdf' not in '') + self.assertIn('a', 'abdb') + self.assertIn('a', 'bdab') + self.assertIn('a', 'bdaba') + self.assertIn('a', 'bdba') + self.assertNotIn('a', 'bdb') + self.assertIn('a', 'bdba') + self.assertIn('a', ('a',1,None)) + self.assertIn('a', (1,None,'a')) + self.assertIn('a', ('a',1,None)) + self.assertIn('a', (1,None,'a')) + self.assertNotIn('a', ('x',1,'y')) + self.assertNotIn('a', ('x',1,None)) + self.assertNotIn('abcd', 'abcxxxx') + self.assertIn('ab', 'abcd') + self.assertIn('ab', 'abc') + self.assertIn('ab', (1,None,'ab')) + self.assertIn('', 'abc') + self.assertIn('', '') + self.assertIn('', 'abc') + self.assertNotIn('\0', 'abc') + self.assertIn('\0', '\0abc') + self.assertIn('\0', 'abc\0') + self.assertIn('a', '\0abc') + self.assertIn('asdf', 'asdf') + self.assertNotIn('asdf', 'asd') + self.assertNotIn('asdf', '') self.assertRaises(TypeError, "abc".__contains__) diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index 367715a..0ff1f71 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -47,7 +47,7 @@ class TestUnicodeFiles(unittest.TestCase): base = unicodedata.normalize("NFD", base) file_list = [unicodedata.normalize("NFD", f) for f in file_list] - self.assertTrue(base in file_list) + self.assertIn(base, file_list) # Do as many "equivalancy' tests as we can - ie, check that although we # have different types for the filename, they refer to the same file. diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py index 61e49a5..2ecb09e 100644 --- a/Lib/test/test_unicodedata.py +++ b/Lib/test/test_unicodedata.py @@ -220,7 +220,7 @@ class UnicodeMiscTest(UnicodeDatabaseTest): self.assertEqual(popen.returncode, 1) error = "SyntaxError: (unicode error) \\N escapes not supported " \ "(can't load unicodedata module)" - self.assertTrue(error in popen.stderr.read().decode("ascii")) + self.assertIn(error, popen.stderr.read().decode("ascii")) def test_decimal_numeric_consistent(self): # Test that decimal and numeric are consistent, diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index e33f31e..95febe1 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -636,7 +636,7 @@ class Test_TestLoader(TestCase): self.assertEqual(list(suite), []) # audioop should now be loaded, thanks to loadTestsFromName() - self.assertTrue(module_name in sys.modules) + self.assertIn(module_name, sys.modules) finally: if module_name in sys.modules: del sys.modules[module_name] @@ -1024,7 +1024,7 @@ class Test_TestLoader(TestCase): self.assertEqual(list(suite), [unittest.TestSuite()]) # audioop should now be loaded, thanks to loadTestsFromName() - self.assertTrue(module_name in sys.modules) + self.assertIn(module_name, sys.modules) finally: if module_name in sys.modules: del sys.modules[module_name] diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index d755a61..269451f 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -787,8 +787,8 @@ class HandlerTests(unittest.TestCase): r = MockResponse(200, "OK", {}, "") newreq = h.do_request_(req) if data is None: # GET - self.assertTrue("Content-length" not in req.unredirected_hdrs) - self.assertTrue("Content-type" not in req.unredirected_hdrs) + self.assertNotIn("Content-length", req.unredirected_hdrs) + self.assertNotIn("Content-type", req.unredirected_hdrs) else: # POST self.assertEqual(req.unredirected_hdrs["Content-length"], "0") self.assertEqual(req.unredirected_hdrs["Content-type"], @@ -907,13 +907,13 @@ class HandlerTests(unittest.TestCase): # now it's a GET, there should not be headers regarding content # (possibly dragged from before being a POST) headers = [x.lower() for x in o.req.headers] - self.assertTrue("content-length" not in headers) - self.assertTrue("content-type" not in headers) + self.assertNotIn("content-length", headers) + self.assertNotIn("content-type", headers) self.assertEqual(o.req.headers["Nonsense"], "viking=withhold") - self.assertTrue("Spam" not in o.req.headers) - self.assertTrue("Spam" not in o.req.unredirected_hdrs) + self.assertNotIn("Spam", o.req.headers) + self.assertNotIn("Spam", o.req.unredirected_hdrs) # loop detection req = Request(from_url) diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py index 9d0a8b1..39dd196 100644 --- a/Lib/test/test_userdict.py +++ b/Lib/test/test_userdict.py @@ -95,7 +95,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): # Test "in". for i in u2.keys(): - self.assertTrue(i in u2) + self.assertIn(i, u2) self.assertEqual(i in u1, i in d1) self.assertEqual(i in u0, i in d0) @@ -122,7 +122,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): # Test setdefault t = collections.UserDict() self.assertEqual(t.setdefault("x", 42), 42) - self.assertTrue("x" in t) + self.assertIn("x", t) self.assertEqual(t.setdefault("x", 23), 42) # Test pop @@ -152,8 +152,8 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): d = D({1: 2, 3: 4}) self.assertEqual(d[1], 2) self.assertEqual(d[3], 4) - self.assertTrue(2 not in d) - self.assertTrue(2 not in d.keys()) + self.assertNotIn(2, d) + self.assertNotIn(2, d.keys()) self.assertEqual(d[2], 42) class E(collections.UserDict): def __missing__(self, key): diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 7393d25..d5876a7 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -483,7 +483,7 @@ class _WarningsTests(BaseTest): with support.captured_output('stderr') as stream: self.module.warn(text) result = stream.getvalue() - self.assertTrue(text in result) + self.assertIn(text, result) def test_showwarning_not_callable(self): with original_warnings.catch_warnings(module=self.module): diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 028b418..57a098d 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -193,7 +193,7 @@ class ReferencesTestCase(TestBase): def __bytes__(self): return b"bytes" instance = C() - self.assertTrue("__bytes__" in dir(weakref.proxy(instance))) + self.assertIn("__bytes__", dir(weakref.proxy(instance))) self.assertEqual(bytes(weakref.proxy(instance)), b"bytes") def test_proxy_index(self): @@ -715,8 +715,8 @@ class SubclassableWeakrefTestCase(TestBase): refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertTrue(r2 is refs[0]) - self.assertTrue(r1 in refs[1:]) - self.assertTrue(r3 in refs[1:]) + self.assertIn(r1, refs[1:]) + self.assertIn(r3, refs[1:]) def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): @@ -726,8 +726,8 @@ class SubclassableWeakrefTestCase(TestBase): r2 = MyRef(o, str) self.assertTrue(r1 is not r2) refs = weakref.getweakrefs(o) - self.assertTrue(r1 in refs) - self.assertTrue(r2 in refs) + self.assertIn(r1, refs) + self.assertIn(r2, refs) def test_subclass_refs_with_slots(self): class MyRef(weakref.ref): @@ -860,8 +860,8 @@ class MappingTestCase(TestBase): "deleting the keys did not clear the dictionary") o = Object(42) dict[o] = "What is the meaning of the universe?" - self.assertTrue(o in dict) - self.assertTrue(34 not in dict) + self.assertIn(o, dict) + self.assertNotIn(34, dict) def test_weak_keyed_iters(self): dict, objects = self.make_weak_keyed_dict() @@ -873,8 +873,8 @@ class MappingTestCase(TestBase): objects2 = list(objects) for wr in refs: ob = wr() - self.assertTrue(ob in dict) - self.assertTrue(ob in dict) + self.assertIn(ob, dict) + self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) self.assertEqual(len(objects2), 0) @@ -884,8 +884,8 @@ class MappingTestCase(TestBase): self.assertEqual(len(list(dict.keyrefs())), len(objects)) for wr in dict.keyrefs(): ob = wr() - self.assertTrue(ob in dict) - self.assertTrue(ob in dict) + self.assertIn(ob, dict) + self.assertIn(ob, dict) self.assertEqual(ob.arg, dict[ob]) objects2.remove(ob) self.assertEqual(len(objects2), 0) @@ -1091,13 +1091,13 @@ class MappingTestCase(TestBase): weakdict = klass() o = weakdict.setdefault(key, value1) self.assertTrue(o is value1) - self.assertTrue(key in weakdict) + self.assertIn(key, weakdict) self.assertTrue(weakdict.get(key) is value1) self.assertTrue(weakdict[key] is value1) o = weakdict.setdefault(key, value2) self.assertTrue(o is value1) - self.assertTrue(key in weakdict) + self.assertIn(key, weakdict) self.assertTrue(weakdict.get(key) is value1) self.assertTrue(weakdict[key] is value1) diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py index 4e0aa38..0136d75 100644 --- a/Lib/test/test_weakset.py +++ b/Lib/test/test_weakset.py @@ -51,9 +51,9 @@ class TestWeakSet(unittest.TestCase): for c in self.letters: self.assertEqual(c in self.s, c in self.d) self.assertRaises(TypeError, self.s.__contains__, [[]]) - self.assertTrue(self.obj in self.fs) + self.assertIn(self.obj, self.fs) del self.obj - self.assertTrue(ustr('F') not in self.fs) + self.assertNotIn(ustr('F'), self.fs) def test_union(self): u = self.s.union(self.items2) @@ -150,7 +150,7 @@ class TestWeakSet(unittest.TestCase): s=H() f=set() f.add(s) - self.assertTrue(s in f) + self.assertIn(s, f) f.remove(s) f.add(s) f.discard(s) @@ -185,7 +185,7 @@ class TestWeakSet(unittest.TestCase): def test_add(self): x = ustr('Q') self.s.add(x) - self.assertTrue(x in self.s) + self.assertIn(x, self.s) dup = self.s.copy() self.s.add(x) self.assertEqual(self.s, dup) @@ -198,66 +198,66 @@ class TestWeakSet(unittest.TestCase): def test_remove(self): x = ustr('a') self.s.remove(x) - self.assertTrue(x not in self.s) + self.assertNotIn(x, self.s) self.assertRaises(KeyError, self.s.remove, x) self.assertRaises(TypeError, self.s.remove, []) def test_discard(self): a, q = ustr('a'), ustr('Q') self.s.discard(a) - self.assertTrue(a not in self.s) + self.assertNotIn(a, self.s) self.s.discard(q) self.assertRaises(TypeError, self.s.discard, []) def test_pop(self): for i in range(len(self.s)): elem = self.s.pop() - self.assertTrue(elem not in self.s) + self.assertNotIn(elem, self.s) self.assertRaises(KeyError, self.s.pop) def test_update(self): retval = self.s.update(self.items2) self.assertEqual(retval, None) for c in (self.items + self.items2): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) self.assertRaises(TypeError, self.s.update, [[]]) def test_update_set(self): self.s.update(set(self.items2)) for c in (self.items + self.items2): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) def test_ior(self): self.s |= set(self.items2) for c in (self.items + self.items2): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) def test_intersection_update(self): retval = self.s.intersection_update(self.items2) self.assertEqual(retval, None) for c in (self.items + self.items2): if c in self.items2 and c in self.items: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(TypeError, self.s.intersection_update, [[]]) def test_iand(self): self.s &= set(self.items2) for c in (self.items + self.items2): if c in self.items2 and c in self.items: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_difference_update(self): retval = self.s.difference_update(self.items2) self.assertEqual(retval, None) for c in (self.items + self.items2): if c in self.items and c not in self.items2: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(TypeError, self.s.difference_update, [[]]) self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) @@ -265,27 +265,27 @@ class TestWeakSet(unittest.TestCase): self.s -= set(self.items2) for c in (self.items + self.items2): if c in self.items and c not in self.items2: - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_symmetric_difference_update(self): retval = self.s.symmetric_difference_update(self.items2) self.assertEqual(retval, None) for c in (self.items + self.items2): if (c in self.items) ^ (c in self.items2): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) def test_ixor(self): self.s ^= set(self.items2) for c in (self.items + self.items2): if (c in self.items) ^ (c in self.items2): - self.assertTrue(c in self.s) + self.assertIn(c, self.s) else: - self.assertTrue(c not in self.s) + self.assertNotIn(c, self.s) def test_inplace_on_self(self): t = self.s.copy() @@ -348,7 +348,7 @@ class TestWeakSet(unittest.TestCase): self.assertFalse(u in s) with testcontext() as u: s.add(u) - self.assertTrue(u in s) + self.assertIn(u, s) t = s.copy() with testcontext() as u: s.update(t) diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 0b1a637..ab6096a 100755 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -440,7 +440,7 @@ class HeaderTests(TestCase): h.get("content-disposition")) del h['content-disposition'] - self.assertTrue(b'content-disposition' not in h) + self.assertNotIn(b'content-disposition', h) class ErrorHandler(BaseCGIHandler): @@ -493,7 +493,7 @@ class HandlerTests(TestCase): if k not in empty: self.assertEqual(env[k],v) for k,v in empty.items(): - self.assertTrue(k in env) + self.assertIn(k, env) def testEnviron(self): h = TestHandler(X="Y") @@ -506,7 +506,7 @@ class HandlerTests(TestCase): h = BaseCGIHandler(None,None,None,{}) h.setup_environ() for key in 'wsgi.url_scheme', 'wsgi.input', 'wsgi.errors': - self.assertTrue(key in h.environ) + self.assertIn(key, h.environ) def testScheme(self): h=TestHandler(HTTPS="on"); h.setup_environ() @@ -593,7 +593,7 @@ class HandlerTests(TestCase): "\r\n%s" % (h.error_status,len(h.error_body),h.error_body) ).encode("iso-8859-1")) - self.assertTrue("AssertionError" in h.stderr.getvalue()) + self.assertIn("AssertionError", h.stderr.getvalue()) def testErrorAfterOutput(self): MSG = "Some output has been sent" @@ -606,7 +606,7 @@ class HandlerTests(TestCase): self.assertEqual(h.stdout.getvalue(), ("Status: 200 OK\r\n" "\r\n"+MSG).encode("iso-8859-1")) - self.assertTrue("AssertionError" in h.stderr.getvalue()) + self.assertIn("AssertionError", h.stderr.getvalue()) def testHeaderFormats(self): diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 34b24c0..9aa11ac 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -63,9 +63,9 @@ class TestsWithSourceFile(unittest.TestCase): lines = directory.splitlines() self.assertEqual(len(lines), 4) # Number of files + header - self.assertTrue('File Name' in lines[0]) - self.assertTrue('Modified' in lines[0]) - self.assertTrue('Size' in lines[0]) + self.assertIn('File Name', lines[0]) + self.assertIn('Modified', lines[0]) + self.assertIn('Size', lines[0]) fn, date, time_, size = lines[1].split() self.assertEqual(fn, 'another.name') @@ -76,17 +76,17 @@ class TestsWithSourceFile(unittest.TestCase): # Check the namelist names = zipfp.namelist() self.assertEqual(len(names), 3) - self.assertTrue(TESTFN in names) - self.assertTrue("another.name" in names) - self.assertTrue("strfile" in names) + self.assertIn(TESTFN, names) + self.assertIn("another.name", names) + self.assertIn("strfile", names) # Check infolist infos = zipfp.infolist() names = [i.filename for i in infos] self.assertEqual(len(names), 3) - self.assertTrue(TESTFN in names) - self.assertTrue("another.name" in names) - self.assertTrue("strfile" in names) + self.assertIn(TESTFN, names) + self.assertIn("another.name", names) + self.assertIn("strfile", names) for i in infos: self.assertEqual(i.file_size, len(self.data)) @@ -459,9 +459,9 @@ class TestZip64InSmallFiles(unittest.TestCase): lines = directory.splitlines() self.assertEqual(len(lines), 4) # Number of files + header - self.assertTrue('File Name' in lines[0]) - self.assertTrue('Modified' in lines[0]) - self.assertTrue('Size' in lines[0]) + self.assertIn('File Name', lines[0]) + self.assertIn('Modified', lines[0]) + self.assertIn('Size', lines[0]) fn, date, time_, size = lines[1].split() self.assertEqual(fn, 'another.name') @@ -472,17 +472,17 @@ class TestZip64InSmallFiles(unittest.TestCase): # Check the namelist names = zipfp.namelist() self.assertEqual(len(names), 3) - self.assertTrue(TESTFN in names) - self.assertTrue("another.name" in names) - self.assertTrue("strfile" in names) + self.assertIn(TESTFN, names) + self.assertIn("another.name", names) + self.assertIn("strfile", names) # Check infolist infos = zipfp.infolist() names = [i.filename for i in infos] self.assertEqual(len(names), 3) - self.assertTrue(TESTFN in names) - self.assertTrue("another.name" in names) - self.assertTrue("strfile" in names) + self.assertIn(TESTFN, names) + self.assertIn("another.name", names) + self.assertIn("strfile", names) for i in infos: self.assertEqual(i.file_size, len(self.data)) @@ -528,7 +528,7 @@ class PyZipFileTests(unittest.TestCase): zipfp.writepy(fn) bn = os.path.basename(fn) - self.assertTrue(bn not in zipfp.namelist()) + self.assertNotIn(bn, zipfp.namelist()) self.assertTrue(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) @@ -540,7 +540,7 @@ class PyZipFileTests(unittest.TestCase): zipfp.writepy(fn, "testpackage") bn = "%s/%s" % ("testpackage", os.path.basename(fn)) - self.assertTrue(bn not in zipfp.namelist()) + self.assertNotIn(bn, zipfp.namelist()) self.assertTrue(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) @@ -577,7 +577,7 @@ class PyZipFileTests(unittest.TestCase): names = zipfp.namelist() self.assertTrue('mod1.pyc' in names or 'mod1.pyo' in names) self.assertTrue('mod2.pyc' in names or 'mod2.pyo' in names) - self.assertTrue('mod2.txt' not in names) + self.assertNotIn('mod2.txt', names) finally: shutil.rmtree(TESTFN2) diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 62440e1..0233934 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -294,7 +294,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): z.close() zi = zipimport.zipimporter(TEMP_ZIP) self.assertEquals(data, zi.get_data(name)) - self.assertTrue('zipimporter object' in repr(zi)) + self.assertIn('zipimporter object', repr(zi)) finally: z.close() os.remove(TEMP_ZIP) diff --git a/Lib/test/test_zipimport_support.py b/Lib/test/test_zipimport_support.py index 3a99eb7..a868ced 100644 --- a/Lib/test/test_zipimport_support.py +++ b/Lib/test/test_zipimport_support.py @@ -185,7 +185,7 @@ class ZipSupportTests(ImportHooksBaseTestCase): print ("Expected line", expected) print ("Got stdout:") print (data) - self.assertTrue(expected.encode('utf-8') in data) + self.assertIn(expected.encode('utf-8'), data) zip_name, run_name = make_zip_script(d, "test_zip", script_name, '__main__.py') exit_code, data = run_python(zip_name) @@ -194,7 +194,7 @@ class ZipSupportTests(ImportHooksBaseTestCase): print ("Expected line", expected) print ("Got stdout:") print (data) - self.assertTrue(expected.encode('utf-8') in data) + self.assertIn(expected.encode('utf-8'), data) def test_pdb_issue4201(self): test_src = textwrap.dedent("""\ @@ -209,13 +209,13 @@ class ZipSupportTests(ImportHooksBaseTestCase): p = spawn_python(script_name) p.stdin.write(b'l\n') data = kill_python(p) - self.assertTrue(script_name.encode('utf-8') in data) + self.assertIn(script_name.encode('utf-8'), data) zip_name, run_name = make_zip_script(d, "test_zip", script_name, '__main__.py') p = spawn_python(zip_name) p.stdin.write(b'l\n') data = kill_python(p) - self.assertTrue(run_name.encode('utf-8') in data) + self.assertIn(run_name.encode('utf-8'), data) def test_main(): -- cgit v0.12