[test] use assertIn where appropriate
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 08 Apr 2014 17:39:39 +0200
changeset 9674 96549de9dd70
parent 9673 f5e77035f332
child 9675 8aabfefc8a81
[test] use assertIn where appropriate Automatically generated with: find -name unittest_*.py -o -name test_*.py | xargs sed -i -e 's/assertTrue(\([^,]*\) in \([^,]*\))/assertIn(\1, \2)/'
devtools/test/unittest_dbfill.py
devtools/test/unittest_fill.py
hooks/test/unittest_syncschema.py
server/test/unittest_ldapsource.py
server/test/unittest_migractions.py
sobjects/test/unittest_notification.py
test/unittest_cwconfig.py
test/unittest_rqlrewrite.py
test/unittest_schema.py
web/test/unittest_application.py
web/test/unittest_propertysheet.py
web/test/unittest_views_basecontrollers.py
web/test/unittest_views_navigation.py
web/test/unittest_webconfig.py
--- a/devtools/test/unittest_dbfill.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/devtools/test/unittest_dbfill.py	Tue Apr 08 17:39:39 2014 +0200
@@ -86,7 +86,7 @@
         # Test for random index
         for index in range(5):
             cost_value = self.bug_valgen.generate_attribute_value({}, 'cost', index)
-            self.assertTrue(cost_value in range(index+1))
+            self.assertIn(cost_value, range(index+1))
 
     def test_date(self):
         """test date generation"""
--- a/devtools/test/unittest_fill.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/devtools/test/unittest_fill.py	Tue Apr 08 17:39:39 2014 +0200
@@ -43,7 +43,7 @@
         class MyValueGenerator(ValueGenerator):
             def generate_server(self, index):
                 return attrname
-        self.assertTrue('generate_server' in dir(ValueGenerator))
+        self.assertIn('generate_server', dir(ValueGenerator))
 
 
     def test_bad_signature_detection(self):
@@ -63,7 +63,7 @@
         class MyValueGenerator(ValueGenerator):
             def generate_server(self, index, foo):
                 pass
-        self.assertTrue('generate_server' in dir(ValueGenerator))
+        self.assertIn('generate_server', dir(ValueGenerator))
 
 
 if __name__ == '__main__':
--- a/hooks/test/unittest_syncschema.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/hooks/test/unittest_syncschema.py	Tue Apr 08 17:39:39 2014 +0200
@@ -86,8 +86,8 @@
         self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
         self.assertFalse(self.index_exists('Societe2', 'name'))
         self.commit()
-        self.assertTrue('name' in schema['Societe2'].subject_relations())
-        self.assertTrue('concerne2' in schema['Societe2'].subject_relations())
+        self.assertIn('name', schema['Societe2'].subject_relations())
+        self.assertIn('concerne2', schema['Societe2'].subject_relations())
         self.assertTrue(self.index_exists('Societe2', 'name'))
         # now we should be able to insert and query Societe2
         s2eid = self.execute('INSERT Societe2 X: X name "logilab"')[0][0]
@@ -103,7 +103,7 @@
         self.commit()
         self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
         self.commit()
-        self.assertTrue('concerne2' in schema['CWUser'].subject_relations())
+        self.assertIn('concerne2', schema['CWUser'].subject_relations())
         self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
         self.assertFalse(self.execute('Any X WHERE X concerne2 Y'))
         # schema should be cleaned on delete (after commit)
@@ -154,7 +154,7 @@
         snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')]
         self.assertFalse('subdiv' in snames)
         snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
-        self.assertTrue('subdiv' in snames)
+        self.assertIn('subdiv', snames)
 
 
     def test_perms_synchronization_1(self):
@@ -294,8 +294,8 @@
                      {'x': attreid})
         self.commit()
         self.schema.rebuild_infered_relations()
-        self.assertTrue('Transition' in self.schema['messageid'].subjects())
-        self.assertTrue('WorkflowTransition' in self.schema['messageid'].subjects())
+        self.assertIn('Transition', self.schema['messageid'].subjects())
+        self.assertIn('WorkflowTransition', self.schema['messageid'].subjects())
         self.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
 
     def test_change_fulltextindexed(self):
--- a/server/test/unittest_ldapsource.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/server/test/unittest_ldapsource.py	Tue Apr 08 17:39:39 2014 +0200
@@ -241,7 +241,7 @@
         self.assertMetadata(e)
         self.assertEqual(e.firstname, None)
         self.assertEqual(e.surname, None)
