diff --git a/.meta.toml b/.meta.toml index 733abde717..7c5b7b9370 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,7 +2,7 @@ # https://github.com/zopefoundation/meta/tree/master/config/zope-product [meta] template = "zope-product" -commit-id = "da0ad14b" +commit-id = "15e6a5a9" [python] with-pypy = false @@ -130,3 +130,6 @@ ignore-bad-ideas = [ ignore = [ "docs/locale/*/LC_MESSAGES/*.mo", ] + +[pre-commit] +teyit-exclude = "App/tests/fixtures/error\\.py" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d996f7755..52c1ca2a0c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,11 @@ repos: hooks: - id: pyupgrade args: [--py38-plus] + - repo: https://github.com/isidentical/teyit + rev: 0.4.3 + hooks: + - id: teyit + exclude: App/tests/fixtures/error\.py - repo: https://github.com/PyCQA/flake8 rev: "7.1.1" hooks: diff --git a/src/App/tests/test_ApplicationManager.py b/src/App/tests/test_ApplicationManager.py index ec227e16ab..8690f157b1 100644 --- a/src/App/tests/test_ApplicationManager.py +++ b/src/App/tests/test_ApplicationManager.py @@ -131,7 +131,7 @@ def test_holds_db(self): db = object() parent_jar = object() fc = self._makeOne(db, parent_jar) - self.assertTrue(fc.db() is db) + self.assertIs(fc.db(), db) class ConfigurationViewerTests(ConfigTestBase, unittest.TestCase): @@ -204,10 +204,10 @@ def test___getitem___hit(self): found = dc['foo'] self.assertIsInstance(found, AltDatabaseManager) self.assertEqual(found.id, 'foo') - self.assertTrue(found.__parent__ is dc) + self.assertIs(found.__parent__, dc) conn = found._p_jar self.assertIsInstance(conn, FakeConnection) - self.assertTrue(conn.db() is foo) + self.assertIs(conn.db(), foo) def test___bobo_traverse___miss(self): self._makeConfig(foo=object(), bar=object(), qux=object()) @@ -227,10 +227,10 @@ def test___bobo_traverse___hit_db(self): found = dc.__bobo_traverse__(None, 'foo') self.assertIsInstance(found, AltDatabaseManager) self.assertEqual(found.id, 'foo') - self.assertTrue(found.__parent__ is dc) + self.assertIs(found.__parent__, dc) conn = found._p_jar self.assertIsInstance(conn, FakeConnection) - self.assertTrue(conn.db() is foo) + self.assertIs(conn.db(), foo) def test___bobo_traverse___miss_db_hit_attr(self): foo = object() @@ -241,7 +241,7 @@ def test___bobo_traverse___miss_db_hit_attr(self): dc = self._makeOne().__of__(root) dc.spam = spam = object() found = dc.__bobo_traverse__(None, 'spam') - self.assertTrue(found is spam) + self.assertIs(found, spam) class ApplicationManagerTests(ConfigTestBase, unittest.TestCase): @@ -493,11 +493,11 @@ def test_refcount_no_limit(self): pairs = dm.refcount() # XXX : Ugly empiricism here: I don't know why the count is up 1. foo_count = sys.getrefcount(Foo) - self.assertTrue((foo_count + 1, 'foo.Foo') in pairs) + self.assertIn((foo_count + 1, 'foo.Foo'), pairs) bar_count = sys.getrefcount(Bar) - self.assertTrue((bar_count + 1, 'foo.Bar') in pairs) + self.assertIn((bar_count + 1, 'foo.Bar'), pairs) baz_count = sys.getrefcount(Baz) - self.assertTrue((baz_count + 1, 'qux.Baz') in pairs) + self.assertIn((baz_count + 1, 'qux.Baz'), pairs) def test_refdict(self): import sys @@ -539,7 +539,7 @@ def test_rcdate(self): dm = self._makeOne('test') found = dm.rcdate() App.ApplicationManager._v_rst = None - self.assertTrue(found is dummy) + self.assertIs(found, dummy) def test_rcdeltas(self): dm = self._makeOne('test') @@ -548,8 +548,8 @@ def test_rcdeltas(self): mappings = dm.rcdeltas() self.assertTrue(len(mappings)) mapping = mappings[0] - self.assertTrue('rc' in mapping) - self.assertTrue('pc' in mapping) + self.assertIn('rc', mapping) + self.assertIn('pc', mapping) self.assertEqual(mapping['delta'], mapping['rc'] - mapping['pc']) # def test_dbconnections(self): XXX -- TOO UGLY TO TEST diff --git a/src/OFS/tests/testAppInitializer.py b/src/OFS/tests/testAppInitializer.py index c305793e71..086a2896de 100644 --- a/src/OFS/tests/testAppInitializer.py +++ b/src/OFS/tests/testAppInitializer.py @@ -84,7 +84,7 @@ def test_install_virtual_hosting(self): i = self.getOne() i.install_virtual_hosting() app = i.getApp() - self.assertTrue('virtual_hosting' in app) + self.assertIn('virtual_hosting', app) self.assertEqual( app.virtual_hosting.meta_type, 'Virtual Host Monster') @@ -93,8 +93,8 @@ def test_install_required_roles(self): i = self.getOne() i.install_required_roles() app = i.getApp() - self.assertTrue('Owner' in app.__ac_roles__) - self.assertTrue('Authenticated' in app.__ac_roles__) + self.assertIn('Owner', app.__ac_roles__) + self.assertIn('Authenticated', app.__ac_roles__) def test_install_inituser(self): fname = os.path.join(self.TEMPNAME, 'inituser') @@ -122,7 +122,7 @@ def test_install_root_view(self): i = self.getOne() i.install_root_view() app = i.getApp() - self.assertTrue('index_html' in app) + self.assertIn('index_html', app) self.assertEqual(app.index_html.meta_type, 'Page Template') def test_install_products_which_need_the_application(self): diff --git a/src/OFS/tests/testCopySupport.py b/src/OFS/tests/testCopySupport.py index a6905e8cb7..38fa697f99 100644 --- a/src/OFS/tests/testCopySupport.py +++ b/src/OFS/tests/testCopySupport.py @@ -138,56 +138,56 @@ def test_interfaces(self): verifyClass(ICopySource, CopySource) def testRename(self): - self.assertTrue('file' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) self.folder1.manage_renameObject(id='file', new_id='filex') - self.assertFalse('file' in self.folder1.objectIds()) - self.assertTrue('filex' in self.folder1.objectIds()) + self.assertNotIn('file', self.folder1.objectIds()) + self.assertIn('filex', self.folder1.objectIds()) def testCopy(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) cookie = self.folder1.manage_copyObjects(ids=('file',)) self.folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) def testCut(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) cookie = self.folder1.manage_cutObjects(ids=('file',)) self.folder2.manage_pasteObjects(cookie) - self.assertFalse('file' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) + self.assertNotIn('file', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) def testCopyNewObject(self): - self.assertFalse('newfile' in self.folder1.objectIds()) + self.assertNotIn('newfile', self.folder1.objectIds()) manage_addFile(self.folder1, 'newfile', file=b'', content_type='text/plain') cookie = self.folder1.manage_copyObjects(ids=('newfile',)) self.folder2.manage_pasteObjects(cookie) - self.assertTrue('newfile' in self.folder1.objectIds()) - self.assertTrue('newfile' in self.folder2.objectIds()) + self.assertIn('newfile', self.folder1.objectIds()) + self.assertIn('newfile', self.folder2.objectIds()) def testPasteSingleNotSameID(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) cookie = self.folder1.manage_copyObjects(ids=('file',)) result = self.folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) - self.assertTrue(result == [{'id': 'file', 'new_id': 'file'}]) + self.assertIn('file', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) + self.assertEqual(result, [{'id': 'file', 'new_id': 'file'}]) def testPasteSingleSameID(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) manage_addFile(self.folder2, 'file', file=b'', content_type='text/plain') cookie = self.folder1.manage_copyObjects(ids=('file',)) result = self.folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) - self.assertTrue('copy_of_file' in self.folder2.objectIds()) - self.assertTrue(result == [{'id': 'file', 'new_id': 'copy_of_file'}]) + self.assertIn('file', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) + self.assertIn('copy_of_file', self.folder2.objectIds()) + self.assertEqual(result, [{'id': 'file', 'new_id': 'copy_of_file'}]) def testPasteSingleSameIDMultipleTimes(self): cookie = self.folder1.manage_copyObjects(ids=('file',)) @@ -227,25 +227,25 @@ def testPasteSpecialName(self): self.assertEqual(result, [{'id': 'copy_of_', 'new_id': 'copy2_of_'}]) def testPasteMultiNotSameID(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file1' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file1', self.folder1.objectIds()) manage_addFile(self.folder1, 'file1', file=b'', content_type='text/plain') - self.assertFalse('file2' in self.folder1.objectIds()) + self.assertNotIn('file2', self.folder1.objectIds()) manage_addFile(self.folder1, 'file2', file=b'', content_type='text/plain') - self.assertFalse('file' in self.folder2.objectIds()) - self.assertFalse('file1' in self.folder2.objectIds()) - self.assertFalse('file2' in self.folder2.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) + self.assertNotIn('file1', self.folder2.objectIds()) + self.assertNotIn('file2', self.folder2.objectIds()) cookie = self.folder1.manage_copyObjects( ids=('file', 'file1', 'file2',)) result = self.folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in self.folder1.objectIds()) - self.assertTrue('file1' in self.folder1.objectIds()) - self.assertTrue('file2' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) - self.assertTrue('file1' in self.folder2.objectIds()) - self.assertTrue('file2' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertIn('file1', self.folder1.objectIds()) + self.assertIn('file2', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) + self.assertIn('file1', self.folder2.objectIds()) + self.assertIn('file2', self.folder2.objectIds()) self.assertEqual(result, [ {'id': 'file', 'new_id': 'file'}, {'id': 'file1', 'new_id': 'file1'}, @@ -253,34 +253,34 @@ def testPasteMultiNotSameID(self): ]) def testPasteMultiSameID(self): - self.assertTrue('file' in self.folder1.objectIds()) - self.assertFalse('file1' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertNotIn('file1', self.folder1.objectIds()) manage_addFile(self.folder1, 'file1', file=b'', content_type='text/plain') - self.assertFalse('file2' in self.folder1.objectIds()) + self.assertNotIn('file2', self.folder1.objectIds()) manage_addFile(self.folder1, 'file2', file=b'', content_type='text/plain') - self.assertFalse('file' in self.folder2.objectIds()) + self.assertNotIn('file', self.folder2.objectIds()) manage_addFile(self.folder2, 'file', file=b'', content_type='text/plain') - self.assertFalse('file1' in self.folder2.objectIds()) + self.assertNotIn('file1', self.folder2.objectIds()) manage_addFile(self.folder2, 'file1', file=b'', content_type='text/plain') - self.assertFalse('file2' in self.folder2.objectIds()) + self.assertNotIn('file2', self.folder2.objectIds()) manage_addFile(self.folder2, 'file2', file=b'', content_type='text/plain') cookie = self.folder1.manage_copyObjects( ids=('file', 'file1', 'file2',)) result = self.folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in self.folder1.objectIds()) - self.assertTrue('file1' in self.folder1.objectIds()) - self.assertTrue('file2' in self.folder1.objectIds()) - self.assertTrue('file' in self.folder2.objectIds()) - self.assertTrue('file1' in self.folder2.objectIds()) - self.assertTrue('file2' in self.folder2.objectIds()) - self.assertTrue('copy_of_file' in self.folder2.objectIds()) - self.assertTrue('copy_of_file1' in self.folder2.objectIds()) - self.assertTrue('copy_of_file2' in self.folder2.objectIds()) + self.assertIn('file', self.folder1.objectIds()) + self.assertIn('file1', self.folder1.objectIds()) + self.assertIn('file2', self.folder1.objectIds()) + self.assertIn('file', self.folder2.objectIds()) + self.assertIn('file1', self.folder2.objectIds()) + self.assertIn('file2', self.folder2.objectIds()) + self.assertIn('copy_of_file', self.folder2.objectIds()) + self.assertIn('copy_of_file1', self.folder2.objectIds()) + self.assertIn('copy_of_file2', self.folder2.objectIds()) self.assertEqual(result, [ {'id': 'file', 'new_id': 'copy_of_file'}, {'id': 'file1', 'new_id': 'copy_of_file1'}, @@ -408,14 +408,14 @@ def test_copy_baseline(self): self._initPolicyAndUser() - self.assertTrue('file' in folder1.objectIds()) - self.assertFalse('file' in folder2.objectIds()) + self.assertIn('file', folder1.objectIds()) + self.assertNotIn('file', folder2.objectIds()) cookie = folder1.manage_copyObjects(ids=('file', )) folder2.manage_pasteObjects(cookie) - self.assertTrue('file' in folder1.objectIds()) - self.assertTrue('file' in folder2.objectIds()) + self.assertIn('file', folder1.objectIds()) + self.assertIn('file', folder2.objectIds()) def test_copy_cant_read_source(self): folder1, folder2 = self._initFolders() @@ -472,24 +472,24 @@ def test_copy_cant_copy_invisible_items(self): new_id = copy_info[0]['new_id'] new_folder = folder2[new_id] # The private item should not be in the copy. - self.assertTrue('private' not in new_folder.objectIds()) + self.assertNotIn('private', new_folder.objectIds()) # There is nothing wrong with copying the public item. - self.assertTrue('public' in new_folder.objectIds()) + self.assertIn('public', new_folder.objectIds()) def test_move_baseline(self): folder1, folder2 = self._initFolders() folder2.all_meta_types = FILE_META_TYPES - self.assertTrue('file' in folder1.objectIds()) - self.assertFalse('file' in folder2.objectIds()) + self.assertIn('file', folder1.objectIds()) + self.assertNotIn('file', folder2.objectIds()) self._initPolicyAndUser() cookie = folder1.manage_cutObjects(ids=('file', )) folder2.manage_pasteObjects(cookie) - self.assertFalse('file' in folder1.objectIds()) - self.assertTrue('file' in folder2.objectIds()) + self.assertNotIn('file', folder1.objectIds()) + self.assertIn('file', folder2.objectIds()) def test_move_cant_read_source(self): folder1, folder2 = self._initFolders() diff --git a/src/OFS/tests/testFileAndImage.py b/src/OFS/tests/testFileAndImage.py index b35102ae23..45ec9a21e4 100644 --- a/src/OFS/tests/testFileAndImage.py +++ b/src/OFS/tests/testFileAndImage.py @@ -152,12 +152,16 @@ def setUp(self): # Since we do the create here, let's test the events here too self.assertEqual(1, len(self.eventCatcher.created)) - self.assertTrue( - aq_base(self.eventCatcher.created[0].object) is aq_base(self.file)) + self.assertIs( + aq_base(self.eventCatcher.created[0].object), + aq_base(self.file) + ) self.assertEqual(1, len(self.eventCatcher.modified)) - self.assertTrue( - aq_base(self.eventCatcher.created[0].object) is aq_base(self.file)) + self.assertIs( + aq_base(self.eventCatcher.created[0].object), + aq_base(self.file) + ) self.eventCatcher.reset() @@ -207,7 +211,7 @@ def testManageEditWithFileData(self): self.assertTrue(ADummyCache.invalidated) self.assertTrue(ADummyCache.set) self.assertEqual(1, len(self.eventCatcher.modified)) - self.assertTrue(self.eventCatcher.modified[0].object is self.file) + self.assertIs(self.eventCatcher.modified[0].object, self.file) def testManageEditWithoutFileData(self): self.file.manage_edit('foobar', 'text/plain') @@ -215,7 +219,7 @@ def testManageEditWithoutFileData(self): self.assertEqual(self.file.content_type, 'text/plain') self.assertTrue(ADummyCache.invalidated) self.assertEqual(1, len(self.eventCatcher.modified)) - self.assertTrue(self.eventCatcher.modified[0].object is self.file) + self.assertIs(self.eventCatcher.modified[0].object, self.file) def testManageUpload(self): f = BytesIO(b'jammyjohnson') @@ -223,7 +227,7 @@ def testManageUpload(self): self.assertEqual(self.file.data, b'jammyjohnson') self.assertEqual(self.file.content_type, 'application/octet-stream') self.assertEqual(1, len(self.eventCatcher.modified)) - self.assertTrue(self.eventCatcher.modified[0].object is self.file) + self.assertIs(self.eventCatcher.modified[0].object, self.file) def testManageUploadWithoutFileData(self): self.file.manage_upload() @@ -297,7 +301,7 @@ def testPrincipiaSearchSource_text(self): self.file.manage_edit('foobar', 'text/plain', filedata=b'Now is the time for all good men to ' b'come to the aid of the Party.') - self.assertTrue(b'Party' in self.file.PrincipiaSearchSource()) + self.assertIn(b'Party', self.file.PrincipiaSearchSource()) def test_manage_DAVget_binary(self): self.assertEqual(self.file.manage_DAVget(), self.data) diff --git a/src/OFS/tests/testHistory.py b/src/OFS/tests/testHistory.py index db25c1467a..0ff5dccae2 100644 --- a/src/OFS/tests/testHistory.py +++ b/src/OFS/tests/testHistory.py @@ -77,14 +77,14 @@ def test_manage_change_history(self): self.assertEqual(len(entry.keys()), 6) # the transactions are in newest-first order self.assertEqual(entry['description'], 'Change %i' % (3 - i)) - self.assertTrue('key' in entry) + self.assertIn('key', entry) # lets not assume the size will stay the same forever - self.assertTrue('size' in entry) - self.assertTrue('tid' in entry) - self.assertTrue('time' in entry) + self.assertIn('size', entry) + self.assertIn('tid', entry) + self.assertIn('time', entry) if i: # check times are increasing - self.assertTrue(entry['time'] < r[i - 1]['time']) + self.assertLess(entry['time'], r[i - 1]['time']) self.assertEqual(entry['user_name'], '') def test_manage_historyCopy(self): diff --git a/src/OFS/tests/testObjectManager.py b/src/OFS/tests/testObjectManager.py index edb26b350d..d42c10292a 100644 --- a/src/OFS/tests/testObjectManager.py +++ b/src/OFS/tests/testObjectManager.py @@ -328,15 +328,15 @@ def test_manage_delObjects(self): ob = ItemForDeletion() om._setObject('stuff', ob) om.manage_delObjects('stuff') - self.assertFalse('stuff' in om) + self.assertNotIn('stuff', om) om._setObject('stuff', ob) om.manage_delObjects(['stuff']) - self.assertFalse('stuff' in om) + self.assertNotIn('stuff', om) om._setObject('stuff', ob) om.manage_delObjects('stuff') - self.assertFalse('stuff' in om) + self.assertNotIn('stuff', om) def test_hasObject(self): om = self._makeOne() @@ -401,13 +401,13 @@ def test_getsetitem(self): si1 = SimpleItem('1') si2 = SimpleItem('2') om['1'] = si1 - self.assertTrue('1' in om) - self.assertTrue(si1 in om.objectValues()) - self.assertTrue('1' in om.objectIds()) + self.assertIn('1', om) + self.assertIn(si1, om.objectValues()) + self.assertIn('1', om.objectIds()) om['2'] = si2 - self.assertTrue('2' in om) - self.assertTrue(si2 in om.objectValues()) - self.assertTrue('2' in om.objectIds()) + self.assertIn('2', om) + self.assertIn(si2, om.objectValues()) + self.assertIn('2', om.objectIds()) self.assertRaises(BadRequest, om._setObject, '1', si2) self.assertRaises(BadRequest, om.__setitem__, '1', si2) @@ -417,13 +417,13 @@ def test_delitem(self): si2 = SimpleItem('2') om['1'] = si1 om['2'] = si2 - self.assertTrue('1' in om) - self.assertTrue('2' in om) + self.assertIn('1', om) + self.assertIn('2', om) del om['1'] - self.assertFalse('1' in om) - self.assertTrue('2' in om) + self.assertNotIn('1', om) + self.assertIn('2', om) om._delObject('2') - self.assertFalse('2' in om) + self.assertNotIn('2', om) def test_iterator(self): om = self._makeOne() @@ -435,8 +435,8 @@ def test_iterator(self): self.assertTrue(hasattr(iterator, '__iter__')) self.assertTrue(hasattr(iterator, '__next__')) result = [i for i in iterator] - self.assertTrue('1' in result) - self.assertTrue('2' in result) + self.assertIn('1', result) + self.assertIn('2', result) def test_len(self): om = self._makeOne() @@ -444,7 +444,7 @@ def test_len(self): si2 = SimpleItem('2') om['1'] = si1 om['2'] = si2 - self.assertTrue(len(om) == 2) + self.assertEqual(len(om), 2) def test_nonzero(self): om = self._makeOne() @@ -463,8 +463,8 @@ def test___getitem___hit(self): si1 = SimpleItem('1') om['1'] = si1 got = om['1'] - self.assertTrue(aq_self(got) is si1) - self.assertTrue(got.__parent__ is om) + self.assertIs(aq_self(got), si1) + self.assertIs(got.__parent__, om) def test_get_miss_wo_default(self): om = self._makeOne() @@ -473,7 +473,7 @@ def test_get_miss_wo_default(self): def test_get_miss_w_default(self): om = self._makeOne() obj = object() - self.assertTrue(om.get('nonesuch', obj) is obj) + self.assertIs(om.get('nonesuch', obj), obj) def test_get_miss_w_non_instance_attr(self): om = self._makeOne() @@ -484,26 +484,26 @@ def test_get_hit(self): si1 = SimpleItem('1') om['1'] = si1 got = om.get('1') - self.assertTrue(aq_self(got) is si1) - self.assertTrue(got.__parent__ is om) + self.assertIs(aq_self(got), si1) + self.assertIs(got.__parent__, om) def test_items(self): om = self._makeOne() si1 = SimpleItem('1') om['1'] = si1 - self.assertTrue(('1', si1) in list(om.items())) + self.assertIn(('1', si1), list(om.items())) def test_keys(self): om = self._makeOne() si1 = SimpleItem('1') om['1'] = si1 - self.assertTrue('1' in list(om.keys())) + self.assertIn('1', list(om.keys())) def test_values(self): om = self._makeOne() si1 = SimpleItem('1') om['1'] = si1 - self.assertTrue(si1 in list(om.values())) + self.assertIn(si1, list(om.values())) def test_list_imports(self): om = self._makeOne() @@ -512,7 +512,7 @@ def test_list_imports(self): # in skel/import. Tolerate both cases. self.assertIsInstance(om.list_imports(), list) for filename in om.list_imports(): - self.assertTrue(os.path.splitext(filename)[1] in ('.zexp', '.xml')) + self.assertIn(os.path.splitext(filename)[1], ('.zexp', '.xml')) def test_manage_get_sortedObjects_quote_id(self): # manage_get_sortedObjects now returns a urlquoted version diff --git a/src/OFS/tests/testRanges.py b/src/OFS/tests/testRanges.py index b334f6f3bd..f110f377a3 100644 --- a/src/OFS/tests/testRanges.py +++ b/src/OFS/tests/testRanges.py @@ -128,11 +128,11 @@ def expectUnsatisfiable(self, range): body = self.doGET(req, rsp) - self.assertTrue(rsp.getStatus() == 416) + self.assertEqual(rsp.getStatus(), 416) expect_content_range = 'bytes */%d' % len(self.data) content_range = rsp.getHeader('content-range') - self.assertFalse(content_range is None) + self.assertIsNotNone(content_range) self.assertEqual(content_range, expect_content_range) self.assertEqual(body, b'') @@ -163,7 +163,7 @@ def expectSingleRange(self, range, start, end, if_range=None): expect_content_range = 'bytes %d-%d/%d' % ( start, end - 1, len(self.data)) content_range = rsp.getHeader('content-range') - self.assertFalse(content_range is None) + self.assertIsNotNone(content_range) self.assertEqual(content_range, expect_content_range) self.assertEqual(rsp.getHeader('content-length'), str(len(body))) self.assertEqual(body, self.data[start:end]) @@ -184,7 +184,7 @@ def expectMultipleRanges(self, range, sets, draft=0): body = self.doGET(req, rsp) - self.assertTrue(rsp.getStatus() == 206) + self.assertEqual(rsp.getStatus(), 206) self.assertFalse(rsp.getHeader('content-range')) ct = rsp.getHeader('content-type').split(';')[0] diff --git a/src/OFS/tests/testSimpleItem.py b/src/OFS/tests/testSimpleItem.py index 5ae1cb1f4b..4fb858bf3a 100644 --- a/src/OFS/tests/testSimpleItem.py +++ b/src/OFS/tests/testSimpleItem.py @@ -42,7 +42,7 @@ def _raise_during_standard_error_message(*args, **kw): self.assertEqual(sys.exc_info()[0], OverflowError) value = sys.exc_info()[1] self.assertTrue(value.message.startswith("'simple'")) - self.assertTrue('full details: testing' in value.message) + self.assertIn('full details: testing', value.message) def test_raise_StandardErrorMessage_TaintedString_errorValue(self): from AccessControl.tainted import TaintedString @@ -65,7 +65,7 @@ def _raise_during_standard_error_message(*args, **kw): import sys self.assertEqual(sys.exc_info()[0], OverflowError) value = sys.exc_info()[1] - self.assertFalse('<' in value.message) + self.assertNotIn('<', value.message) class TestItem_w__name__(unittest.TestCase): diff --git a/src/OFS/tests/testTraverse.py b/src/OFS/tests/testTraverse.py index 32e0798549..68f63bfc7a 100644 --- a/src/OFS/tests/testTraverse.py +++ b/src/OFS/tests/testTraverse.py @@ -227,18 +227,18 @@ def test_interfaces(self): verifyClass(ITraversable, Traversable) def testTraversePath(self): - self.assertTrue('file' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) self.assertTrue( self.folder1.unrestrictedTraverse(('', 'folder1', 'file'))) self.assertTrue(self.folder1.unrestrictedTraverse(('', 'folder1'))) def testTraverseURLNoSlash(self): - self.assertTrue('file' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) self.assertTrue(self.folder1.unrestrictedTraverse('/folder1/file')) self.assertTrue(self.folder1.unrestrictedTraverse('/folder1')) def testTraverseURLSlash(self): - self.assertTrue('file' in self.folder1.objectIds()) + self.assertIn('file', self.folder1.objectIds()) self.assertTrue(self.folder1.unrestrictedTraverse('/folder1/file/')) self.assertTrue(self.folder1.unrestrictedTraverse('/folder1/')) @@ -274,8 +274,10 @@ def testBoboTraverseToMethod(self): # Verify it's possible to use __bobo_traverse__ to a method. self._setupSecurity() bb = self._makeBoboTraversable() - self.assertTrue( - bb.restrictedTraverse('bb_method') is not bb.bb_method) + self.assertIsNot( + bb.restrictedTraverse('bb_method'), + bb.bb_method + ) def testBoboTraverseToSimpleAttrValue(self): # Verify it's possible to use __bobo_traverse__ to a simple @@ -291,8 +293,10 @@ def testBoboTraverseToNonAttrValue(self): # is fine, but to test the code branch we sub in the forgiving one self._setupSecurity(UnitTestSecurityPolicy()) bb = self._makeBoboTraversable() - self.assertTrue( - bb.restrictedTraverse('manufactured') == 42) + self.assertEqual( + bb.restrictedTraverse('manufactured'), + 42 + ) def testBoboTraverseToAcquiredObject(self): # Verify it's possible to use a __bobo_traverse__ which retrieves @@ -424,14 +428,17 @@ def testDefaultValueWhenNotFound(self): def testTraverseUp(self): # Test that we can traverse upwards from Acquisition import aq_base - self.assertTrue( - aq_base(self.root.folder1.file.restrictedTraverse('../..')) is - aq_base(self.root)) + self.assertIs( + aq_base(self.root.folder1.file.restrictedTraverse('../..')), + aq_base(self.root) + ) def testTraverseToNameStartingWithPlus(self): # Verify it's possible to traverse to a name such as +something - self.assertTrue( - self.folder1.unrestrictedTraverse('+something') == 'plus') + self.assertEqual( + self.folder1.unrestrictedTraverse('+something'), + 'plus' + ) def testTraverseWrongType(self): with self.assertRaises(TypeError): diff --git a/src/OFS/tests/test_DTMLDocument.py b/src/OFS/tests/test_DTMLDocument.py index 86c8b76864..5806e3337d 100644 --- a/src/OFS/tests/test_DTMLDocument.py +++ b/src/OFS/tests/test_DTMLDocument.py @@ -75,8 +75,8 @@ def test_defaults_no_standard_html_header(self): addDTMLDocument(dispatcher, 'id') method = dispatcher._set['id'] self.assertIsInstance(method, DTMLDocument) - self.assertFalse('standard_html_header' in method.read()) - self.assertFalse('standard_html_footer' in method.read()) + self.assertNotIn('standard_html_header', method.read()) + self.assertNotIn('standard_html_footer', method.read()) class DummyDispatcher: diff --git a/src/OFS/tests/test_DTMLMethod.py b/src/OFS/tests/test_DTMLMethod.py index af2064cd35..ca26194d3d 100644 --- a/src/OFS/tests/test_DTMLMethod.py +++ b/src/OFS/tests/test_DTMLMethod.py @@ -268,8 +268,8 @@ def test_defaults_no_standard_html_header(self): addDTMLMethod(dispatcher, 'id') method = dispatcher._set['id'] self.assertIsInstance(method, DTMLMethod) - self.assertFalse('standard_html_header' in method.read()) - self.assertFalse('standard_html_footer' in method.read()) + self.assertNotIn('standard_html_header', method.read()) + self.assertNotIn('standard_html_footer', method.read()) class DummyDispatcher: diff --git a/src/OFS/tests/test_Uninstalled.py b/src/OFS/tests/test_Uninstalled.py index 7ea9937577..288a5d6b85 100644 --- a/src/OFS/tests/test_Uninstalled.py +++ b/src/OFS/tests/test_Uninstalled.py @@ -76,7 +76,7 @@ def test_Broken_product_with_oid_yields_instance_derived_from_Broken(self): inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass')) self.assertIsInstance(inst, BrokenClass) - self.assertTrue(inst._p_jar is self) + self.assertIs(inst._p_jar, self) self.assertEqual(inst._p_oid, OID) klass = inst.__class__ @@ -137,7 +137,7 @@ def test_Broken_instance___getstate___gives_access_to_its_state(self): transaction.commit() # check that object is not left over app = base.app() - self.assertFalse('tr' in app.objectIds()) + self.assertNotIn('tr', app.objectIds()) def test_suite(): diff --git a/src/OFS/tests/test_userfolder.py b/src/OFS/tests/test_userfolder.py index b9217a2dbc..180627e870 100644 --- a/src/OFS/tests/test_userfolder.py +++ b/src/OFS/tests/test_userfolder.py @@ -91,8 +91,8 @@ def testGetRolesInContext(self): user = uf.getUser('user1') app.manage_addLocalRoles('user1', ['Owner']) roles = user.getRolesInContext(app) - self.assertTrue('role1' in roles) - self.assertTrue('Owner' in roles) + self.assertIn('role1', roles) + self.assertIn('Owner', roles) def testHasRole(self): app = self._makeApp() diff --git a/src/Products/Five/browser/tests/test_metaconfigure.py b/src/Products/Five/browser/tests/test_metaconfigure.py index a8cbc94272..a503f8ecab 100644 --- a/src/Products/Five/browser/tests/test_metaconfigure.py +++ b/src/Products/Five/browser/tests/test_metaconfigure.py @@ -34,47 +34,47 @@ def test_publishTraverse_w_index_returns_index(self): request = DummyRequest() view = self._makeOne(request=request) index = view.index = DummyTemplate() - self.assertTrue(view.publishTraverse(request, 'index.html') is index) + self.assertIs(view.publishTraverse(request, 'index.html'), index) def test___getitem___uses_index_macros(self): view = self._makeOne() view.index = index = DummyTemplate() index.macros = {} index.macros['aaa'] = aaa = object() - self.assertTrue(view['aaa'] is aaa) + self.assertIs(view['aaa'], aaa) def test__getitem__gives_shortcut_to_index_macros(self): view = self._makeOne() view.index = index = DummyTemplate() index.macros = {} - self.assertTrue(view['macros'] is index.macros) + self.assertIs(view['macros'], index.macros) def test___call___no_args_no_kw(self): view = self._makeOne() view.index = index = DummyTemplate() result = view() - self.assertTrue(result is index) + self.assertIs(result, index) self.assertEqual(index._called_with, ((), {})) def test___call___w_args_no_kw(self): view = self._makeOne() view.index = index = DummyTemplate() result = view('abc') - self.assertTrue(result is index) + self.assertIs(result, index) self.assertEqual(index._called_with, (('abc',), {})) def test___call___no_args_w_kw(self): view = self._makeOne() view.index = index = DummyTemplate() result = view(foo='bar') - self.assertTrue(result is index) + self.assertIs(result, index) self.assertEqual(index._called_with, ((), {'foo': 'bar'})) def test___call___w_args_w_kw(self): view = self._makeOne() view.index = index = DummyTemplate() result = view('abc', foo='bar') - self.assertTrue(result is index) + self.assertIs(result, index) self.assertEqual(index._called_with, (('abc',), {'foo': 'bar'})) diff --git a/src/Products/Five/browser/tests/test_pagetemplatefile.py b/src/Products/Five/browser/tests/test_pagetemplatefile.py index 0d2ae0f209..651547e506 100644 --- a/src/Products/Five/browser/tests/test_pagetemplatefile.py +++ b/src/Products/Five/browser/tests/test_pagetemplatefile.py @@ -68,17 +68,17 @@ def test_pt_getContext_no_kw_no_physicalRoot(self): view = self._makeView(context, request) vptf = self._makeOne('seagull.pt') namespace = vptf.pt_getContext(view, request) - self.assertTrue(namespace['context'] is context) - self.assertTrue(namespace['request'] is request) + self.assertIs(namespace['context'], context) + self.assertIs(namespace['request'], request) views = namespace['views'] self.assertIsInstance(views, ViewMapper) self.assertEqual(views.ob, context) self.assertEqual(views.request, request) - self.assertTrue(namespace['here'] is context) - self.assertTrue(namespace['container'] is context) - self.assertTrue(namespace['root'] is None) + self.assertIs(namespace['here'], context) + self.assertIs(namespace['container'], context) + self.assertIsNone(namespace['root']) modules = namespace['modules'] - self.assertTrue(modules is SecureModuleImporter) + self.assertIs(modules, SecureModuleImporter) self.assertEqual(namespace['traverse_subpath'], []) self.assertEqual(namespace['user'].getId(), 'a_user') @@ -92,7 +92,7 @@ def test_pt_getContext_w_physicalRoot(self): view = self._makeView(context, request) vptf = self._makeOne('seagull.pt') namespace = vptf.pt_getContext(view, request) - self.assertTrue(namespace['root'] is root) + self.assertIs(namespace['root'], root) def test_pt_getContext_w_ignored_kw(self): from AccessControl.SecurityManagement import newSecurityManager @@ -102,8 +102,8 @@ def test_pt_getContext_w_ignored_kw(self): view = self._makeView(context, request) vptf = self._makeOne('seagull.pt') namespace = vptf.pt_getContext(view, request, foo='bar') - self.assertFalse('foo' in namespace) - self.assertFalse('foo' in namespace['options']) + self.assertNotIn('foo', namespace) + self.assertNotIn('foo', namespace['options']) def test_pt_getContext_w_args_kw(self): from AccessControl.SecurityManagement import newSecurityManager @@ -160,8 +160,8 @@ def __init__(self, context, request): foo = Foo(context, request) bound = foo.bar self.assertIsInstance(bound, BoundPageTemplate) - self.assertTrue(bound.__func__ is template) - self.assertTrue(bound.__self__ is foo) + self.assertIs(bound.__func__, template) + self.assertIs(bound.__self__, foo) class ViewMapperTests(unittest.TestCase): @@ -199,7 +199,7 @@ def _adapt(context, request): provideAdapter(_adapt, (None, None), Interface, name='test') mapper = self._makeOne() - self.assertTrue(mapper['test'] is self) + self.assertIs(mapper['test'], self) _marker = object() @@ -222,9 +222,9 @@ def test___init__(self): pt = DummyTemplate({'foo': 'bar'}) ob = DummyContext() bpt = self._makeOne(pt, ob) - self.assertTrue(bpt.__func__ is pt) - self.assertTrue(bpt.__self__ is ob) - self.assertTrue(bpt.__parent__ is ob) + self.assertIs(bpt.__func__, pt) + self.assertIs(bpt.__self__, ob) + self.assertIs(bpt.__parent__, ob) self.assertEqual(bpt.macros['foo'], 'bar') self.assertEqual(bpt.filename, 'dummy.pt') diff --git a/src/Products/Five/utilities/browser/tests/test_marker.py b/src/Products/Five/utilities/browser/tests/test_marker.py index f67b90138c..e55d56373e 100644 --- a/src/Products/Five/utilities/browser/tests/test_marker.py +++ b/src/Products/Five/utilities/browser/tests/test_marker.py @@ -53,7 +53,7 @@ def test_editview(self): view = EditView(obj, {}) # Test state before making any changes - self.assertTrue(view.context.aq_inner is obj) + self.assertIs(view.context.aq_inner, obj) self.assertEqual(view.request, {}) self.assertEqual(view.getAvailableInterfaceNames(), []) self.assertEqual(view.getDirectlyProvidedNames(), []) diff --git a/src/Products/PageTemplates/tests/testExpressions.py b/src/Products/PageTemplates/tests/testExpressions.py index 81c321e4ae..0b73be7419 100644 --- a/src/Products/PageTemplates/tests/testExpressions.py +++ b/src/Products/PageTemplates/tests/testExpressions.py @@ -105,7 +105,7 @@ def test_evaluate_with_render_DTML_template(self): def test_evaluate_alternative_first_missing(self): ec = self._makeContext() - self.assertTrue(ec.evaluate('x | nothing') is None) + self.assertIsNone(ec.evaluate('x | nothing')) def test_evaluate_dict_key_as_underscore(self): # Traversing to the name `_` will raise a DeprecationWarning @@ -204,8 +204,8 @@ def test_mixed(self): def test_builtin_in_path_expr(self): ec = self._makeContext() - self.assertIs(ec.evaluate('True'), True) - self.assertIs(ec.evaluate('False'), False) + self.assertTrue(ec.evaluate('True')) + self.assertFalse(ec.evaluate('False')) self.assertIs(ec.evaluate('nocall: test'), safe_builtins["test"]) @@ -343,5 +343,5 @@ def test_createErrorInfo_returns_unrestricted_object(self): # See: https://bugs.launchpad.net/zope2/+bug/174705 context = self._makeOne() info = context.createErrorInfo(AttributeError('nonesuch'), (12, 3)) - self.assertTrue(info.type is AttributeError) + self.assertIs(info.type, AttributeError) self.assertEqual(info.__allow_access_to_unprotected_subobjects__, 1) diff --git a/src/Products/PageTemplates/tests/testZRPythonExpr.py b/src/Products/PageTemplates/tests/testZRPythonExpr.py index 955d1eeaa4..63f2abdd4c 100644 --- a/src/Products/PageTemplates/tests/testZRPythonExpr.py +++ b/src/Products/PageTemplates/tests/testZRPythonExpr.py @@ -13,14 +13,14 @@ def test_call_with_ns_prefer_context_to_here(self): request = {'request': 1} names = {'context': context, 'here': here, 'request': request} result = call_with_ns(lambda td: td.this, names) - self.assertTrue(result is context, result) + self.assertIs(result, context, result) def test_call_with_ns_no_context_or_here(self): from Products.PageTemplates.ZRPythonExpr import call_with_ns request = {'request': 1} names = {'request': request} result = call_with_ns(lambda td: td.this, names) - self.assertTrue(result is None, result) + self.assertIsNone(result, result) def test_call_with_ns_no_request(self): from Products.PageTemplates.ZRPythonExpr import call_with_ns diff --git a/src/Products/PageTemplates/tests/testZopePageTemplate.py b/src/Products/PageTemplates/tests/testZopePageTemplate.py index 626f6d9c5c..503fce54a5 100644 --- a/src/Products/PageTemplates/tests/testZopePageTemplate.py +++ b/src/Products/PageTemplates/tests/testZopePageTemplate.py @@ -523,7 +523,7 @@ def test___before_publishing_traverse___wo__hacked_path(self): src = self._makeOne() request = DummyRequest() src.__before_publishing_traverse__(None, request) - self.assertFalse('_hacked_path' in request.__dict__) + self.assertNotIn('_hacked_path', request.__dict__) def test___before_publishing_traverse___w__hacked_path_false(self): src = self._makeOne() diff --git a/src/Products/PageTemplates/tests/test_engine.py b/src/Products/PageTemplates/tests/test_engine.py index 44d4d6b3a8..1f87848be5 100644 --- a/src/Products/PageTemplates/tests/test_engine.py +++ b/src/Products/PageTemplates/tests/test_engine.py @@ -23,13 +23,13 @@ def test_pagetemplate(self): with open(os.path.join(path, "simple.pt")) as fd: data = fd.read() template.write(data) - self.assertTrue('world' in template()) + self.assertIn('world', template()) # test arguments with open(os.path.join(path, "options.pt")) as fd: data = fd.read() template.write(data) - self.assertTrue('Hello world' in template(greeting='Hello world')) + self.assertIn('Hello world', template(greeting='Hello world')) def test_pagetemplatefile(self): from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -37,7 +37,7 @@ def test_pagetemplatefile(self): # test rendering engine template = PageTemplateFile(os.path.join(path, "simple.pt")) template = template.__of__(self.folder) - self.assertTrue('world' in template()) + self.assertIn('world', template()) def test_pagetemplatefile_processing_instruction_skipped(self): from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -59,14 +59,17 @@ def test_zopepagetemplate(self): with open(os.path.join(path, "simple.pt")) as fd: data = fd.read() template.write(data) - self.assertTrue('world' in template()) + self.assertIn('world', template()) # test arguments with open(os.path.join(path, "options.pt")) as fd: data = fd.read() template.write(data) - self.assertTrue('Hello world' in template( - greeting='Hello world')) + self.assertIn( + 'Hello world', + template( + greeting='Hello world') + ) # test commit import transaction diff --git a/src/Products/PageTemplates/tests/test_pagetemplate.py b/src/Products/PageTemplates/tests/test_pagetemplate.py index d3b8ad1bda..3e5f063f0b 100644 --- a/src/Products/PageTemplates/tests/test_pagetemplate.py +++ b/src/Products/PageTemplates/tests/test_pagetemplate.py @@ -33,19 +33,19 @@ def __str__(self): template = self._makeOne('rr.pt') result = template(refs=[Prioritized(1), Prioritized(2)]) - self.assertTrue('P1' in result) - self.assertTrue(result.index('P1') < result.index('P2')) + self.assertIn('P1', result) + self.assertLess(result.index('P1'), result.index('P2')) def test_locals(self): template = self._makeOne('locals.pt') result = template() - self.assertTrue('function test' in result) - self.assertTrue('function same_type' in result) + self.assertIn('function test', result) + self.assertIn('function same_type', result) def test_locals_base(self): template = self._makeOne('locals_base.pt') result = template() - self.assertTrue('Application' in result) + self.assertIn('Application', result) def test_nocall(self): template = self._makeOne("nocall.pt") @@ -53,7 +53,7 @@ def test_nocall(self): def dont_call(): raise RuntimeError() result = template(callable=dont_call) - self.assertTrue(repr(dont_call) in result) + self.assertIn(repr(dont_call), result) def test_exists(self): template = self._makeOne("exists.pt") @@ -61,12 +61,12 @@ def test_exists(self): def dont_call(): raise RuntimeError() result = template(callable=dont_call) - self.assertTrue('ok' in result) + self.assertIn('ok', result) def test_simple(self): template = self._makeOne("simple.pt") result = template() - self.assertTrue('Hello world!' in result) + self.assertIn('Hello world!', result) def test_secure(self): soup = '' @@ -82,13 +82,13 @@ def test_secure(self): from AccessControl.SecurityInfo import allow_module allow_module('html') result = template(soup=soup) - self.assertTrue('<foo></bar>' in result) + self.assertIn('<foo></bar>', result) def test_structure(self): template = self._makeOne("structure.pt") param = "abc" result = template(param=param) - self.assertTrue(param in result) + self.assertIn(param, result) def test_suite(): diff --git a/src/Products/PageTemplates/tests/test_viewpagetemplatefile.py b/src/Products/PageTemplates/tests/test_viewpagetemplatefile.py index d2d450d50d..e359f0ae6e 100644 --- a/src/Products/PageTemplates/tests/test_viewpagetemplatefile.py +++ b/src/Products/PageTemplates/tests/test_viewpagetemplatefile.py @@ -47,7 +47,7 @@ def afterSetUp(self): def test_simple(self): view = SimpleView(self.folder, self.folder.REQUEST) result = view.index() - self.assertTrue('Hello world!' in result) + self.assertIn('Hello world!', result) def test_secure(self): view = SecureView(self.folder, self.folder.REQUEST) @@ -57,18 +57,18 @@ def test_secure(self): except Unauthorized: self.fail("Unexpected exception.") else: - self.assertTrue('<foo></bar>' in result) + self.assertIn('<foo></bar>', result) def test_locals(self): view = LocalsView(self.folder, self.folder.REQUEST) result = view.index() - self.assertTrue("view:yes" in result) - self.assertTrue('here==context:True' in result) - self.assertTrue('here==container:True' in result) - self.assertTrue("root:(\'\',)" in result) - self.assertTrue("nothing:" in result) + self.assertIn("view:yes", result) + self.assertIn('here==context:True', result) + self.assertIn('here==container:True', result) + self.assertIn("root:(\'\',)", result) + self.assertIn("nothing:", result) # test for the existence of the cgi.parse function - self.assertTrue("parse" in result) + self.assertIn("parse", result) def test_options(self): view = OptionsView(self.folder, self.folder.REQUEST) @@ -78,8 +78,8 @@ def test_options(self): c='abc', ) result = view.index(**options) - self.assertTrue("a : 1" in result) - self.assertTrue("c : abc" in result) + self.assertIn("a : 1", result) + self.assertIn("c : abc", result) def test_processing_instruction(self): view = ProcessingInstructionTestView(self.folder, self.folder.REQUEST) diff --git a/src/Products/SiteAccess/tests/testVirtualHostMonster.py b/src/Products/SiteAccess/tests/testVirtualHostMonster.py index 4ebb862fff..000726d6ad 100644 --- a/src/Products/SiteAccess/tests/testVirtualHostMonster.py +++ b/src/Products/SiteAccess/tests/testVirtualHostMonster.py @@ -267,7 +267,7 @@ def test_add_addToContainer(self): vhm1 = self._makeOne() vhm1.manage_addToContainer(self.root) - self.assertTrue(vhm1.getId() in self.root.objectIds()) + self.assertIn(vhm1.getId(), self.root.objectIds()) self.assertTrue(queryBeforeTraverse(self.root, vhm1.meta_type)) def test_add_manage_addVirtualHostMonster(self): @@ -277,6 +277,6 @@ def test_add_manage_addVirtualHostMonster(self): from ZPublisher.BeforeTraverse import queryBeforeTraverse manage_addVirtualHostMonster(self.root) - self.assertTrue(VirtualHostMonster.id in self.root.objectIds()) + self.assertIn(VirtualHostMonster.id, self.root.objectIds()) hook = queryBeforeTraverse(self.root, VirtualHostMonster.meta_type) self.assertTrue(hook) diff --git a/src/Testing/ZopeTestCase/testPortalTestCase.py b/src/Testing/ZopeTestCase/testPortalTestCase.py index 060953e45f..243bd8d6a5 100644 --- a/src/Testing/ZopeTestCase/testPortalTestCase.py +++ b/src/Testing/ZopeTestCase/testPortalTestCase.py @@ -119,7 +119,7 @@ def test_getPortal(self): self.assertTrue(hasattr_(self.app, portal_name)) self.assertTrue(hasattr_(self.portal, 'Members')) self.assertTrue(hasattr_(self.portal, 'portal_membership')) - self.assertTrue('Member' in self.portal.userdefined_roles()) + self.assertIn('Member', self.portal.userdefined_roles()) def test_setupUserFolder(self): # User folder should be set up. @@ -151,7 +151,7 @@ def test_setupHomeFolder(self): self.login() self._setupHomeFolder() self.assertTrue(hasattr_(self.portal.Members, user_name)) - self.assertFalse(self.folder is None) + self.assertIsNotNone(self.folder) # Shut up deprecation warnings try: owner_info = self.folder.getOwnerTuple() @@ -307,7 +307,7 @@ def test_clear(self): self._setupUser() self._setupHomeFolder() self._clear(1) - self.assertFalse(portal_name in self.app.__dict__) + self.assertNotIn(portal_name, self.app.__dict__) auth_name = getSecurityManager().getUser().getUserName() self.assertEqual(auth_name, 'Anonymous User') self.assertEqual(self._called, ['beforeClose', 'afterClear']) @@ -321,7 +321,7 @@ def test_setUp(self): self.assertTrue(hasattr_(self.portal, 'acl_users')) self.assertTrue(hasattr_(self.portal, 'Members')) self.assertTrue(hasattr_(self.portal, 'portal_membership')) - self.assertTrue('Member' in self.portal.userdefined_roles()) + self.assertIn('Member', self.portal.userdefined_roles()) self.assertTrue(hasattr_(self.portal.Members, user_name)) acl_user = self.portal.acl_users.getUserById(user_name) self.assertTrue(acl_user) @@ -336,7 +336,7 @@ def test_tearDown(self): self._setUp() self._called = [] self._tearDown() - self.assertFalse(portal_name in self.app.__dict__) + self.assertNotIn(portal_name, self.app.__dict__) auth_name = getSecurityManager().getUser().getUserName() self.assertEqual(auth_name, 'Anonymous User') self.assertEqual( @@ -429,7 +429,7 @@ def getPortal(self): def testGetUserDoesNotWrapUser(self): user = self.portal.acl_users.getUserById(user_name) self.assertFalse(hasattr(user, 'aq_base')) - self.assertTrue(user is aq_base(user)) + self.assertIs(user, aq_base(user)) def testLoggedInUserIsWrapped(self): user = getSecurityManager().getUser() @@ -454,7 +454,7 @@ def _setupUserFolder(self): def testGetUserWrapsUser(self): user = self.portal.acl_users.getUserById(user_name) self.assertTrue(hasattr(user, 'aq_base')) - self.assertFalse(user is aq_base(user)) + self.assertIsNot(user, aq_base(user)) self.assertTrue( user.__parent__.__class__.__name__, 'WrappingUserFolder') diff --git a/src/Testing/ZopeTestCase/testZODBCompat.py b/src/Testing/ZopeTestCase/testZODBCompat.py index a900f9025e..1324688e1b 100644 --- a/src/Testing/ZopeTestCase/testZODBCompat.py +++ b/src/Testing/ZopeTestCase/testZODBCompat.py @@ -326,14 +326,14 @@ def _getfolder(self): def testTransactionAbort(self): folder = self._getfolder() - self.assertTrue(folder is not None) - self.assertTrue(folder._p_jar is None) + self.assertIsNotNone(folder) + self.assertIsNone(folder._p_jar) transaction.savepoint() - self.assertTrue(folder._p_jar is not None) + self.assertIsNotNone(folder._p_jar) transaction.abort() del folder folder = self._getfolder() - self.assertTrue(folder is None) + self.assertIsNone(folder) def test_suite(): diff --git a/src/Testing/ZopeTestCase/testZopeTestCase.py b/src/Testing/ZopeTestCase/testZopeTestCase.py index 3ce3a9fd2e..76b23feb4b 100644 --- a/src/Testing/ZopeTestCase/testZopeTestCase.py +++ b/src/Testing/ZopeTestCase/testZopeTestCase.py @@ -71,7 +71,7 @@ def test_setupFolder(self): self._setupFolder() self.assertTrue(hasattr_(self.app, folder_name)) self.assertTrue(hasattr_(self, 'folder')) - self.assertTrue(user_role in self.folder.userdefined_roles()) + self.assertIn(user_role, self.folder.userdefined_roles()) self.assertPermissionsOfRole(standard_permissions, user_role) def test_setupUserFolder(self): @@ -234,7 +234,7 @@ def test_clear(self): self._setupUser() self.login() self._clear(1) - self.assertFalse(folder_name in self.app.__dict__) + self.assertNotIn(folder_name, self.app.__dict__) auth_name = getSecurityManager().getUser().getUserName() self.assertEqual(auth_name, 'Anonymous User') self.assertEqual(self._called, ['beforeClose', 'afterClear']) @@ -246,7 +246,7 @@ def test_setUp(self): self._setUp() self.assertTrue(hasattr_(self.app, folder_name)) self.assertTrue(hasattr_(self, 'folder')) - self.assertTrue(user_role in self.folder.userdefined_roles()) + self.assertIn(user_role, self.folder.userdefined_roles()) self.assertPermissionsOfRole(standard_permissions, user_role) self.assertTrue(hasattr_(self.folder, 'acl_users')) acl_user = self.folder.acl_users.getUserById(user_name) @@ -262,7 +262,7 @@ def test_tearDown(self): self._setUp() self._called = [] self._tearDown() - self.assertFalse(folder_name in self.app.__dict__) + self.assertNotIn(folder_name, self.app.__dict__) auth_name = getSecurityManager().getUser().getUserName() self.assertEqual(auth_name, 'Anonymous User') self.assertEqual( @@ -356,7 +356,7 @@ class TestPlainUserFolder(ZopeTestCase.ZopeTestCase): def testGetUserDoesNotWrapUser(self): user = self.folder.acl_users.getUserById(user_name) self.assertFalse(hasattr(user, 'aq_base')) - self.assertTrue(user is aq_base(user)) + self.assertIs(user, aq_base(user)) def testLoggedInUserIsWrapped(self): user = getSecurityManager().getUser() @@ -377,7 +377,7 @@ def _setupUserFolder(self): def testGetUserWrapsUser(self): user = self.folder.acl_users.getUserById(user_name) self.assertTrue(hasattr(user, 'aq_base')) - self.assertFalse(user is aq_base(user)) + self.assertIsNot(user, aq_base(user)) self.assertTrue( user.__parent__.__class__.__name__, 'WrappingUserFolder') diff --git a/src/Testing/tests/test_testbrowser.py b/src/Testing/tests/test_testbrowser.py index 78733250bd..1ba44b9a51 100644 --- a/src/Testing/tests/test_testbrowser.py +++ b/src/Testing/tests/test_testbrowser.py @@ -127,7 +127,7 @@ def test_handle_errors_false(self): # Even errors which can be handled by Zope go to the client: with self.assertRaises(NotFound): browser.open('http://localhost/nothing-is-here') - self.assertTrue(browser.contents is None) + self.assertIsNone(browser.contents) def test_handle_errors_false_redirect(self): self.folder._setObject('redirect', RedirectStub()) @@ -136,7 +136,7 @@ def test_handle_errors_false_redirect(self): with self.assertRaises(NotFound): browser.open('http://localhost/test_folder_1_/redirect') - self.assertTrue(browser.contents is None) + self.assertIsNone(browser.contents) def test_handle_errors_false_HTTPExceptionHandler_in_app(self): """HTTPExceptionHandler does not handle errors if requested via WSGI. @@ -192,8 +192,8 @@ def test_headers_camel_case(self): browser = Browser() browser.open('http://localhost/test_folder_1_/stub') header_text = str(browser.headers) - self.assertTrue('Content-Length: ' in header_text) - self.assertTrue('Content-Type: ' in header_text) + self.assertIn('Content-Length: ', header_text) + self.assertIn('Content-Type: ', header_text) def test_suite(): diff --git a/src/ZPublisher/tests/testBaseRequest.py b/src/ZPublisher/tests/testBaseRequest.py index 4f2be00b6f..4ad384858e 100644 --- a/src/ZPublisher/tests/testBaseRequest.py +++ b/src/ZPublisher/tests/testBaseRequest.py @@ -223,7 +223,7 @@ def _makeRootAndFolder(self, use_docstring=None): def test_no_docstring_on_instance(self): root, folder = self._makeRootAndFolder() r = self._makeOne(root) - self.assertTrue(r.__doc__ is None) + self.assertIsNone(r.__doc__) def test___bobo_traverse___raises(self): root, folder = self._makeRootAndFolder() diff --git a/src/ZPublisher/tests/testHTTPRangeSupport.py b/src/ZPublisher/tests/testHTTPRangeSupport.py index fe754bd0d8..9d58b7dd46 100644 --- a/src/ZPublisher/tests/testHTTPRangeSupport.py +++ b/src/ZPublisher/tests/testHTTPRangeSupport.py @@ -23,13 +23,15 @@ class TestRangeHeaderParse(unittest.TestCase): # Utility methods def expectNone(self, header): result = parseRange(header) - self.assertTrue(result is None, 'Expected None, got %r' % result) + self.assertIsNone(result, 'Expected None, got %r' % result) def expectSets(self, header, sets): result = parseRange(header) - self.assertTrue( - result == sets, - f'Expected {sets!r}, got {result!r}') + self.assertEqual( + result, + sets, + f'Expected {sets!r}, got {result!r}' + ) # Syntactically incorrect headers def testGarbage(self): @@ -85,9 +87,11 @@ class TestExpandRanges(unittest.TestCase): def expectSets(self, sets, size, expect): result = expandRanges(sets, size) - self.assertTrue( - result == expect, - f'Expected {expect!r}, got {result!r}') + self.assertEqual( + result, + expect, + f'Expected {expect!r}, got {result!r}' + ) def testExpandOpenEnd(self): self.expectSets([(1, 2), (5, None)], 50, [(1, 2), (5, 50)]) diff --git a/src/ZPublisher/tests/testHTTPRequest.py b/src/ZPublisher/tests/testHTTPRequest.py index 7fa07d191b..2bc1b7dad8 100644 --- a/src/ZPublisher/tests/testHTTPRequest.py +++ b/src/ZPublisher/tests/testHTTPRequest.py @@ -56,8 +56,8 @@ def test_dict_methods(self): def test_dict_special_methods(self): rec = self._makeOne() rec.a = 1 - self.assertTrue('a' in rec) - self.assertFalse('b' in rec) + self.assertIn('a', rec) + self.assertNotIn('b', rec) self.assertEqual(len(rec), 1) self.assertEqual(list(iter(rec)), ['a']) @@ -206,14 +206,18 @@ def _valueIsOrHoldsTainted(self, val): def _noFormValuesInOther(self, req): for key in list(req.taintedform.keys()): - self.assertFalse( - key in req.other, - 'REQUEST.other should not hold tainted values at first!') + self.assertNotIn( + key, + req.other, + 'REQUEST.other should not hold tainted values at first!' + ) for key in list(req.form.keys()): - self.assertFalse( - key in req.other, - 'REQUEST.other should not hold form values at first!') + self.assertNotIn( + key, + req.other, + 'REQUEST.other should not hold form values at first!' + ) def _onlyTaintedformHoldsTaintedStrings(self, req): for key, val in list(req.taintedform.items()): @@ -232,9 +236,11 @@ def _onlyTaintedformHoldsTaintedStrings(self, req): def _taintedKeysAlsoInForm(self, req): for key in list(req.taintedform.keys()): - self.assertTrue( - key in req.form, - "Found tainted %s not in form" % key) + self.assertIn( + key, + req.form, + "Found tainted %s not in form" % key + ) self.assertEqual( req.form[key], req.taintedform[key], "Key %s not correctly reproduced in tainted; expected %r, " @@ -250,7 +256,7 @@ def test_webdav_source_port_available(self): def test_no_docstring_on_instance(self): env = {'SERVER_NAME': 'testingharnas', 'SERVER_PORT': '80'} req = self._makeOne(environ=env) - self.assertTrue(req.__doc__ is None) + self.assertIsNone(req.__doc__) def test___bobo_traverse___raises(self): env = {'SERVER_NAME': 'testingharnas', 'SERVER_PORT': '80'} @@ -739,13 +745,17 @@ def test_processInputs_w_tainted_values_cleans_exceptions(self): warnings.simplefilter('ignore') convert('') except Exception as e: - self.assertFalse( - '<' in e.args, - '%s converter does not quote unsafe value!' % type) + self.assertNotIn( + '<', + e.args, + '%s converter does not quote unsafe value!' % type + ) except SyntaxError as e: - self.assertFalse( - '<' in e, - '%s converter does not quote unsafe value!' % type) + self.assertNotIn( + '<', + e, + '%s converter does not quote unsafe value!' % type + ) def test_processInputs_w_dotted_name_as_tuple(self): # Collector #500 @@ -1002,7 +1012,7 @@ def test_debug_not_in_qs_still_gets_attr(self): request = self._makeOne() self.assertIsInstance(request.debug, DebugFlags) # It won't be available through dictonary lookup, though - self.assertTrue(request.get('debug') is None) + self.assertIsNone(request.get('debug')) def test_debug_in_qs_gets_form_var(self): env = {'QUERY_STRING': 'debug=1'} @@ -1036,16 +1046,16 @@ def test_locale_property_accessor(self): # before accessing request.locale for the first time, request._locale # is still a marker - self.assertTrue(request._locale is _marker) + self.assertIs(request._locale, _marker) # when accessing request.locale we will see an ILocale self.assertTrue(ILocale.providedBy(request.locale)) # and request._locale has been set - self.assertTrue(request._locale is request.locale) + self.assertIs(request._locale, request.locale) # It won't be available through dictonary lookup, though - self.assertTrue(request.get('locale') is None) + self.assertIsNone(request.get('locale')) def test_locale_in_qs(self): provideAdapter(BrowserLanguages, [IHTTPRequest], @@ -1112,9 +1122,9 @@ def test_locale_fallback(self): locale = request.locale self.assertTrue(ILocale.providedBy(locale)) - self.assertTrue(locale.id.language is None) - self.assertTrue(locale.id.territory is None) - self.assertTrue(locale.id.variant is None) + self.assertIsNone(locale.id.language) + self.assertIsNone(locale.id.territory) + self.assertIsNone(locale.id.variant) def test_method_GET(self): env = {'REQUEST_METHOD': 'GET'} diff --git a/src/ZPublisher/tests/testHTTPResponse.py b/src/ZPublisher/tests/testHTTPResponse.py index 5d64b5b3dd..c04e6cc2b4 100644 --- a/src/ZPublisher/tests/testHTTPResponse.py +++ b/src/ZPublisher/tests/testHTTPResponse.py @@ -127,8 +127,8 @@ def test_retry(self): response = self._makeOne(stdout=STDOUT, stderr=STDERR) cloned = response.retry() self.assertIsInstance(cloned, self._getTargetClass()) - self.assertTrue(cloned.stdout is STDOUT) - self.assertTrue(cloned.stderr is STDERR) + self.assertIs(cloned.stdout, STDOUT) + self.assertIs(cloned.stderr, STDERR) def test_setStatus_code(self): response = self._makeOne() @@ -261,7 +261,7 @@ def test_setCookie_w_secure_true_value(self): cookie = response.cookies.get('foo', None) self.assertEqual(len(cookie), 2) self.assertEqual(cookie.get('value'), 'bar') - self.assertIs(cookie.get('Secure'), True) + self.assertTrue(cookie.get('Secure')) cookies = response._cookie_list() self.assertEqual(len(cookies), 1) @@ -564,10 +564,10 @@ def test_setBody_with_is_error_converted_to_Site_Error(self): response.body = b'BEFORE' result = response.setBody(b'BODY', 'TITLE', is_error=True) self.assertTrue(result) - self.assertFalse(b'BEFORE' in response.body) - self.assertTrue(b'

