Fix more file opening ResourceWarnings
I've managed to get better at grepping for this and this finds some of the stragglers. They are all file opens without closes fixed by using a with open() context manager. Change-Id: I7b8c8516a86558e2027cb0f01aefe2dd1849069cchanges/49/873049/1
parent
2747ea6f56
commit
ee3339c8e6
|
@ -40,7 +40,8 @@ def handle_repo(path):
|
|||
config_path = os.path.join(path, fn)
|
||||
break
|
||||
try:
|
||||
config = yaml.safe_load(open(config_path))
|
||||
with open(config_path) as f:
|
||||
config = yaml.safe_load(f)
|
||||
except Exception:
|
||||
print(" Has yaml errors")
|
||||
return
|
||||
|
|
|
@ -62,7 +62,8 @@ class TestGitDriver(ZuulTestCase):
|
|||
|
||||
# Update zuul.yaml to force a tenant reconfiguration
|
||||
path = os.path.join(self.upstream_root, 'common-config', 'zuul.yaml')
|
||||
config = yaml.safe_load(open(path, 'r').read())
|
||||
with open(path, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
change = {
|
||||
'name': 'org/project',
|
||||
'check': {
|
||||
|
|
|
@ -6199,7 +6199,8 @@ For CI problems and help debugging, contact ci@example.org"""
|
|||
|
||||
build = self.getBuildByName('check-job')
|
||||
inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml')
|
||||
inventory = yaml.safe_load(open(inv_path, 'r'))
|
||||
with open(inv_path, 'r') as f:
|
||||
inventory = yaml.safe_load(f)
|
||||
label = inventory['all']['hosts']['controller']['nodepool']['label']
|
||||
self.assertEqual('slow-label', label)
|
||||
|
||||
|
|
|
@ -140,7 +140,8 @@ def _read_config_file(filename: str):
|
|||
raise ValueError("Unable to read logging config file at %s" % filename)
|
||||
|
||||
if os.path.splitext(filename)[1] in ('.yml', '.yaml', '.json'):
|
||||
return yaml.safe_load(open(filename, 'r'))
|
||||
with open(filename, 'r') as f:
|
||||
return yaml.safe_load(f)
|
||||
return filename
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue