Skip to content

Commit

Permalink
Add teyit for better test assertions (#1226)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
icemac and pre-commit-ci-lite[bot] authored Aug 26, 2024
1 parent 9f88fe5 commit 1b21489
Show file tree
Hide file tree
Showing 42 changed files with 389 additions and 340 deletions.
5 changes: 4 additions & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,3 +130,6 @@ ignore-bad-ideas = [
ignore = [
"docs/locale/*/LC_MESSAGES/*.mo",
]

[pre-commit]
teyit-exclude = "App/tests/fixtures/error\\.py"
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions src/App/tests/test_ApplicationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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())
Expand All @@ -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()
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/OFS/tests/testAppInitializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand Down Expand Up @@ -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):
Expand Down
124 changes: 62 additions & 62 deletions src/OFS/tests/testCopySupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',))
Expand Down Expand Up @@ -227,60 +227,60 @@ 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'},
{'id': 'file2', 'new_id': 'file2'},
])

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'},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 1b21489

Please sign in to comment.