-        self.assertTrue('users' in [g.name for g in e.in_group])
+        self.assertIn('users' in [g.name for g, e.in_group])
         self.assertEqual(e.owned_by[0].login, 'syt')
         self.assertEqual(e.created_by, ())
         addresses = [pe.address for pe in e.use_email]
--- a/server/test/unittest_migractions.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/server/test/unittest_migractions.py	Tue Apr 08 17:39:39 2014 +0200
@@ -76,7 +76,7 @@
         self.session.create_entity('Note')
         self.commit()
         self.mh.cmd_add_attribute('Note', 'yesno')
-        self.assertTrue('yesno' in self.schema)
+        self.assertIn('yesno', self.schema)
         self.assertEqual(self.schema['yesno'].subjects(), ('Note',))
         self.assertEqual(self.schema['yesno'].objects(), ('Boolean',))
         self.assertEqual(self.schema['Note'].default('yesno'), False)
@@ -94,7 +94,7 @@
         orderdict = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
                                          'RDEF relation_type RT, RDEF ordernum O, RT name RTN'))
         self.mh.cmd_add_attribute('Note', 'whatever')
-        self.assertTrue('whatever' in self.schema)
+        self.assertIn('whatever', self.schema)
         self.assertEqual(self.schema['whatever'].subjects(), ('Note',))
         self.assertEqual(self.schema['whatever'].objects(), ('Int',))
         self.assertEqual(self.schema['Note'].default('whatever'), 0)
@@ -128,7 +128,7 @@
         self.session.commit(free_cnxset=False)
         self.assertFalse('shortpara' in self.schema)
         self.mh.cmd_add_attribute('Note', 'shortpara')
-        self.assertTrue('shortpara' in self.schema)
+        self.assertIn('shortpara', self.schema)
         self.assertEqual(self.schema['shortpara'].subjects(), ('Note', ))
         self.assertEqual(self.schema['shortpara'].objects(), ('String', ))
         # test created column is actually a varchar(64)
@@ -148,9 +148,9 @@
         self.mh.cmd_add_attribute('Note', 'mydate')
         self.mh.cmd_add_attribute('Note', 'oldstyledefaultdate')
         self.mh.cmd_add_attribute('Note', 'newstyledefaultdate')
-        self.assertTrue('mydate' in self.schema)
-        self.assertTrue('oldstyledefaultdate' in self.schema)
-        self.assertTrue('newstyledefaultdate' in self.schema)
+        self.assertIn('mydate', self.schema)
+        self.assertIn('oldstyledefaultdate', self.schema)
+        self.assertIn('newstyledefaultdate', self.schema)
         self.assertEqual(self.schema['mydate'].subjects(), ('Note', ))
         self.assertEqual(self.schema['mydate'].objects(), ('Date', ))
         testdate = date(2005, 12, 13)
@@ -196,7 +196,7 @@
         eid2 = self.mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0]
         self.mh.cmd_rename_attribute('Personne', 'sexe', 'civility')
         self.assertFalse('sexe' in self.schema)
-        self.assertTrue('civility' in self.schema)
+        self.assertIn('civility', self.schema)
         # test data has been backported
         c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0]
         self.assertEqual(c1, 'M')
@@ -219,10 +219,10 @@
         self.assertFalse('Folder2' in self.schema)
         self.assertFalse('filed_under2' in self.schema)
         self.mh.cmd_add_entity_type('Folder2')
-        self.assertTrue('Folder2' in self.schema)
-        self.assertTrue('Old' in self.schema)
+        self.assertIn('Folder2', self.schema)
+        self.assertIn('Old', self.schema)
         self.assertTrue(self.session.execute('CWEType X WHERE X name "Folder2"'))
