[test] use assertNotIn where appropriate
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 08 Apr 2014 18:00:14 +0200
changeset 9675 8aabfefc8a81
parent 9674 96549de9dd70
child 9676 3f62606c01a2
[test] use assertNotIn where appropriate Automatically generated with: find -name unittest_*.py -o -name test_*.py | xargs sed -i -e 's/assertFalse(\([^,]*\) in \([^,]*\))/assertNotIn(\1, \2)/' plus revert of a couple false matches.
devtools/test/unittest_fill.py
hooks/test/unittest_syncschema.py
server/test/unittest_migractions.py
server/test/unittest_rqlannotation.py
sobjects/test/unittest_notification.py
test/unittest_schema.py
test/unittest_vregistry.py
web/test/unittest_propertysheet.py
web/test/unittest_views_basecontrollers.py
web/test/unittest_views_navigation.py
--- a/devtools/test/unittest_fill.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/devtools/test/unittest_fill.py	Tue Apr 08 18:00:14 2014 +0200
@@ -39,7 +39,7 @@
 
 
     def test_autoextend(self):
-        self.assertFalse('generate_server' in dir(ValueGenerator))
+        self.assertNotIn('generate_server', dir(ValueGenerator))
         class MyValueGenerator(ValueGenerator):
             def generate_server(self, index):
                 return attrname
@@ -47,19 +47,19 @@
 
 
     def test_bad_signature_detection(self):
-        self.assertFalse('generate_server' in dir(ValueGenerator))
+        self.assertNotIn('generate_server', dir(ValueGenerator))
         try:
             class MyValueGenerator(ValueGenerator):
                 def generate_server(self):
                     pass
         except TypeError:
-            self.assertFalse('generate_server' in dir(ValueGenerator))
+            self.assertNotIn('generate_server', dir(ValueGenerator))
         else:
             self.fail('TypeError not raised')
 
 
     def test_signature_extension(self):
-        self.assertFalse('generate_server' in dir(ValueGenerator))
+        self.assertNotIn('generate_server', dir(ValueGenerator))
         class MyValueGenerator(ValueGenerator):
             def generate_server(self, index, foo):
                 pass
--- a/hooks/test/unittest_syncschema.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/hooks/test/unittest_syncschema.py	Tue Apr 08 18:00:14 2014 +0200
@@ -82,8 +82,8 @@
             'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E '
             'WHERE RT name "concerne2", E name "Societe2"')[0][0]
         self._set_perms(concerne2_rdef_eid)
-        self.assertFalse('name' in schema['Societe2'].subject_relations())
-        self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
+        self.assertNotIn('name', schema['Societe2'].subject_relations())
+        self.assertNotIn('concerne2', schema['Societe2'].subject_relations())
         self.assertFalse(self.index_exists('Societe2', 'name'))
         self.commit()
         self.assertIn('name', schema['Societe2'].subject_relations())
@@ -104,7 +104,7 @@
         self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
         self.commit()
         self.assertIn('concerne2', schema['CWUser'].subject_relations())
-        self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
+        self.assertNotIn('concerne2', schema['Societe2'].subject_relations())
         self.assertFalse(self.execute('Any X WHERE X concerne2 Y'))
         # schema should be cleaned on delete (after commit)
         self.execute('DELETE CWEType X WHERE X name "Societe2"')
@@ -116,7 +116,7 @@
         self.assertFalse(self.index_exists('Societe2', 'name'))
         self.assertFalse(schema.has_entity('Societe2'))
         self.assertFalse(schema.has_entity('concerne2'))
-        self.assertFalse('concerne2' in schema['CWUser'].subject_relations())
+        self.assertNotIn('concerne2', schema['CWUser'].subject_relations())
 
     def test_metartype_with_nordefs(self):
         META_RTYPES.add('custom_meta')
