Commit 609e795c authored by Julien Cristau's avatar Julien Cristau
Browse files

[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.
parent 96549de9dd70
...@@ -39,7 +39,7 @@ class AutoExtendableTC(TestCase): ...@@ -39,7 +39,7 @@ class AutoExtendableTC(TestCase):
def test_autoextend(self): def test_autoextend(self):
self.assertFalse('generate_server' in dir(ValueGenerator)) self.assertNotIn('generate_server', dir(ValueGenerator))
class MyValueGenerator(ValueGenerator): class MyValueGenerator(ValueGenerator):
def generate_server(self, index): def generate_server(self, index):
return attrname return attrname
...@@ -47,19 +47,19 @@ class AutoExtendableTC(TestCase): ...@@ -47,19 +47,19 @@ class AutoExtendableTC(TestCase):
def test_bad_signature_detection(self): def test_bad_signature_detection(self):
self.assertFalse('generate_server' in dir(ValueGenerator)) self.assertNotIn('generate_server', dir(ValueGenerator))
try: try:
class MyValueGenerator(ValueGenerator): class MyValueGenerator(ValueGenerator):
def generate_server(self): def generate_server(self):
pass pass
except TypeError: except TypeError:
self.assertFalse('generate_server' in dir(ValueGenerator)) self.assertNotIn('generate_server', dir(ValueGenerator))
else: else:
self.fail('TypeError not raised') self.fail('TypeError not raised')
def test_signature_extension(self): def test_signature_extension(self):
self.assertFalse('generate_server' in dir(ValueGenerator)) self.assertNotIn('generate_server', dir(ValueGenerator))
class MyValueGenerator(ValueGenerator): class MyValueGenerator(ValueGenerator):
def generate_server(self, index, foo): def generate_server(self, index, foo):
pass pass
......
...@@ -82,8 +82,8 @@ class SchemaModificationHooksTC(CubicWebTC): ...@@ -82,8 +82,8 @@ class SchemaModificationHooksTC(CubicWebTC):
'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E ' '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] 'WHERE RT name "concerne2", E name "Societe2"')[0][0]
self._set_perms(concerne2_rdef_eid) self._set_perms(concerne2_rdef_eid)
self.assertFalse('name' in schema['Societe2'].subject_relations()) self.assertNotIn('name', schema['Societe2'].subject_relations())
self.assertFalse('concerne2' in schema['Societe2'].subject_relations()) self.assertNotIn('concerne2', schema['Societe2'].subject_relations())
self.assertFalse(self.index_exists('Societe2', 'name')) self.assertFalse(self.index_exists('Societe2', 'name'))
self.commit() self.commit()
self.assertIn('name', schema['Societe2'].subject_relations()) self.assertIn('name', schema['Societe2'].subject_relations())
...@@ -104,7 +104,7 @@ class SchemaModificationHooksTC(CubicWebTC): ...@@ -104,7 +104,7 @@ class SchemaModificationHooksTC(CubicWebTC):
self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid}) self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
self.commit() self.commit()
self.assertIn('concerne2', schema['CWUser'].subject_relations()) 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')) self.assertFalse(self.execute('Any X WHERE X concerne2 Y'))
# schema should be cleaned on delete (after commit) # schema should be cleaned on delete (after commit)
self.execute('DELETE CWEType X WHERE X name "Societe2"') self.execute('DELETE CWEType X WHERE X name "Societe2"')
...@@ -116,7 +116,7 @@ class SchemaModificationHooksTC(CubicWebTC): ...@@ -116,7 +116,7 @@ class SchemaModificationHooksTC(CubicWebTC):
self.assertFalse(self.index_exists('Societe2', 'name')) self.assertFalse(self.index_exists('Societe2', 'name'))
self.assertFalse(schema.has_entity('Societe2')) self.assertFalse(schema.has_entity('Societe2'))
self.assertFalse(schema.has_entity('concerne2')) 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): def test_metartype_with_nordefs(self):
META_RTYPES.add('custom_meta') META_RTYPES.add('custom_meta')
...@@ -152,7 +152,7 @@ class SchemaModificationHooksTC(CubicWebTC): ...@@ -152,7 +152,7 @@ class SchemaModificationHooksTC(CubicWebTC):
instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)] 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']) self.assertEqual(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')] 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')] snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
self.assertIn('subdiv', snames) self.assertIn('subdiv', snames)
......
...@@ -72,7 +72,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -72,7 +72,7 @@ class MigrationCommandsTC(CubicWebTC):
self.repo.vreg['etypes'].clear_caches() self.repo.vreg['etypes'].clear_caches()
def test_add_attribute_bool(self): def test_add_attribute_bool(self):
self.assertFalse('yesno' in self.schema) self.assertNotIn('yesno', self.schema)
self.session.create_entity('Note') self.session.create_entity('Note')
self.commit() self.commit()
self.mh.cmd_add_attribute('Note', 'yesno') self.mh.cmd_add_attribute('Note', 'yesno')
...@@ -88,7 +88,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -88,7 +88,7 @@ class MigrationCommandsTC(CubicWebTC):
self.mh.rollback() self.mh.rollback()
def test_add_attribute_int(self): def test_add_attribute_int(self):
self.assertFalse('whatever' in self.schema) self.assertNotIn('whatever', self.schema)
self.session.create_entity('Note') self.session.create_entity('Note')
self.session.commit(free_cnxset=False) self.session.commit(free_cnxset=False)
orderdict = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, ' orderdict = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
...@@ -123,10 +123,10 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -123,10 +123,10 @@ class MigrationCommandsTC(CubicWebTC):
self.mh.rollback() self.mh.rollback()
def test_add_attribute_varchar(self): def test_add_attribute_varchar(self):
self.assertFalse('whatever' in self.schema) self.assertNotIn('whatever', self.schema)
self.session.create_entity('Note') self.session.create_entity('Note')
self.session.commit(free_cnxset=False) 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.mh.cmd_add_attribute('Note', 'shortpara')
self.assertIn('shortpara', self.schema) self.assertIn('shortpara', self.schema)
self.assertEqual(self.schema['shortpara'].subjects(), ('Note', )) self.assertEqual(self.schema['shortpara'].subjects(), ('Note', ))
...@@ -142,9 +142,9 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -142,9 +142,9 @@ class MigrationCommandsTC(CubicWebTC):
self.mh.rollback() self.mh.rollback()
def test_add_datetime_with_default_value_attribute(self): def test_add_datetime_with_default_value_attribute(self):
self.assertFalse('mydate' in self.schema) self.assertNotIn('mydate', self.schema)
self.assertFalse('oldstyledefaultdate' in self.schema) self.assertNotIn('oldstyledefaultdate', self.schema)
self.assertFalse('newstyledefaultdate' in self.schema) self.assertNotIn('newstyledefaultdate', self.schema)
self.mh.cmd_add_attribute('Note', 'mydate') self.mh.cmd_add_attribute('Note', 'mydate')
self.mh.cmd_add_attribute('Note', 'oldstyledefaultdate') self.mh.cmd_add_attribute('Note', 'oldstyledefaultdate')
self.mh.cmd_add_attribute('Note', 'newstyledefaultdate') self.mh.cmd_add_attribute('Note', 'newstyledefaultdate')
...@@ -191,11 +191,11 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -191,11 +191,11 @@ class MigrationCommandsTC(CubicWebTC):
self.mh.rollback() self.mh.rollback()
def test_rename_attribute(self): 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] 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] 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.mh.cmd_rename_attribute('Personne', 'sexe', 'civility')
self.assertFalse('sexe' in self.schema) self.assertNotIn('sexe', self.schema)
self.assertIn('civility', self.schema) self.assertIn('civility', self.schema)
# test data has been backported # test data has been backported
c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0] c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0]
...@@ -216,8 +216,8 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -216,8 +216,8 @@ class MigrationCommandsTC(CubicWebTC):
self.assertEqual(s1, "foo") self.assertEqual(s1, "foo")
def test_add_entity_type(self): def test_add_entity_type(self):
self.assertFalse('Folder2' in self.schema) self.assertNotIn('Folder2', self.schema)
self.assertFalse('filed_under2' in self.schema) self.assertNotIn('filed_under2', self.schema)
self.mh.cmd_add_entity_type('Folder2') self.mh.cmd_add_entity_type('Folder2')
self.assertIn('Folder2', self.schema) self.assertIn('Folder2', self.schema)
self.assertIn('Old', self.schema) self.assertIn('Old', self.schema)
...@@ -253,7 +253,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -253,7 +253,7 @@ class MigrationCommandsTC(CubicWebTC):
self.session.commit(free_cnxset=False) self.session.commit(free_cnxset=False)
eschema = self.schema.eschema('Folder2') eschema = self.schema.eschema('Folder2')
self.mh.cmd_drop_entity_type('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"')) self.assertFalse(self.session.execute('CWEType X WHERE X name "Folder2"'))
# test automatic workflow deletion # test automatic workflow deletion
self.assertFalse(self.session.execute('Workflow X WHERE NOT X workflow_of ET')) self.assertFalse(self.session.execute('Workflow X WHERE NOT X workflow_of ET'))
...@@ -277,7 +277,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -277,7 +277,7 @@ class MigrationCommandsTC(CubicWebTC):
if not e.final and e != 'Old')) if not e.final and e != 'Old'))
self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',)) self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',))
self.mh.cmd_drop_relation_type('filed_under2') 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): def test_add_relation_definition_nortype(self):
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire')
...@@ -296,7 +296,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -296,7 +296,7 @@ class MigrationCommandsTC(CubicWebTC):
self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire') self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire')
self.assertIn('concerne2', self.schema) self.assertIn('concerne2', self.schema)
self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Note') 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): def test_drop_relation_definition_existant_rtype(self):
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
...@@ -523,10 +523,10 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -523,10 +523,10 @@ class MigrationCommandsTC(CubicWebTC):
try: try:
self.mh.cmd_remove_cube('email', removedeps=True) self.mh.cmd_remove_cube('email', removedeps=True)
# file was there because it's an email dependancy, should have been removed # file was there because it's an email dependancy, should have been removed
self.assertFalse('email' in self.config.cubes()) self.assertNotIn('email', self.config.cubes())
self.assertFalse(self.config.cube_dir('email') in self.config.cubes_path()) self.assertNotIn(self.config.cube_dir('email'), self.config.cubes_path())
self.assertFalse('file' in self.config.cubes()) self.assertNotIn('file', self.config.cubes())
self.assertFalse(self.config.cube_dir('file') in self.config.cubes_path()) self.assertNotIn(self.config.cube_dir('file'), self.config.cubes_path())
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', for ertype in ('Email', 'EmailThread', 'EmailPart', 'File',
'sender', 'in_thread', 'reply_to', 'data_format'): 'sender', 'in_thread', 'reply_to', 'data_format'):
self.assertFalse(ertype in schema, ertype) self.assertFalse(ertype in schema, ertype)
...@@ -583,7 +583,7 @@ class MigrationCommandsTC(CubicWebTC): ...@@ -583,7 +583,7 @@ class MigrationCommandsTC(CubicWebTC):
try: try:
self.mh.cmd_remove_cube('email') self.mh.cmd_remove_cube('email')
cubes.remove('email') cubes.remove('email')
self.assertFalse('email' in self.config.cubes()) self.assertNotIn('email', self.config.cubes())
self.assertIn('file', self.config.cubes()) self.assertIn('file', self.config.cubes())
for ertype in ('Email', 'EmailThread', 'EmailPart', for ertype in ('Email', 'EmailThread', 'EmailPart',
'sender', 'in_thread', 'reply_to'): 'sender', 'in_thread', 'reply_to'):
......
...@@ -342,7 +342,7 @@ class SQLGenAnnotatorTC(BaseQuerierTC): ...@@ -342,7 +342,7 @@ class SQLGenAnnotatorTC(BaseQuerierTC):
def test_remove_from_deleted_source_1(self): def test_remove_from_deleted_source_1(self):
rqlst = self._prepare('Note X WHERE X eid 999998, NOT X cw_source Y') 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) self.assertEqual(rqlst.defined_vars['Y']._q_invariant, True)
def test_remove_from_deleted_source_2(self): def test_remove_from_deleted_source_2(self):
......
...@@ -31,10 +31,10 @@ class MessageIdTC(TestCase): ...@@ -31,10 +31,10 @@ class MessageIdTC(TestCase):
msgid1 = construct_message_id('testapp', 21) msgid1 = construct_message_id('testapp', 21)
msgid2 = construct_message_id('testapp', 21) msgid2 = construct_message_id('testapp', 21)
self.assertNotEqual(msgid1, msgid2) self.assertNotEqual(msgid1, msgid2)
self.assertFalse('&' in msgid1) self.assertNotIn('&', msgid1)
self.assertFalse('=' in msgid1) self.assertNotIn('=', msgid1)
self.assertFalse('/' in msgid1) self.assertNotIn('/', msgid1)
self.assertFalse('+' in msgid1) self.assertNotIn('+', msgid1)
values = parse_message_id(msgid1, 'testapp') values = parse_message_id(msgid1, 'testapp')
self.assertTrue(values) self.assertTrue(values)
# parse_message_id should work with or without surrounding <> # parse_message_id should work with or without surrounding <>
......
...@@ -249,7 +249,7 @@ class SchemaReaderClassTest(TestCase): ...@@ -249,7 +249,7 @@ class SchemaReaderClassTest(TestCase):
def test_fulltext_container(self): def test_fulltext_container(self):
schema = loader.load(config) schema = loader.load(config)
self.assertIn('has_text', schema['CWUser'].subject_relations()) 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): def test_permission_settings(self):
schema = loader.load(config) schema = loader.load(config)
......
...@@ -74,7 +74,7 @@ class VRegistryTC(TestCase): ...@@ -74,7 +74,7 @@ class VRegistryTC(TestCase):
def test_properties(self): def test_properties(self):
self.vreg.reset() 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.assertTrue(self.vreg.property_info('system.version.cubicweb'))
self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key') self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
......
...@@ -42,12 +42,12 @@ class PropertySheetTC(TestCase): ...@@ -42,12 +42,12 @@ class PropertySheetTC(TestCase):
self.assertTrue(ps.need_reload()) self.assertTrue(ps.need_reload())
self.assertIn('pouet.css', ps._cache) self.assertIn('pouet.css', ps._cache)
ps.reload() ps.reload()
self.assertFalse('pouet.css' in ps._cache) self.assertNotIn('pouet.css', ps._cache)
self.assertFalse(ps.need_reload()) self.assertFalse(ps.need_reload())
ps.process_resource(DATADIR, 'pouet.css') # put in cache ps.process_resource(DATADIR, 'pouet.css') # put in cache
os.utime(join(DATADIR, 'pouet.css'), None) os.utime(join(DATADIR, 'pouet.css'), None)
self.assertFalse(ps.need_reload()) self.assertFalse(ps.need_reload())
self.assertFalse('pouet.css' in ps._cache) self.assertNotIn('pouet.css', ps._cache)
if __name__ == '__main__': if __name__ == '__main__':
unittest_main() unittest_main()
...@@ -121,7 +121,7 @@ class EditControllerTC(CubicWebTC): ...@@ -121,7 +121,7 @@ class EditControllerTC(CubicWebTC):
path, params = self.expect_redirect_handle_request(req, 'edit') path, params = self.expect_redirect_handle_request(req, 'edit')
cnx.commit() # commit to check we don't get late validation error for instance cnx.commit() # commit to check we don't get late validation error for instance
self.assertEqual(path, 'cwuser/user') self.assertEqual(path, 'cwuser/user')
self.assertFalse('vid' in params) self.assertNotIn('vid', params)
def test_user_editing_itself_no_relation(self): def test_user_editing_itself_no_relation(self):
"""checking we can edit an entity without specifying some required """checking we can edit an entity without specifying some required
......
...@@ -131,7 +131,7 @@ class NavigationTC(CubicWebTC): ...@@ -131,7 +131,7 @@ class NavigationTC(CubicWebTC):
# req, rset=rset, view=view, context='navbottom') # req, rset=rset, view=view, context='navbottom')
# # breadcrumbs should _NOT_ be in footers by default # # breadcrumbs should _NOT_ be in footers by default
# clsids = set(obj.id for obj in objs) # 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", ' # self.execute('INSERT CWProperty P: P pkey "ctxcomponents.breadcrumbs.context", '
# 'P value "navbottom"') # 'P value "navbottom"')
# # breadcrumbs should now be in footers # # breadcrumbs should now be in footers
...@@ -145,7 +145,7 @@ class NavigationTC(CubicWebTC): ...@@ -145,7 +145,7 @@ class NavigationTC(CubicWebTC):
# req, rset=rset, view=view, context='navtop') # req, rset=rset, view=view, context='navtop')
# clsids = [obj.id for obj in objs] # clsids = [obj.id for obj in objs]
# self.assertFalse('breadcrumbs' in clsids) # self.assertNotIn('breadcrumbs', clsids)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment