Fix ResourceWarning: unclosed file, in tests

This commit is contained in:
Mickaël Schoentgen 2018-08-18 11:43:38 +02:00
parent 041a4ee05b
commit f9619a8e1c
2 changed files with 10 additions and 10 deletions

View file

@ -86,12 +86,11 @@ class TestEXIFHeader(unittest.TestCase):
def test_with_bytes(self): def test_with_bytes(self):
outputBytes = io.BytesIO() outputBytes = io.BytesIO()
message = b"Secret" message = b"Secret"
exifHeader.hide(open("./tests/sample-files/20160505T130442.jpg", 'rb'), with open("./tests/sample-files/20160505T130442.jpg", 'rb') as f:
outputBytes, exifHeader.hide(f, outputBytes, secret_message=message)
secret_message=message)
clear_message = exifHeader.reveal(outputBytes) clear_message = exifHeader.reveal(outputBytes)
self.assertEqual(message, clear_message) self.assertEqual(message, clear_message)
def tearDown(self): def tearDown(self):
try: try:

View file

@ -134,13 +134,14 @@ class TestLSB(unittest.TestCase):
for message in messages_to_hide: for message in messages_to_hide:
message = "Hello World" message = "Hello World"
outputBytes = io.BytesIO() outputBytes = io.BytesIO()
bytes_image = lsb.hide(open("./tests/sample-files/20160505T130442.jpg", 'rb'), message) with open("./tests/sample-files/20160505T130442.jpg", 'rb') as f:
bytes_image.save(outputBytes, "PNG") bytes_image = lsb.hide(f, message)
outputBytes.seek(0) bytes_image.save(outputBytes, "PNG")
outputBytes.seek(0)
clear_message = lsb.reveal(outputBytes) clear_message = lsb.reveal(outputBytes)
self.assertEqual(message, clear_message) self.assertEqual(message, clear_message)
def tearDown(self): def tearDown(self):
try: try: