Add a binary data test for queue file
This commit is contained in:
parent
23e925b259
commit
d74198ee66
1 changed files with 39 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
@ -74,6 +75,44 @@ class TestQueueFile(unittest.TestCase):
|
||||||
|
|
||||||
self.assertIsNotNone(ex_found[0])
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Reference in a new issue