-        self.assertTrue('filed_under2' in self.schema)
+        self.assertIn('filed_under2', self.schema)
         self.assertTrue(self.session.execute('CWRType X WHERE X name "filed_under2"'))
         self.assertEqual(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()),
                           ['created_by', 'creation_date', 'cw_source', 'cwuri',
@@ -269,7 +269,7 @@
     def test_add_drop_relation_type(self):
         self.mh.cmd_add_entity_type('Folder2', auto=False)
         self.mh.cmd_add_relation_type('filed_under2')
-        self.assertTrue('filed_under2' in self.schema)
+        self.assertIn('filed_under2', self.schema)
         # Old will be missing as it has been renamed into 'New' in the migrated
         # schema while New hasn't been added here.
         self.assertEqual(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
@@ -294,7 +294,7 @@
         self.mh.rqlexec('SET X concerne2 Y WHERE X is Personne, Y is Affaire')
         self.session.commit(free_cnxset=False)
         self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire')
-        self.assertTrue('concerne2' in self.schema)
+        self.assertIn('concerne2', self.schema)
         self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Note')
         self.assertFalse('concerne2' in self.schema)
 
@@ -546,10 +546,10 @@
                 raise
         finally:
             self.mh.cmd_add_cube('email')
-            self.assertTrue('email' in self.config.cubes())
-            self.assertTrue(self.config.cube_dir('email') in self.config.cubes_path())
-            self.assertTrue('file' in self.config.cubes())
-            self.assertTrue(self.config.cube_dir('file') in self.config.cubes_path())
+            self.assertIn('email', self.config.cubes())
+            self.assertIn(self.config.cube_dir('email'), self.config.cubes_path())
+            self.assertIn('file', self.config.cubes())
+            self.assertIn(self.config.cube_dir('file'), self.config.cubes_path())
             for ertype in ('Email', 'EmailThread', 'EmailPart', 'File',
                            'sender', 'in_thread', 'reply_to', 'data_format'):
                 self.assertTrue(ertype in schema, ertype)
@@ -584,7 +584,7 @@
                 self.mh.cmd_remove_cube('email')
                 cubes.remove('email')
                 self.assertFalse('email' in self.config.cubes())
-                self.assertTrue('file' in self.config.cubes())
+                self.assertIn('file', self.config.cubes())
                 for ertype in ('Email', 'EmailThread', 'EmailPart',
                                'sender', 'in_thread', 'reply_to'):
                     self.assertFalse(ertype in schema, ertype)
@@ -594,7 +594,7 @@
                 raise
         finally:
             self.mh.cmd_add_cube('email')
-            self.assertTrue('email' in self.config.cubes())
+            self.assertIn('email', self.config.cubes())
             # trick: overwrite self.maxeid to avoid deletion of just reintroduced
             #        types (and their associated tables!)
             self.maxeid = self.session.execute('Any MAX(X)')[0][0]
--- a/sobjects/test/unittest_notification.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/sobjects/test/unittest_notification.py	Tue Apr 08 17:39:39 2014 +0200
@@ -40,7 +40,7 @@
         # parse_message_id should work with or without surrounding <>
         self.assertEqual(values, parse_message_id(msgid1[1:-1], 'testapp'))
         self.assertEqual(values['eid'], '21')
-        self.assertTrue('timestamp' in values)
+        self.assertIn('timestamp', values)
         self.assertEqual(parse_message_id(msgid1[1:-1], 'anotherapp'), None)
 
     def test_notimestamp(self):
--- a/test/unittest_cwconfig.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/test/unittest_cwconfig.py	Tue Apr 08 17:39:39 2014 +0200
@@ -123,7 +123,7 @@
         self.assertEqual(self.config.cubes_search_path(),
                           [CUSTOM_CUBES_DIR,
                            self.config.CUBES_DIR])
-        self.assertTrue('mycube' in self.config.available_cubes())
+        self.assertIn('mycube', self.config.available_cubes())
         # test cubes python path
         self.config.adjust_sys_path()
         import cubes
--- a/test/unittest_rqlrewrite.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/test/unittest_rqlrewrite.py	Tue Apr 08 17:39:39 2014 +0200
@@ -129,7 +129,7 @@
             "F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission), "
             "(EXISTS(S ref LIKE 'PUBLIC%')) OR (EXISTS(B in_group G, G name 'public', G is CWGroup)), "
             "S is Affaire")
-        self.assertTrue('D' in kwargs)
+        self.assertIn('D', kwargs)
 
     def test_or(self):
         constraint = '(X identity U) OR (X in_state ST, CL identity U, CL in_state ST, ST name "subscribed")'
--- a/test/unittest_schema.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/test/unittest_schema.py	Tue Apr 08 17:39:39 2014 +0200
@@ -248,7 +248,7 @@
 
     def test_fulltext_container(self):
         schema = loader.load(config)
-        self.assertTrue('has_text' in schema['CWUser'].subject_relations())
+        self.assertIn('has_text', schema['CWUser'].subject_relations())
         self.assertFalse('has_text' in schema['EmailAddress'].subject_relations())
 
     def test_permission_settings(self):
--- a/web/test/unittest_application.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/web/test/unittest_application.py	Tue Apr 08 17:39:39 2014 +0200
@@ -332,8 +332,8 @@
         except Redirect as redir:
             self.fail('anonymous user should get login form')
         clear_cache(req, 'get_authorization')
-        self.assertTrue('__login' in form)
-        self.assertTrue('__password' in form)
+        self.assertIn('__login', form)
+        self.assertIn('__password', form)
         self.assertFalse(req.cnx) # Mock cnx are False
         req.form['__login'] = self.admlogin
         req.form['__password'] = self.admpassword
--- a/web/test/unittest_propertysheet.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/web/test/unittest_propertysheet.py	Tue Apr 08 17:39:39 2014 +0200
@@ -35,12 +35,12 @@
                           'a {bgcolor: #FFFFFF; size: 1%;}')
         self.assertEqual(ps.process_resource(DATADIR, 'pouet.css'),
                           CACHEDIR)
