Use with to open temp file

This commit is contained in:
twangboy 2017-09-14 08:42:19 -06:00
parent 352fe69e35
commit 056f3bb4c0
No known key found for this signature in database
GPG Key ID: 93FF3BDEB278C9EB

View File

@ -111,8 +111,8 @@ class FileReplaceTestCase(TestCase, LoaderModuleMockMixin):
os.remove(tfile.name)
# A newline should not be added in empty files
tfile = tempfile.NamedTemporaryFile('w+b', delete=False)
tfile.close()
with tempfile.NamedTemporaryFile('w+b', delete=False) as tfile:
pass
filemod.replace(tfile.name, **args)
expected = args['repl'] + os.linesep
with salt.utils.fopen(tfile.name) as tfile2:
@ -343,8 +343,8 @@ class FileBlockReplaceTestCase(TestCase, LoaderModuleMockMixin):
os.remove(tfile.name)
# A newline should not be added in empty files
tfile = tempfile.NamedTemporaryFile(mode='w+b', delete=False)
tfile.close()
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as tfile:
pass
filemod.blockreplace(tfile.name, **args)
with salt.utils.fopen(tfile.name) as tfile2:
self.assertEqual(tfile2.read(), block)