forked from timvideos/gst-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_testsource.py
266 lines (203 loc) · 7 KB
/
test_testsource.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../../")))
from gstswitch.exception import RangeError
from gstswitch.testsource import Preview, VideoSrc, BasePipeline, VideoPipeline
import pytest
from mock import Mock, patch
from gi.repository import Gst
class TestVideoSrcPort(object):
def test_blank(self):
tests = ['', None, [], {}]
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=test)
def test_range(self):
tests = [-100, 1e7, 65536]
for test in tests:
with pytest.raises(RangeError):
VideoSrc(port=test)
def test_invalid(self):
tests = [[1, 2, 3, 4], {1: 2, 2: 3}, '1e10']
for test in tests:
with pytest.raises(TypeError):
VideoSrc(port=test)
def test_normal(self):
tests = [1, 65535, 1000]
for test in tests:
src = VideoSrc(port=test)
assert src.port == test
class TestVideoSrcWidth(object):
def test_blank(self):
tests = ['', None, [], {}]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, width=test)
def test_non_positive(self):
tests = ['-1.111', -1.111, 0, -1e10]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, width=test)
def test_invalid(self):
tests = [[1, 2, 3], {1: 2, 2: 3}, (1, 2)]
port = 1000
for test in tests:
with pytest.raises(TypeError):
VideoSrc(port=port, width=test)
def test_normal(self):
tests = [ 1e6, 300, '200']
port = 1000
for test in tests:
src = VideoSrc(port=port, width=test)
assert src.width == test
class TestVideoSrcHeight(object):
def test_blank(self):
tests = ['', None, [], {}]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, height=test)
def test_non_positive(self):
tests = ['-1.111', -1.111, 0, -1e10]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, height=test)
def test_invalid(self):
tests = [[1, 2, 3], {1: 2, 2: 3}, (1, 2)]
port = 1000
for test in tests:
with pytest.raises(TypeError):
VideoSrc(port=port, height=test)
def test_normal(self):
tests = [1e6, 300, '200']
port = 1000
for test in tests:
src = VideoSrc(port=port, height=test)
assert src.height == test
class TestVideoSrcPattern(object):
def test_range(self):
tests = [-100, 1e7, 65536, -1, 20]
port = 1000
for test in tests:
with pytest.raises(RangeError):
VideoSrc(port=port, pattern=test)
def test_invalid(self):
tests = [[1, 2, 3, 4], {1: 2, 2: 3}]
port = 1000
for test in tests:
with pytest.raises(TypeError):
VideoSrc(port=port, pattern=test)
def test_normal(self):
tests = [1, 0, 19, 10]
port = 1000
for test in tests:
src = VideoSrc(port=port, pattern=test)
assert src.pattern == str(test)
class TestVideoSrcTimeOverlay(object):
def test_fail(self):
tests = ['', 1234, 'hi', [1, 2], {1: 2}, None, 0, []]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, timeoverlay=test)
def test_normal(self):
tests = [True, False]
port = 1000
for test in tests:
src = VideoSrc(port=port, timeoverlay=test)
assert src.timeoverlay == test
class TestVideoSrcClockOverlay(object):
def test_fail(self):
tests = ['', 1234, 'hi', [1, 2], {1: 2}, None, 0, []]
port = 1000
for test in tests:
with pytest.raises(ValueError):
VideoSrc(port=port, clockoverlay=test)
def test_normal(self):
tests = [True, False]
port = 1000
for test in tests:
src = VideoSrc(port=port, clockoverlay=test)
assert src.clockoverlay == test
class MockPipeline(object):
def play(self):
pass
def pause(self):
pass
def disable(self):
pass
class TestVideoSrcPlay(object):
def test_run(self):
src = VideoSrc(port=3000)
src.pipeline = MockPipeline()
src.run()
def test_pause(self):
src = VideoSrc(port=3000)
src.pipeline = MockPipeline()
src.pause()
def test_end(self):
src = VideoSrc(port=3000)
src.pipeline = MockPipeline()
src.end()
class TestPreviewPort(object):
def test_blank(self):
tests = ['', None, [], {}]
for test in tests:
with pytest.raises(ValueError):
Preview(port=test)
def test_range(self):
tests = [-100, 1e7, 65536]
for test in tests:
with pytest.raises(RangeError):
Preview(port=test)
def test_invalid(self):
tests = [[1, 2, 3, 4], {1: 2, 2: 3}, '1e10']
for test in tests:
with pytest.raises(TypeError):
Preview(port=test)
def test_normal(self):
tests = [1, 65535, 1000]
for test in tests:
src = Preview(port=test)
assert src.preview_port == test
class TestPreviewPlay(object):
def test_run(self):
src = Preview(port=3001)
src.pipeline = MockPipeline()
src.run()
def test_pause(self):
src = Preview(port=3001)
src.pipeline = MockPipeline()
src.pause()
def test_end(self):
src = Preview(port=3001)
src.pipeline = MockPipeline()
src.end()
class TestBasePipeline(object):
def test_play(self, monkeypatch):
monkeypatch.setattr(Gst.Pipeline, '__init__', Mock())
pipeline = BasePipeline()
pipeline.set_state = Mock()
pipeline.play()
def test_pause(self, monkeypatch):
monkeypatch.setattr(Gst.Pipeline, '__init__', Mock())
pipeline = BasePipeline()
pipeline.set_state = Mock()
pipeline.pause()
def test_disable(self, monkeypatch):
monkeypatch.setattr(Gst.Pipeline, '__init__', Mock())
pipeline = BasePipeline()
pipeline.set_state = Mock()
pipeline.disable()
class TestVideoPipeline(object):
def test_permuate_time_clock_1(self):
VideoPipeline(port=3000, pattern=10, timeoverlay=False, clockoverlay=False)
def test_permuate_time_clock_2(self):
VideoPipeline(port=3000, pattern=10, timeoverlay=False, clockoverlay=True)
def test_permuate_time_clock_3(self):
VideoPipeline(port=3000, pattern=10, timeoverlay=True, clockoverlay=False)
def test_permuate_time_clock_4(self):
VideoPipeline(port=3000, pattern=10, timeoverlay=True, clockoverlay=True)