Site Error

' in response.body) - self.assertTrue(b'TITLE' in response.body) - self.assertTrue(b'BODY' in response.body) + self.assertNotIn(b'BEFORE', response.body) + self.assertIn(b'

Site Error

', response.body) + self.assertIn(b'TITLE', response.body) + self.assertIn(b'BODY', response.body) self.assertEqual(response.getHeader('Content-Type'), 'text/html; charset=utf-8') @@ -716,7 +716,7 @@ def test_setBody_compression_no_prior_vary_header(self): response = self._makeOne() response.enableHTTPCompression({'HTTP_ACCEPT_ENCODING': 'gzip'}) response.setBody(b'foo' * 100) # body must get smaller on compression - self.assertTrue('Accept-Encoding' in response.getHeader('Vary')) + self.assertIn('Accept-Encoding', response.getHeader('Vary')) def test_setBody_compression_w_prior_vary_header_wo_encoding(self): # Vary header should be added here @@ -724,7 +724,7 @@ def test_setBody_compression_w_prior_vary_header_wo_encoding(self): response.setHeader('Vary', 'Cookie') response.enableHTTPCompression({'HTTP_ACCEPT_ENCODING': 'gzip'}) response.setBody(b'foo' * 100) # body must get smaller on compression - self.assertTrue('Accept-Encoding' in response.getHeader('Vary')) + self.assertIn('Accept-Encoding', response.getHeader('Vary')) def test_setBody_compression_w_prior_vary_header_incl_encoding(self): # Vary header already had Accept-Ecoding', do'nt munge @@ -861,7 +861,7 @@ def test_notFoundError(self): response.notFoundError() except NotFound as raised: self.assertEqual(response.status, 404) - self.assertTrue("

