forked from timvideos/gst-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_server.py
139 lines (115 loc) · 4.41 KB
/
test_server.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
from server import Server
import pytest
from exception import *
import subprocess
class TestPath(object):
# Path Tests
def test_invalid_path(self):
path = '/usr/'
s = Server(path=path)
with pytest.raises(PathError):
s.run()
def test_invalid_path_none(self):
paths = [None, '', [], {}]
for path in paths:
with pytest.raises(ValueError):
Server(path=path)
class TestVideoPort(object):
# Video Port Tests
def test_invalid_video_port_null(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
video_ports = [None, '', [], {}]
for video_port in video_ports:
with pytest.raises(ValueError):
Server(path=path, video_port=video_port)
def test_invalid_video_port_type(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
video_ports = [[1, 2, 3], {1: 2, 2: 3}]
for video_port in video_ports:
with pytest.raises(TypeError):
Server(path=path, video_port=video_port)
def test_invalid_video_port_range(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
video_ports = [-99, -1, 1e6]
for video_port in video_ports:
with pytest.raises(ValueError):
Server(path=path, video_port=video_port)
class TestAudioPort(object):
# Audio Port Tests
def test_invalid_audio_port_null(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
audio_ports = [None, '', [], {}]
for audio_port in audio_ports:
with pytest.raises(ValueError):
Server(path=path, audio_port=audio_port)
def test_invalid_audio_port_type(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
audio_ports = [[1, 2, 3], {1: 2, 2: 3}]
for audio_port in audio_ports:
with pytest.raises(TypeError):
Server(path=path, audio_port=audio_port)
def test_invalid_audio_port_range(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
audio_ports = [-99, -1, 1e6]
for audio_port in audio_ports:
with pytest.raises(ValueError):
Server(path=path, audio_port=audio_port)
class TestControlPort(object):
# Control Port Tests
def test_invalid_control_port_null(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
control_ports = [None, '', [], {}]
for control_port in control_ports:
with pytest.raises(ValueError):
Server(path=path, control_port=control_port)
def test_invalid_control_port_type(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
control_ports = [[1, 2, 3], {1: 2, 2: 3}]
for control_port in control_ports:
with pytest.raises(TypeError):
Server(path=path, control_port=control_port)
def test_invalid_control_port_range(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
control_ports = [-99, -1, 1e6]
for control_port in control_ports:
with pytest.raises(ValueError):
Server(path=path, control_port=control_port)
class TestProcess(object):
# OS Errors
def test_terminate_fail(self):
class fake_proc(object):
def __init__(self):
pass
def terminate(self):
raise OSError
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
s.proc = fake_proc()
with pytest.raises(ServerProcessError):
s.terminate()
class TestNormal(object):
# Normal Functioning Tests
def test_normal_terminate(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
s.run()
assert s.proc is not None
s.terminate()
assert s.proc is None
def test_normal_kill(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
s.run()
assert s.proc is not None
s.kill()
assert s.proc is None
def test_terminate(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
with pytest.raises(ServerProcessError):
s.terminate()
def test_kill(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
with pytest.raises(ServerProcessError):
s.terminate()