Add a binary data test for queue file

This commit is contained in:
Joseph Schorr 2016-05-13 15:27:33 -04:00
parent 23e925b259
commit d74198ee66

View file

@ -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()