Resource: Unknown

" in str(raised)) + self.assertIn("

Resource: Unknown

", str(raised)) else: self.fail("Didn't raise NotFound") @@ -871,7 +871,7 @@ def test_notFoundError_w_entry(self): response.notFoundError('ENTRY') except NotFound as raised: self.assertEqual(response.status, 404) - self.assertTrue("

Resource: ENTRY

" in str(raised)) + self.assertIn("

Resource: ENTRY

", str(raised)) else: self.fail("Didn't raise NotFound") @@ -881,7 +881,7 @@ def test_forbiddenError(self): response.forbiddenError() except NotFound as raised: self.assertEqual(response.status, 404) - self.assertTrue("

Resource: Unknown

" in str(raised)) + self.assertIn("

Resource: Unknown

", str(raised)) else: self.fail("Didn't raise NotFound") @@ -891,7 +891,7 @@ def test_forbiddenError_w_entry(self): response.forbiddenError('ENTRY') except NotFound as raised: self.assertEqual(response.status, 404) - self.assertTrue("

Resource: ENTRY

" in str(raised)) + self.assertIn("

Resource: ENTRY

", str(raised)) else: self.fail("Didn't raise NotFound") @@ -934,8 +934,11 @@ def test_badRequestError_valid_parameter_name(self): response.badRequestError('some_parameter') except BadRequest as raised: self.assertEqual(response.status, 400) - self.assertTrue("The parameter, some_parameter, " - "was omitted from the request." in str(raised)) + self.assertIn( + "The parameter, some_parameter, " + "was omitted from the request.", + str(raised) + ) else: self.fail("Didn't raise BadRequest") @@ -945,8 +948,11 @@ def test_badRequestError_invalid_parameter_name(self): response.badRequestError('URL1') except InternalError as raised: self.assertEqual(response.status, 400) - self.assertTrue("Sorry, an internal error occurred in this " - "resource." in str(raised)) + self.assertIn( + "Sorry, an internal error occurred in this " + "resource.", + str(raised) + ) else: self.fail("Didn't raise InternalError") @@ -954,12 +960,12 @@ def test__unauthorized_no_realm(self): response = self._makeOne() response.realm = '' response._unauthorized() - self.assertFalse('WWW-Authenticate' in response.headers) + self.assertNotIn('WWW-Authenticate', response.headers) def test__unauthorized_w_default_realm(self): response = self._makeOne() response._unauthorized() - self.assertTrue('WWW-Authenticate' in response.headers) # literal + self.assertIn('WWW-Authenticate', response.headers) # literal self.assertEqual(response.headers['WWW-Authenticate'], 'basic realm="Zope", charset="UTF-8"') @@ -967,7 +973,7 @@ def test__unauthorized_w_realm(self): response = self._makeOne() response.realm = 'Folly' response._unauthorized() - self.assertTrue('WWW-Authenticate' in response.headers) # literal + self.assertIn('WWW-Authenticate', response.headers) # literal self.assertEqual(response.headers['WWW-Authenticate'], 'basic realm="Folly", charset="UTF-8"') @@ -977,8 +983,11 @@ def test_unauthorized_no_debug_mode(self): response.unauthorized() except Unauthorized as raised: self.assertEqual(response.status, 200) # publisher sets 401 later - self.assertTrue("You are not authorized " - "to access this resource." in str(raised)) + self.assertIn( + "You are not authorized " + "to access this resource.", + str(raised) + ) else: self.fail("Didn't raise Unauthorized") @@ -988,8 +997,10 @@ def test_unauthorized_w_debug_mode_no_credentials(self): try: response.unauthorized() except Unauthorized as raised: - self.assertTrue("\nNo Authorization header found." - in str(raised)) + self.assertIn( + "\nNo Authorization header found.", + str(raised) + ) else: self.fail("Didn't raise Unauthorized") @@ -1000,8 +1011,10 @@ def test_unauthorized_w_debug_mode_w_credentials(self): try: response.unauthorized() except Unauthorized as raised: - self.assertTrue("\nUsername and password are not correct." - in str(raised)) + self.assertIn( + "\nUsername and password are not correct.", + str(raised) + ) else: self.fail("Didn't raise Unauthorized") @@ -1381,7 +1394,7 @@ def test_exception_Internal_Server_Error(self): raise AttributeError('ERROR VALUE') except AttributeError: body = response.exception() - self.assertTrue(b'ERROR VALUE' in bytes(body)) + self.assertIn(b'ERROR VALUE', bytes(body)) self.assertEqual(response.status, 500) self.assertEqual(response.errmsg, 'Internal Server Error') @@ -1395,7 +1408,7 @@ def test_exception_500_text(self): raise exc except AttributeError: body = response.exception() - self.assertTrue(expected in bytes(body)) + self.assertIn(expected, bytes(body)) self.assertEqual(response.status, 500) self.assertEqual(response.errmsg, 'Internal Server Error') diff --git a/src/ZPublisher/tests/test_WSGIPublisher.py b/src/ZPublisher/tests/test_WSGIPublisher.py index b624a3ac7f..55428d0088 100644 --- a/src/ZPublisher/tests/test_WSGIPublisher.py +++ b/src/ZPublisher/tests/test_WSGIPublisher.py @@ -84,7 +84,7 @@ def test_listHeaders_includes_Server_header_w_server_version_set(self): response.setBody('TESTING') headers = response.listHeaders() sv = [x for x in headers if x[0] == 'Server'] - self.assertTrue(('Server', 'TESTME') in sv) + self.assertIn(('Server', 'TESTME'), sv) def test_listHeaders_includes_Date_header(self): import time @@ -119,7 +119,7 @@ def __next__(self): body = TestStreamIterator() response.setBody(body) response.finalize() - self.assertTrue(body is response.body) + self.assertIs(body, response.body) self.assertEqual(response._streaming, 1) def test_setBody_IStreamIterator(self): @@ -147,7 +147,7 @@ def __len__(self): body = TestStreamIterator() response.setBody(body) response.finalize() - self.assertTrue(body is response.body) + self.assertIs(body, response.body) self.assertEqual(response._streaming, 0) self.assertEqual(response.getHeader('Content-Length'), '%d' % len(TestStreamIterator.data)) @@ -225,7 +225,7 @@ def test_wo_REMOTE_USER(self): _realm = 'TESTING' _debug_mode = True returned = self._callFUT(request, (_object, _realm, _debug_mode)) - self.assertTrue(returned is response) + self.assertIs(returned, response) self.assertTrue(request._processedInputs) self.assertTrue(response.debug_mode) self.assertEqual(response.realm, 'TESTING') @@ -399,7 +399,7 @@ def test_upgrades_ztk_not_found(self): except ZTK_NotFound: self.fail('ZTK exception raised, expected zExceptions.') except NotFound as exc: - self.assertTrue('name_not_found' in str(exc)) + self.assertIn('name_not_found', str(exc)) def test_response_body_is_file(self): from io import BytesIO @@ -420,7 +420,7 @@ def read(self, *args, **kw): _publish = DummyCallable() _publish._result = _response app_iter = self._callFUT(environ, start_response, _publish) - self.assertTrue(app_iter is body) + self.assertIs(app_iter, body) def test_response_is_stream(self): from zope.interface import implementer @@ -448,7 +448,7 @@ def __next__(self): _publish = DummyCallable() _publish._result = _response app_iter = self._callFUT(environ, start_response, _publish) - self.assertTrue(app_iter is body) + self.assertIs(app_iter, body) def test_response_is_unboundstream(self): from zope.interface import implementer @@ -475,7 +475,7 @@ def __next__(self): _publish = DummyCallable() _publish._result = _response app_iter = self._callFUT(environ, start_response, _publish) - self.assertTrue(app_iter is body) + self.assertIs(app_iter, body) def test_stream_file_wrapper(self): from zope.interface import implementer @@ -504,8 +504,8 @@ def __init__(self, file): _publish = DummyCallable() _publish._result = _response app_iter = self._callFUT(environ, start_response, _publish) - self.assertTrue(app_iter.file is body) - self.assertTrue(isinstance(app_iter, Wrapper)) + self.assertIs(app_iter.file, body) + self.assertIsInstance(app_iter, Wrapper) self.assertEqual( int(_response.headers['content-length']), len(body)) self.assertTrue( @@ -542,8 +542,8 @@ def __init__(self, file): _publish = DummyCallable() _publish._result = _response app_iter = self._callFUT(environ, start_response, _publish) - self.assertTrue(app_iter.file is body) - self.assertTrue(isinstance(app_iter, Wrapper)) + self.assertIs(app_iter.file, body) + self.assertIsInstance(app_iter, Wrapper) self.assertEqual( int(_response.headers['content-length']), len(body)) self.assertTrue( @@ -576,8 +576,8 @@ def __init__(self, file): app_iter = self._callFUT(environ, start_response, _publish) # The stream iterator has no ``read`` and will not be used # for ``wsgi.file_wrapper``. It is returned as-is. - self.assertTrue(app_iter is body) - self.assertTrue(isinstance(app_iter, TestStreamIterator)) + self.assertIs(app_iter, body) + self.assertIsInstance(app_iter, TestStreamIterator) self.assertEqual( int(_response.headers['content-length']), len(body)) self.assertTrue( @@ -684,7 +684,7 @@ def testCustomExceptionViewUnauthorized(self): app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '401 Unauthorized') - self.assertTrue(b'Exception View: Unauthorized' in body) + self.assertIn(b'Exception View: Unauthorized', body) unregisterExceptionView(IUnauthorized) def testCustomExceptionViewForbidden(self): @@ -697,7 +697,7 @@ def testCustomExceptionViewForbidden(self): app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '403 Forbidden') - self.assertTrue(b'Exception View: Forbidden' in body) + self.assertIn(b'Exception View: Forbidden', body) unregisterExceptionView(IForbidden) def testCustomExceptionViewNotFound(self): @@ -710,7 +710,7 @@ def testCustomExceptionViewNotFound(self): app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '404 Not Found') - self.assertTrue(b'Exception View: NotFound' in body) + self.assertIn(b'Exception View: NotFound', body) unregisterExceptionView(INotFound) def testCustomExceptionViewZTKNotFound(self): @@ -723,7 +723,7 @@ def testCustomExceptionViewZTKNotFound(self): app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '404 Not Found') - self.assertTrue(b'Exception View: NotFound' in body) + self.assertIn(b'Exception View: NotFound', body) unregisterExceptionView(INotFound) def testCustomExceptionViewBadRequest(self): @@ -736,7 +736,7 @@ def testCustomExceptionViewBadRequest(self): app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '400 Bad Request') - self.assertTrue(b'Exception View: BadRequest' in body) + self.assertIn(b'Exception View: BadRequest', body) unregisterExceptionView(IException) def testCustomExceptionViewInternalError(self): @@ -750,7 +750,7 @@ def testCustomExceptionViewInternalError(self): body = b''.join(app_iter) self.assertEqual( start_response._called_with[0][0], '500 Internal Server Error') - self.assertTrue(b'Exception View: InternalError' in body) + self.assertIn(b'Exception View: InternalError', body) unregisterExceptionView(IException) def testRedirectExceptionView(self): @@ -764,7 +764,7 @@ def testRedirectExceptionView(self): body = b''.join(app_iter) status, headers = start_response._called_with[0] self.assertEqual(status, '302 Found') - self.assertTrue(b'Exception View: Redirect' in body) + self.assertIn(b'Exception View: Redirect', body) headers = dict(headers) self.assertEqual(headers['Location'], 'http://localhost:9/') unregisterExceptionView(IException) @@ -811,14 +811,14 @@ def test_set_REMOTE_USER_environ(self): _response = DummyResponse() _publish = DummyCallable() _publish._result = _response - self.assertFalse('REMOTE_USER' in environ) + self.assertNotIn('REMOTE_USER', environ) self._callFUT(environ, start_response, _publish) self.assertEqual(environ['REMOTE_USER'], user_name) # After logout there is no REMOTE_USER in environ environ = self._makeEnviron() self.logout() self._callFUT(environ, start_response, _publish) - self.assertFalse('REMOTE_USER' in environ) + self.assertNotIn('REMOTE_USER', environ) def test_set_REMOTE_USER_environ_error(self): environ = self._makeEnviron() diff --git a/src/ZPublisher/tests/test_cookie.py b/src/ZPublisher/tests/test_cookie.py index addb62449d..672a557816 100644 --- a/src/ZPublisher/tests/test_cookie.py +++ b/src/ZPublisher/tests/test_cookie.py @@ -175,7 +175,7 @@ def test_http_only(self): # test true n, v = convertCookieParameter("Http_Only", True) self.assertEqual(n, "HttpOnly") - self.assertIs(v, True) + self.assertTrue(v) # test false _, v = convertCookieParameter("http_only", False) self.assertIsNone(v) @@ -183,7 +183,7 @@ def test_http_only(self): def test_secure(self): n, v = convertCookieParameter("secure", True) self.assertEqual(n, "Secure") - self.assertIs(v, True) + self.assertTrue(v) def test_samesite(self): for t in "None Lax Strict".split(): diff --git a/src/ZPublisher/tests/test_pubevents.py b/src/ZPublisher/tests/test_pubevents.py index d1e4a95551..05c0d227bf 100644 --- a/src/ZPublisher/tests/test_pubevents.py +++ b/src/ZPublisher/tests/test_pubevents.py @@ -169,7 +169,7 @@ def testStreaming(self): self.assertIsInstance(events[0], PubBeforeStreaming) self.assertEqual(events[0].response, response) - self.assertTrue(b'datachunk1datachunk2' in out.getvalue()) + self.assertIn(b'datachunk1datachunk2', out.getvalue()) class ExceptionView: diff --git a/src/ZPublisher/tests/test_xmlrpc.py b/src/ZPublisher/tests/test_xmlrpc.py index ab61ac8948..f742354f4d 100644 --- a/src/ZPublisher/tests/test_xmlrpc.py +++ b/src/ZPublisher/tests/test_xmlrpc.py @@ -58,7 +58,7 @@ def test_nil(self): response = self._makeOne(faux) response.setBody(body) data, method = xmlrpc.client.loads(faux._body) - self.assertIs(data[0]['public'], None) + self.assertIsNone(data[0]['public']) def test_instance(self): # Instances are turned into dicts with their private @@ -135,8 +135,8 @@ def test_instance_security(self): response.setBody(folder) data, method = xmlrpc.client.loads(faux._body) - self.assertFalse('file1' in data[0].keys()) - self.assertTrue('file2' in data[0].keys()) + self.assertNotIn('file1', data[0].keys()) + self.assertIn('file2', data[0].keys()) def test_zopedatetimeinstance(self): # DateTime instance at top-level @@ -146,7 +146,7 @@ def test_zopedatetimeinstance(self): response.setBody(body) data, method = xmlrpc.client.loads(faux._body) data = data[0] - self.assertTrue(isinstance(data, xmlrpc.client.DateTime)) + self.assertIsInstance(data, xmlrpc.client.DateTime) self.assertEqual(data.value, '2006-05-24T07:00:00+00:00') def test_zopedatetimeattribute(self): @@ -157,7 +157,7 @@ def test_zopedatetimeattribute(self): response.setBody(body) data, method = xmlrpc.client.loads(faux._body) data = data[0]['public'] - self.assertTrue(isinstance(data, xmlrpc.client.DateTime)) + self.assertIsInstance(data, xmlrpc.client.DateTime) self.assertEqual(data.value, '2006-05-24T07:00:00+00:00') def test_zopedatetimeattribute_recursive(self): @@ -169,7 +169,7 @@ def test_zopedatetimeattribute_recursive(self): response.setBody(body) data, method = xmlrpc.client.loads(faux._body) data = data[0]['public']['public'] - self.assertTrue(isinstance(data, xmlrpc.client.DateTime)) + self.assertIsInstance(data, xmlrpc.client.DateTime) self.assertEqual(data.value, '2006-05-24T07:00:00+00:00') def test_zopedatetimeinstance_in_list(self): @@ -180,7 +180,7 @@ def test_zopedatetimeinstance_in_list(self): response.setBody(body) data, method = xmlrpc.client.loads(faux._body) data = data[0][0] - self.assertTrue(isinstance(data, xmlrpc.client.DateTime)) + self.assertIsInstance(data, xmlrpc.client.DateTime) self.assertEqual(data.value, '2006-05-24T07:00:00+00:00') def test_zopedatetimeinstance_in_dict(self): @@ -191,7 +191,7 @@ def test_zopedatetimeinstance_in_dict(self): response.setBody(body) data, method = xmlrpc.client.loads(faux._body) data = data[0]['date'] - self.assertTrue(isinstance(data, xmlrpc.client.DateTime)) + self.assertIsInstance(data, xmlrpc.client.DateTime) self.assertEqual(data.value, '2006-05-24T07:00:00+00:00') def test_functionattribute(self): diff --git a/src/ZPublisher/tests/test_zpublish.py b/src/ZPublisher/tests/test_zpublish.py index 8e779f0b18..ad675402c7 100644 --- a/src/ZPublisher/tests/test_zpublish.py +++ b/src/ZPublisher/tests/test_zpublish.py @@ -29,7 +29,7 @@ def test_zpublish_true(self): def f(): pass - self.assertIs(zpublish_mark(f), True) + self.assertTrue(zpublish_mark(f)) self.assertTrue(zpublish_marked(f)) def test_zpublish_false(self): @@ -37,7 +37,7 @@ def test_zpublish_false(self): def f(): pass - self.assertIs(zpublish_mark(f), False) + self.assertFalse(zpublish_mark(f)) self.assertTrue(zpublish_marked(f)) def test_zpublish_method(self): @@ -61,9 +61,9 @@ def f(): pass self.assertIsNone(zpublish_mark(f)) - self.assertIs(zpublish_mark(f, True), True) + self.assertTrue(zpublish_mark(f, True)) zpublish(f) - self.assertIs(zpublish_mark(f), True) + self.assertTrue(zpublish_mark(f)) def test_zpublish_marked(self): def f(): @@ -80,7 +80,7 @@ def f(): self.assertFalse(zpublish_marked(f)) wrapper = zpublish_wrap(f) self.assertFalse(zpublish_marked(f)) - self.assertIs(zpublish_mark(wrapper), True) + self.assertTrue(zpublish_mark(wrapper)) self.assertEqual(signature(wrapper), signature(f)) self.assertIs(wrapper, zpublish_wrap(wrapper)) wrapper2 = zpublish_wrap(wrapper, conditional=False, methods="put") diff --git a/src/ZTUtils/tests/testTree.py b/src/ZTUtils/tests/testTree.py index b2d7c97aa1..603bde28d3 100644 --- a/src/ZTUtils/tests/testTree.py +++ b/src/ZTUtils/tests/testTree.py @@ -270,7 +270,7 @@ def testBaseTree(self): self.assertEqual(treeroot.height, 2) self.assertEqual(treeroot.depth, 0) self.assertEqual(treeroot.state, 1) - self.assertTrue(treeroot.object is self.root) + self.assertIs(treeroot.object, self.root) i = 'b' for subnode in treeroot: @@ -279,7 +279,7 @@ def testBaseTree(self): self.assertEqual(subnode.height, 1) self.assertEqual(subnode.depth, 1) self.assertEqual(subnode.state, -1) - self.assertTrue(subnode.object is self.items[i]) + self.assertIs(subnode.object, self.items[i]) i = chr(ord(i) + 1) expected_set = [self.items['a'], self.items['b'], self.items['c']] @@ -305,7 +305,7 @@ def testExpandedTree(self): self.assertEqual(treeroot.height, 4) self.assertEqual(treeroot.depth, 0) self.assertEqual(treeroot.state, 1) - self.assertTrue(treeroot.object is self.root) + self.assertIs(treeroot.object, self.root) items = self.items expected_set = [ @@ -420,7 +420,7 @@ def testEncodeDecode(self): treeroot1 = self.tm.tree(self.root, self.expansionmap) encoded = Tree.encodeExpansion(treeroot1.flat()) - self.assertFalse(encoded.find(b'\n') != -1) + self.assertEqual(encoded.find(b'\n'), -1) decodedmap = Tree.decodeExpansion(encoded) treeroot2 = self.tm.tree(self.root, decodedmap) @@ -451,6 +451,6 @@ def testDecodeDecompressedSizeLimit(self): from ZTUtils.Tree import b2a big = b2a(zlib.compress(b'x' * (1024 * 1100))) - self.assertTrue(len(big) < 8192) # Must be under the input size limit + self.assertLess(len(big), 8192) # Must be under the input size limit with self.assertRaises(ValueError): Tree.decodeExpansion(b':' + big) diff --git a/src/Zope2/App/tests/test_schema.py b/src/Zope2/App/tests/test_schema.py index 9c722afa4a..db3f468c5a 100644 --- a/src/Zope2/App/tests/test_schema.py +++ b/src/Zope2/App/tests/test_schema.py @@ -51,4 +51,4 @@ def _factory(context): registry = self._makeOne() context = object() found = registry.get(context, 'foundit') - self.assertTrue(found is _marker) + self.assertIs(found, _marker) diff --git a/src/webdav/tests/testPUT_factory.py b/src/webdav/tests/testPUT_factory.py index 0eb92d4501..af6cf42c5d 100644 --- a/src/webdav/tests/testPUT_factory.py +++ b/src/webdav/tests/testPUT_factory.py @@ -45,35 +45,35 @@ def testNoVirtualHosting(self): request = self.app.REQUEST put = request.traverse('/folder/doc') put(request, request.RESPONSE) - self.assertTrue('doc' in self.folder.objectIds()) + self.assertIn('doc', self.folder.objectIds()) def testSimpleVirtualHosting(self): request = self.app.REQUEST put = request.traverse('/VirtualHostBase/http/foo.com:80/' 'VirtualHostRoot/folder/doc') put(request, request.RESPONSE) - self.assertTrue('doc' in self.folder.objectIds()) + self.assertIn('doc', self.folder.objectIds()) def testSubfolderVirtualHosting(self): request = self.app.REQUEST put = request.traverse('/VirtualHostBase/http/foo.com:80/' 'folder/VirtualHostRoot/doc') put(request, request.RESPONSE) - self.assertTrue('doc' in self.folder.objectIds()) + self.assertIn('doc', self.folder.objectIds()) def testInsideOutVirtualHosting(self): request = self.app.REQUEST put = request.traverse('/VirtualHostBase/http/foo.com:80/' 'VirtualHostRoot/_vh_foo/folder/doc') put(request, request.RESPONSE) - self.assertTrue('doc' in self.folder.objectIds()) + self.assertIn('doc', self.folder.objectIds()) def testSubfolderInsideOutVirtualHosting(self): request = self.app.REQUEST put = request.traverse('/VirtualHostBase/http/foo.com:80/' 'folder/VirtualHostRoot/_vh_foo/doc') put(request, request.RESPONSE) - self.assertTrue('doc' in self.folder.objectIds()) + self.assertIn('doc', self.folder.objectIds()) def testCollector2261(self): from OFS.DTMLMethod import addDTMLMethod @@ -106,7 +106,7 @@ def custom_put_factory(name, typ, body): request = self.app.REQUEST put = request.traverse('/folder/doc') put(request, request.RESPONSE) - self.assertTrue('newname' in self.folder.objectIds()) + self.assertIn('newname', self.folder.objectIds()) def test_default_PUT_factory_type_guessing(self): # Check how the default PUT factory guesses the type of object to diff --git a/src/webdav/tests/testResource.py b/src/webdav/tests/testResource.py index 332a78d87c..1e9d6fbd70 100644 --- a/src/webdav/tests/testResource.py +++ b/src/webdav/tests/testResource.py @@ -115,21 +115,21 @@ def test_ms_public_header(self): req, resp = make_request_response() resource = self._makeOne() resource.OPTIONS(req, resp) - self.assertTrue('public' not in resp.headers) + self.assertNotIn('public', resp.headers) Resource.enable_ms_public_header = True req, resp = make_request_response() resource = self._makeOne() resource.OPTIONS(req, resp) - self.assertTrue('public' not in resp.headers) - self.assertTrue('allow' in resp.headers) + self.assertNotIn('public', resp.headers) + self.assertIn('allow', resp.headers) req, resp = make_request_response( environ={'USER_AGENT': MS_DAV_AGENT}) resource = self._makeOne() resource.OPTIONS(req, resp) - self.assertTrue('public' in resp.headers) - self.assertTrue('allow' in resp.headers) + self.assertIn('public', resp.headers) + self.assertIn('allow', resp.headers) self.assertEqual(resp.headers['public'], resp.headers['allow']) finally: