Currently, running gcc-changelog's unit tests may clutter the output
with tons of warnings such as:
.../contrib/gcc-changelog/git_email.py:40: ResourceWarning: unclosed
file <_io.TextIOWrapper name='/tmp/tmpt5okd4qp.patch' mode='r'
encoding='UTF-8'>
lines = open(self.filename).read().splitlines()
ResourceWarning: Enable tracemalloc to get the object allocation
traceback
This commit fixes these leaks, which restores a clean testsuite output.
contrib/
* gcc-changelog/git_update_version.py: Close file objects after
use.
* gcc-changelog/git_email.py: Likewise.
* gcc-changelog/test_email.py: Likewise.
date = None
author = None
- lines = open(self.filename).read().splitlines()
+ with open(self.filename, 'r') as f:
+ lines = f.read().splitlines()
lines = list(takewhile(lambda line: line != '---', lines))
for line in lines:
if line.startswith(DATE_PREFIX):
def read_timestamp(path):
- return open(path).read()
+ with open(path) as f:
+ return f.read()
def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
full_path = os.path.join(folder, entry, 'ChangeLog')
print('writting to %s' % full_path)
if os.path.exists(full_path):
- content = open(full_path).read()
+ with open(full_path) as f:
+ content = f.read()
else:
content = ''
with open(full_path, 'w+') as f:
filename = None
patch_lines = []
- lines = open(os.path.join(script_path, 'test_patches.txt')).read()
+ with open(os.path.join(script_path, 'test_patches.txt')) as f:
+ lines = f.read()
for line in lines.split('\n'):
if line.startswith('==='):
if patch_lines: