summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/scanner/test_transformer.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py
index 27bfad58..4731b5ce 100644
--- a/tests/scanner/test_transformer.py
+++ b/tests/scanner/test_transformer.py
@@ -16,11 +16,14 @@ from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
def create_scanner_from_source_string(source):
ss = SourceScanner()
tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True)
- file = os.fdopen(tmp_fd, 'wt')
- file.write(source)
- file.close()
- ss.parse_files([tmp_name])
+ try:
+ with os.fdopen(tmp_fd, 'wt') as file:
+ file.write(source)
+ ss.parse_files([tmp_name])
+ finally:
+ os.unlink(tmp_name)
+
return ss