##// END OF EJS Templates
tests: reduced memory footprint on subprocession tests....
ergo -
r638:be949416 default
parent child Browse files
Show More
@@ -24,6 +24,29 b' import pytest'
24 from vcsserver import subprocessio
24 from vcsserver import subprocessio
25
25
26
26
27 class KindaFilelike(object): # pragma: no cover
28
29 def __init__(self, data, size):
30 chunks = size / len(data)
31
32 self.stream = self._get_stream(data, chunks)
33
34 def _get_stream(self, data, chunks):
35 for x in xrange(chunks):
36 yield data
37
38 def read(self, n):
39
40 buffer_stream = ''
41 for chunk in self.stream:
42 buffer_stream += chunk
43 if len(buffer_stream) >= n:
44 break
45
46 # self.stream = self.bytes[n:]
47 return buffer_stream
48
49
27 @pytest.fixture(scope='module')
50 @pytest.fixture(scope='module')
28 def environ():
51 def environ():
29 """Delete coverage variables, as they make the tests fail."""
52 """Delete coverage variables, as they make the tests fail."""
@@ -101,8 +124,9 b' def test_output_with_no_input_does_not_f'
101
124
102 @pytest.mark.parametrize('size', [1, 10 ** 5])
125 @pytest.mark.parametrize('size', [1, 10 ** 5])
103 def test_output_with_input(size, environ):
126 def test_output_with_input(size, environ):
104 data = 'X' * size
127 data_len = size
105 inputstream = io.BytesIO(data)
128 inputstream = KindaFilelike('X', size)
129
106 # This acts like the cat command.
130 # This acts like the cat command.
107 args = _get_python_args('shutil.copyfileobj(sys.stdin, sys.stdout)')
131 args = _get_python_args('shutil.copyfileobj(sys.stdin, sys.stdout)')
108 output = ''.join(
132 output = ''.join(
@@ -111,14 +135,14 b' def test_output_with_input(size, environ'
111 )
135 )
112 )
136 )
113
137
114 print("{} {}".format(len(data * size), len(output)))
138 assert len(output) == data_len
115 assert output == data
116
139
117
140
118 @pytest.mark.parametrize('size', [1, 10 ** 5])
141 @pytest.mark.parametrize('size', [1, 10 ** 5])
119 def test_output_with_input_skipping_iterator(size, environ):
142 def test_output_with_input_skipping_iterator(size, environ):
120 data = 'X' * size
143 data_len = size
121 inputstream = io.BytesIO(data)
144 inputstream = KindaFilelike('X', size)
145
122 # This acts like the cat command.
146 # This acts like the cat command.
123 args = _get_python_args('shutil.copyfileobj(sys.stdin, sys.stdout)')
147 args = _get_python_args('shutil.copyfileobj(sys.stdin, sys.stdout)')
124
148
@@ -128,5 +152,4 b' def test_output_with_input_skipping_iter'
128 )
152 )
129 output = ''.join(chunker.output)
153 output = ''.join(chunker.output)
130
154
131 print("{} {}".format(len(data * size), len(output)))
155 assert len(output) == data_len
132 assert output == data
General Comments 0
You need to be logged in to leave comments. Login now