Fixes issue 1571:

Adding missing close for open.
If the "close()" call is missing after a "open(filename)" call, the filename isn't guaranteed to be closed before the interpreter exits.
This is generally a bad practice as explained here: https://stackoverflow.com/questions/7395542/is-explicitly-closing-files-important

Also replaced "fid=open(filename) fid.close()" statements for files with the safer
"with open(filename) as fid:" blocks. See https://www.python.org/dev/peps/pep-0343/
This commit is contained in:
Per A. Brodtkorb
2020-03-23 17:16:44 +01:00
parent 8e2627e8e3
commit e4e8bf8317
38 changed files with 230 additions and 266 deletions

View File

@@ -89,9 +89,8 @@ class lib_pubsub_Except(wtc.PubsubTestCase):
pass
"""
myTopicTree = open('myTopicTree.py', 'w')
myTopicTree.write(dedent(provFile))
myTopicTree.close()
with open('myTopicTree.py', 'w') as myTopicTree:
myTopicTree.write(dedent(provFile))
self.pub.addTopicDefnProvider('myTopicTree',
format=self.pub.TOPIC_TREE_FROM_MODULE)
import os