tests: use file() to open file (#36515)

This commit is contained in:
Frédéric Péters 2019-11-12 11:07:50 +01:00
parent d33ae185a7
commit e4bd408044
7 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ def site_options(request, pub, section, variable, value):
if not config.has_section(section):
config.add_section(section)
config.set(section, variable, value)
with file(path, 'w') as site_option:
with open(path, 'w') as site_option:
config.write(site_option)
def fin():
@ -31,7 +31,7 @@ def site_options(request, pub, section, variable, value):
if os.path.exists(path):
config.read([path])
config.remove_option(section, variable)
with file(path, 'w') as site_option:
with open(path, 'w') as site_option:
config.write(site_option)
request.addfinalizer(fin)
return value

View File

@ -51,7 +51,7 @@ def pub(request, emails):
pub.cfg['language'] = {'language': 'en'}
pub.write_cfg()
file(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write('''\
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write('''\
[api-secrets]
coucou = 1234
''')

View File

@ -102,7 +102,7 @@ def test_load_old_pickle():
test.description = 'Hello world'
os.mkdir(os.path.join(pub.app_dir, 'categories'))
fd = file(os.path.join(pub.app_dir, 'categories', '1'), 'w')
fd = open(os.path.join(pub.app_dir, 'categories', '1'), 'wb')
pickle.dump(test, fd)
fd.close()

View File

@ -404,7 +404,7 @@ def test_configure_postgresql():
['http://wcs.example.net/', os.path.join(alt_tempdir, 'hobo.json')])
assert os.path.exists(os.path.join(alt_tempdir, 'wcs.example.net'))
fd = file(os.path.join(alt_tempdir, 'wcs.example.net', 'site-options.cfg'), 'w')
fd = open(os.path.join(alt_tempdir, 'wcs.example.net', 'site-options.cfg'), 'w')
fd.write('[options]\n')
fd.write('postgresql = true\n')
fd.close()

View File

@ -79,17 +79,17 @@ def setup_idps(pub, idp_number=1):
'role': lasso.PROVIDER_ROLE_IDP,
}
filename = pub.cfg['idp'][base_id]['metadata']
fd = file(os.path.join(pub.app_dir, filename), 'w')
fd = open(os.path.join(pub.app_dir, filename), 'w')
fd.write(metadata)
fd.close()
filename = pub.cfg['idp'][base_id]['publickey']
fd = file(os.path.join(pub.app_dir, filename), 'w')
fd = open(os.path.join(pub.app_dir, filename), 'w')
fd.write(idp_publickey)
fd.close()
filename = pub.cfg['idp'][base_id]['publickey'].replace('public', 'private')
fd = file(os.path.join(pub.app_dir, filename), 'w')
fd = open(os.path.join(pub.app_dir, filename), 'w')
fd.write(idp_privatekey)
fd.close()

View File

@ -60,7 +60,7 @@ def app(pub):
def test_session_max_age(pub, user, app):
with file(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as cfg:
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as cfg:
cfg.write('''[options]
session_max_age: 1
''')

View File

@ -100,7 +100,7 @@ def create_temporary_pub(sql_mode=False, templates_mode=False, lazy_mode=False):
created = True
# always reset site-options.cfg
fd = file(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
fd.write('[wscall-secrets]\n')
fd.write('idp.example.net = BAR\n')
fd.write('\n')