@@ -152,7 +152,7 @@
         instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)]
         self.assertEqual(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
         snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')]
-        self.assertFalse('subdiv' in snames)
+        self.assertNotIn('subdiv', snames)
         snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
         self.assertIn('subdiv', snames)
 
--- a/server/test/unittest_migractions.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/server/test/unittest_migractions.py	Tue Apr 08 18:00:14 2014 +0200
@@ -72,7 +72,7 @@
         self.repo.vreg['etypes'].clear_caches()
 
     def test_add_attribute_bool(self):
-        self.assertFalse('yesno' in self.schema)
+        self.assertNotIn('yesno', self.schema)
         self.session.create_entity('Note')
         self.commit()
         self.mh.cmd_add_attribute('Note', 'yesno')
@@ -88,7 +88,7 @@
         self.mh.rollback()
 
     def test_add_attribute_int(self):
-        self.assertFalse('whatever' in self.schema)
+        self.assertNotIn('whatever', self.schema)
         self.session.create_entity('Note')
         self.session.commit(free_cnxset=False)
         orderdict = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
@@ -123,10 +123,10 @@
         self.mh.rollback()
 
     def test_add_attribute_varchar(self):
-        self.assertFalse('whatever' in self.schema)
+        self.assertNotIn('whatever', self.schema)
         self.session.create_entity('Note')
         self.session.commit(free_cnxset=False)
-        self.assertFalse('shortpara' in self.schema)
+        self.assertNotIn('shortpara', self.schema)
         self.mh.cmd_add_attribute('Note', 'shortpara')
         self.assertIn('shortpara', self.schema)
         self.assertEqual(self.schema['shortpara'].subjects(), ('Note', ))
@@ -142,9 +142,9 @@
         self.mh.rollback()
 
     def test_add_datetime_with_default_value_attribute(self):
-        self.assertFalse('mydate' in self.schema)
-        self.assertFalse('oldstyledefaultdate' in self.schema)
-        self.assertFalse('newstyledefaultdate' in self.schema)
+        self.assertNotIn('mydate', self.schema)
+        self.assertNotIn('oldstyledefaultdate', self.schema)
+        self.assertNotIn('newstyledefaultdate', self.schema)
         self.mh.cmd_add_attribute('Note', 'mydate')
         self.mh.cmd_add_attribute('Note', 'oldstyledefaultdate')
         self.mh.cmd_add_attribute('Note', 'newstyledefaultdate')
@@ -191,11 +191,11 @@
         self.mh.rollback()
 
     def test_rename_attribute(self):
-        self.assertFalse('civility' in self.schema)
+        self.assertNotIn('civility', self.schema)
         eid1 = self.mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0]
         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.assertNotIn('sexe', 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]
@@ -216,8 +216,8 @@
             self.assertEqual(s1, "foo")
 
     def test_add_entity_type(self):
-        self.assertFalse('Folder2' in self.schema)
-        self.assertFalse('filed_under2' in self.schema)
+        self.assertNotIn('Folder2', self.schema)
+        self.assertNotIn('filed_under2', self.schema)
         self.mh.cmd_add_entity_type('Folder2')
         self.assertIn('Folder2', self.schema)
         self.assertIn('Old', self.schema)
@@ -253,7 +253,7 @@
         self.session.commit(free_cnxset=False)
         eschema = self.schema.eschema('Folder2')
         self.mh.cmd_drop_entity_type('Folder2')
-        self.assertFalse('Folder2' in self.schema)
+        self.assertNotIn('Folder2', self.schema)
         self.assertFalse(self.session.execute('CWEType X WHERE X name "Folder2"'))
         # test automatic workflow deletion
         self.assertFalse(self.session.execute('Workflow X WHERE NOT X workflow_of ET'))
@@ -277,7 +277,7 @@
                                 if not e.final and e != 'Old'))
         self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',))
         self.mh.cmd_drop_relation_type('filed_under2')
-        self.assertFalse('filed_under2' in self.schema)
+        self.assertNotIn('filed_under2', self.schema)
 
     def test_add_relation_definition_nortype(self):
         self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire')
@@ -296,7 +296,7 @@
         self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire')
         self.assertIn('concerne2', self.schema)
         self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Note')
-        self.assertFalse('concerne2' in self.schema)
+        self.assertNotIn('concerne2', self.schema)
 
     def test_drop_relation_definition_existant_rtype(self):
         self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
@@ -523,10 +523,10 @@
             try:
                 self.mh.cmd_remove_cube('email', removedeps=True)
                 # file was there because it's an email dependancy, should have been removed
-                self.assertFalse('email' in self.config.cubes())
-                self.assertFalse(self.config.cube_dir('email') in self.config.cubes_path())
-                self.assertFalse('file' in self.config.cubes())
-                self.assertFalse(self.config.cube_dir('file') in self.config.cubes_path())
+                self.assertNotIn('email', self.config.cubes())
+                self.assertNotIn(self.config.cube_dir('email'), self.config.cubes_path())
+                self.assertNotIn('file', self.config.cubes())
+                self.assertNotIn(self.config.cube_dir('file'), self.config.cubes_path())
                 for ertype in ('Email', 'EmailThread', 'EmailPart', 'File',
                                'sender', 'in_thread', 'reply_to', 'data_format'):
                     self.assertFalse(ertype in schema, ertype)
@@ -583,7 +583,7 @@
             try:
                 self.mh.cmd_remove_cube('email')
                 cubes.remove('email')
-                self.assertFalse('email' in self.config.cubes())
+                self.assertNotIn('email', self.config.cubes())
                 self.assertIn('file', self.config.cubes())
                 for ertype in ('Email', 'EmailThread', 'EmailPart',
                                'sender', 'in_thread', 'reply_to'):
--- a/server/test/unittest_rqlannotation.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/server/test/unittest_rqlannotation.py	Tue Apr 08 18:00:14 2014 +0200
@@ -342,7 +342,7 @@
 
     def test_remove_from_deleted_source_1(self):
         rqlst = self._prepare('Note X WHERE X eid 999998, NOT X cw_source Y')
-        self.assertFalse('X' in rqlst.defined_vars) # simplified
+        self.assertNotIn('X', rqlst.defined_vars) # simplified
         self.assertEqual(rqlst.defined_vars['Y']._q_invariant, True)
 
     def test_remove_from_deleted_source_2(self):
--- a/sobjects/test/unittest_notification.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/sobjects/test/unittest_notification.py	Tue Apr 08 18:00:14 2014 +0200
@@ -31,10 +31,10 @@
         msgid1 = construct_message_id('testapp', 21)
         msgid2 = construct_message_id('testapp', 21)
         self.assertNotEqual(msgid1, msgid2)
-        self.assertFalse('&' in msgid1)
-        self.assertFalse('=' in msgid1)
-        self.assertFalse('/' in msgid1)
-        self.assertFalse('+' in msgid1)
+        self.assertNotIn('&', msgid1)
+        self.assertNotIn('=', msgid1)
+        self.assertNotIn('/', msgid1)
+        self.assertNotIn('+', msgid1)
         values = parse_message_id(msgid1, 'testapp')
         self.assertTrue(values)
         # parse_message_id should work with or without surrounding <>
--- a/test/unittest_schema.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/test/unittest_schema.py	Tue Apr 08 18:00:14 2014 +0200
@@ -249,7 +249,7 @@
     def test_fulltext_container(self):
         schema = loader.load(config)
         self.assertIn('has_text', schema['CWUser'].subject_relations())
-        self.assertFalse('has_text' in schema['EmailAddress'].subject_relations())
+        self.assertNotIn('has_text', schema['EmailAddress'].subject_relations())
 
     def test_permission_settings(self):
         schema = loader.load(config)
--- a/test/unittest_vregistry.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/test/unittest_vregistry.py	Tue Apr 08 18:00:14 2014 +0200
@@ -74,7 +74,7 @@
 
     def test_properties(self):
         self.vreg.reset()
-        self.assertFalse('system.version.cubicweb' in self.vreg['propertydefs'])
+        self.assertNotIn('system.version.cubicweb', self.vreg['propertydefs'])
         self.assertTrue(self.vreg.property_info('system.version.cubicweb'))
         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
 
--- a/web/test/unittest_propertysheet.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/web/test/unittest_propertysheet.py	Tue Apr 08 18:00:14 2014 +0200
@@ -42,12 +42,12 @@
         self.assertTrue(ps.need_reload())
         self.assertIn('pouet.css', ps._cache)
         ps.reload()
-        self.assertFalse('pouet.css' in ps._cache)
+        self.assertNotIn('pouet.css', ps._cache)
         self.assertFalse(ps.need_reload())
         ps.process_resource(DATADIR, 'pouet.css') # put in cache
         os.utime(join(DATADIR, 'pouet.css'), None)
         self.assertFalse(ps.need_reload())
-        self.assertFalse('pouet.css' in ps._cache)
+        self.assertNotIn('pouet.css', ps._cache)
 
 if __name__ == '__main__':
     unittest_main()
--- a/web/test/unittest_views_basecontrollers.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/web/test/unittest_views_basecontrollers.py	Tue Apr 08 18:00:14 2014 +0200
@@ -121,7 +121,7 @@
         path, params = self.expect_redirect_handle_request(req, 'edit')
         cnx.commit() # commit to check we don't get late validation error for instance
         self.assertEqual(path, 'cwuser/user')
-        self.assertFalse('vid' in params)
+        self.assertNotIn('vid', params)
 
     def test_user_editing_itself_no_relation(self):
         """checking we can edit an entity without specifying some required
--- a/web/test/unittest_views_navigation.py	Tue Apr 08 17:39:39 2014 +0200
+++ b/web/test/unittest_views_navigation.py	Tue Apr 08 18:00:14 2014 +0200
@@ -131,7 +131,7 @@
     #         req, rset=rset, view=view, context='navbottom')
     #     # breadcrumbs should _NOT_ be in footers by default
     #     clsids = set(obj.id for obj in objs)
-    #     self.assertFalse('breadcrumbs' in clsids)
+    #     self.assertNotIn('breadcrumbs', clsids)
     #     self.execute('INSERT CWProperty P: P pkey "ctxcomponents.breadcrumbs.context", '
     #                  'P value "navbottom"')
     #     # breadcrumbs should now be in footers
@@ -145,7 +145,7 @@
     #         req, rset=rset, view=view, context='navtop')
 
     #     clsids = [obj.id for obj in objs]
-    #     self.assertFalse('breadcrumbs' in clsids)
+    #     self.assertNotIn('breadcrumbs', clsids)
 
 
 if __name__ == '__main__':