-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_subprocessio.py
More file actions
78 lines (66 loc) · 1.59 KB
/
test_subprocessio.py
File metadata and controls
78 lines (66 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import random
import unittest
import subprocessio
import tempfile
class MainTestCase(unittest.TestCase):
def getiter(self, cmd, input):
try:
return subprocessio.SubprocessIOChunker(
cmd,
input,
buffer_size = 65536,
chunk_size = 4096
)
except (EnvironmentError) as e:
# just because.
print str(e)
raise e
def setUp(self):
pass
def tearDown(self):
pass
def test_01_string_throughput(self):
cmd = 'cat'
input = 'This is a test string'
_r = self.getiter(
cmd,
input
)
self.assertEqual(
"".join(_r),
input
)
def test_02_io_throughput(self):
cmd = 'cat'
size = 128000
i = size
input = tempfile.TemporaryFile()
checksum = 0
while i:
_r = random.randrange(32,255)
checksum += _r
input.write(chr(_r))
i -= 1
input.seek(0)
_r = self.getiter(
cmd,
input
)
for e in _r:
size -= len(e)
for l in e:
checksum -= ord(l)
self.assertEqual(
size,
0
)
self.assertEqual(
checksum,
0
)
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(
unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(MainTestCase),
])
)