-        self.assertTrue('pouet.css' in ps._cache)
+        self.assertIn('pouet.css', ps._cache)
         self.assertFalse(ps.need_reload())
         os.utime(join(DATADIR, 'sheet1.py'), None)
-        self.assertTrue('pouet.css' in ps._cache)
+        self.assertIn('pouet.css', ps._cache)
         self.assertTrue(ps.need_reload())
-        self.assertTrue('pouet.css' in ps._cache)
+        self.assertIn('pouet.css', ps._cache)
         ps.reload()
         self.assertFalse('pouet.css' in ps._cache)
         self.assertFalse(ps.need_reload())
--- a/web/test/unittest_views_basecontrollers.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/web/test/unittest_views_basecontrollers.py	Tue Apr 08 17:39:39 2014 +0200
@@ -53,11 +53,11 @@
 class EditControllerTC(CubicWebTC):
     def setUp(self):
         CubicWebTC.setUp(self)
-        self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read'))
+        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
 
     def tearDown(self):
         CubicWebTC.tearDown(self)
-        self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read'))
+        self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read'))
 
     def test_noparam_edit(self):
         """check behaviour of this controller without any form parameter
--- a/web/test/unittest_views_navigation.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/web/test/unittest_views_navigation.py	Tue Apr 08 17:39:39 2014 +0200
@@ -126,7 +126,7 @@
     #         req, rset=rset, view=view, context='navtop')
     #     # breadcrumbs should be in headers by default
     #     clsids = set(obj.id for obj in objs)
-    #     self.assertTrue('breadcrumbs' in clsids)
+    #     self.assertIn('breadcrumbs', clsids)
     #     objs = self.vreg['ctxcomponents'].poss_visible_objects(
     #         req, rset=rset, view=view, context='navbottom')
     #     # breadcrumbs should _NOT_ be in footers by default
@@ -140,7 +140,7 @@
     #         req, rset=rset, view=view, context='navbottom')
 
     #     clsids = [obj.id for obj in objs]
-    #     self.assertTrue('breadcrumbs' in clsids)
+    #     self.assertIn('breadcrumbs', clsids)
     #     objs = self.vreg['ctxcomponents'].poss_visible_objects(
     #         req, rset=rset, view=view, context='navtop')
 
--- a/web/test/unittest_webconfig.py	Wed Apr 09 11:25:45 2014 +0200
+++ b/web/test/unittest_webconfig.py	Tue Apr 08 17:39:39 2014 +0200
@@ -38,11 +38,11 @@
         self.assertTrue(isinstance(ie_css, list))
 
     def test_locate_resource(self):
-        self.assertTrue('FILE_ICON' in self.config.uiprops)
+        self.assertIn('FILE_ICON', self.config.uiprops)
         rname = self.config.uiprops['FILE_ICON'].replace(self.config.datadir_url, '')
-        self.assertTrue('file' in self.config.locate_resource(rname)[0].split(os.sep))
+        self.assertIn('file', self.config.locate_resource(rname)[0].split(os.sep))
         cubicwebcsspath = self.config.locate_resource('cubicweb.css')[0].split(os.sep)
-        self.assertTrue('web' in cubicwebcsspath or 'shared' in cubicwebcsspath) # 'shared' if tests under apycot
+        self.assertIn('web' in cubicwebcsspath or 'shared', cubicwebcsspath) # 'shared' if tests under apycot
 
     def test_sign_text(self):
         signature = self.config.sign_text(u'hôp')