From 36476283a42b7018312dc856e7a6139e3795c2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Thu, 16 Feb 2017 09:25:16 +0100 Subject: [PATCH] Test when the data image is coming via byte stream. --- tests/test_lsb.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_lsb.py b/tests/test_lsb.py index c464724..653d33f 100644 --- a/tests/test_lsb.py +++ b/tests/test_lsb.py @@ -24,6 +24,7 @@ __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2016/04/12 $" __license__ = "GPLv3" +import io import os import unittest @@ -77,6 +78,20 @@ class TestLSB(unittest.TestCase): with self.assertRaises(Exception): lsb.hide("./tests/sample-files/Lenna.png", message) + def test_with_bytes(self): + messages_to_hide = ["a", "foo", "Hello World!", ":Python:"] + + for message in messages_to_hide: + message = "Hello World" + outputBytes = io.BytesIO() + bytes_image = lsb.hide(open("./tests/sample-files/20160505T130442.jpg", 'rb'), message) + bytes_image.save(outputBytes, "PNG") + outputBytes.seek(0) + + clear_message = lsb.reveal(outputBytes) + + self.assertEqual(message, clear_message) + def tearDown(self): try: os.unlink("./image.png")