From d74198ee66f9d1bce932b4e4ce0402da6b2e3963 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 13 May 2016 15:27:33 -0400 Subject: [PATCH] Add a binary data test for queue file --- test/test_queuefile.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/test_queuefile.py b/test/test_queuefile.py index 15858190b..9e5b4a194 100644 --- a/test/test_queuefile.py +++ b/test/test_queuefile.py @@ -1,4 +1,5 @@ import unittest +import os from StringIO import StringIO @@ -74,6 +75,44 @@ class TestQueueFile(unittest.TestCase): self.assertIsNotNone(ex_found[0]) + def test_binary_data(self): + queue = FakeQueue() + + # Generate some binary data. + binary_data = os.urandom(1024) + queue.put(QueueResult(binary_data, None)) + queue.put(QueueResult(None, None)) + + queuefile = QueueFile(queue) + found_data = '' + while True: + current_data = queuefile.read(size=37) + if len(current_data) == 0: + break + + found_data = found_data + current_data + + self.assertEquals(found_data, binary_data) + + def test_empty_data(self): + queue = FakeQueue() + + # Generate some empty binary data. + binary_data = '\0' * 1024 + queue.put(QueueResult(binary_data, None)) + queue.put(QueueResult(None, None)) + + queuefile = QueueFile(queue) + found_data = '' + while True: + current_data = queuefile.read(size=37) + if len(current_data) == 0: + break + + found_data = found_data + current_data + + self.assertEquals(found_data, binary_data) + if __name__ == '__main__': unittest.main()