Skip to content

Commit d6ad4eb

Browse files
authored
Close Temporary file handles (#1363)
Signed-off-by: Mark Reid <[email protected]>
1 parent 7f1f4f8 commit d6ad4eb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

tests/test_otiod.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def test_file_bundle_manifest(self):
102102
self.assertEqual(len(manifest[fname]), count)
103103

104104
def test_round_trip(self):
105-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otiod").name
105+
with tempfile.NamedTemporaryFile(suffix=".otiod") as bogusfile:
106+
tmp_path = bogusfile.name
106107
otio.adapters.write_to_file(self.tl, tmp_path)
107108
self.assertTrue(os.path.exists(tmp_path))
108109

@@ -132,7 +133,8 @@ def test_round_trip(self):
132133
self.assertJsonEqual(result, self.tl)
133134

134135
def test_round_trip_all_missing_references(self):
135-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otiod").name
136+
with tempfile.NamedTemporaryFile(suffix=".otiod") as bogusfile:
137+
tmp_path = bogusfile.name
136138
otio.adapters.write_to_file(
137139
self.tl,
138140
tmp_path,
@@ -154,7 +156,8 @@ def test_round_trip_all_missing_references(self):
154156
)
155157

156158
def test_round_trip_absolute_paths(self):
157-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otiod").name
159+
with tempfile.NamedTemporaryFile(suffix=".otiod") as bogusfile:
160+
tmp_path = bogusfile.name
158161
otio.adapters.write_to_file(self.tl, tmp_path)
159162

160163
# ...but can be optionally told to generate absolute paths

tests/test_otioz.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def test_colliding_basename(self):
124124
shutil.rmtree(tempdir)
125125

126126
def test_round_trip(self):
127-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otioz").name
127+
with tempfile.NamedTemporaryFile(suffix=".otioz") as bogusfile:
128+
tmp_path = bogusfile.name
128129
otio.adapters.write_to_file(self.tl, tmp_path)
129130
self.assertTrue(os.path.exists(tmp_path))
130131

@@ -155,7 +156,8 @@ def test_round_trip(self):
155156
self.assertJsonEqual(result, self.tl)
156157

157158
def test_round_trip_with_extraction(self):
158-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otioz").name
159+
with tempfile.NamedTemporaryFile(suffix=".otioz") as bogusfile:
160+
tmp_path = bogusfile.name
159161
otio.adapters.write_to_file(self.tl, tmp_path)
160162
self.assertTrue(os.path.exists(tmp_path))
161163

@@ -213,7 +215,8 @@ def test_round_trip_with_extraction(self):
213215
)
214216

215217
def test_round_trip_with_extraction_no_media(self):
216-
tmp_path = tempfile.NamedTemporaryFile(suffix=".otioz").name
218+
with tempfile.NamedTemporaryFile(suffix=".otioz") as bogusfile:
219+
tmp_path = bogusfile.name
217220
otio.adapters.write_to_file(
218221
self.tl,
219222
tmp_path,

0 commit comments

Comments
 (0)