mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Use with to open temp file
This commit is contained in:
parent
352fe69e35
commit
056f3bb4c0
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user