forked from timvideos/gst-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_controller.py
177 lines (130 loc) · 5.33 KB
/
test_controller.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
from controller import Controller
from exception import *
import pytest
from mock import Mock, patch
from connection import Connection
from gi.repository import GLib
class TestAddress(object):
def test_address_null(self):
address = ['', None, [], {}]
for x in address:
with pytest.raises(ValueError):
Controller(address=x)
def test_address_colon(self):
address = 'abcdefghijk'
with pytest.raises(ValueError):
Controller(address=address)
def test_address_normal(self):
address = ['unix:abstract=gstswitch', 'unix:temp=/tmp/abcd/xyz']
for x in address:
conn = Controller(address=x)
assert conn.address == x
class TestBusName(object):
def test_normal(self):
names = ['', 'abcd', 12345]
for bus in names:
conn = Controller(bus_name=bus)
assert conn.bus_name == str(bus)
def test_normal_none(self):
name = None
conn = Controller(bus_name=name)
assert conn.bus_name == name
class TestObjectPath(object):
def test_object_path_blank(self):
paths = [None, '', {}, []]
for object_path in paths:
with pytest.raises(ValueError):
Controller(object_path=object_path)
def test_object_path_slash(self):
object_path = 'a/////////'
with pytest.raises(ValueError):
Controller(object_path=object_path)
def test_object_path_normal(self):
object_path = "/info/duzy/gst/switch/SwitchController"
conn = Controller(object_path=object_path)
assert conn.object_path == object_path
class TestInterface(object):
def test_interface_none(self):
default_interface = [None, '', [], {}]
for x in default_interface:
with pytest.raises(ValueError):
Controller(default_interface=x)
def test_interface_dot(self):
default_interface = ['.', 'info.', 'info']
for x in default_interface:
with pytest.raises(ValueError):
Controller(default_interface=x)
def test_interface_normal(self):
default_interface = "info.duzy.gst.switch.SwitchControllerInterface"
conn = Controller(default_interface=default_interface)
assert default_interface == conn.default_interface
class TestEstablishConnection(object):
def test_normal(self, monkeypatch):
monkeypatch.setattr(Connection, 'connect_dbus', Mock())
controller = Controller(address='unix:abstract=abcd')
controller.establish_connection()
assert controller.connection is not None
class MockConnection(object):
def __init__(self, mode):
self.mode = mode
def get_compose_port(self):
if self.mode is False:
return GLib.Variant('(i)', (3001,))
else:
return (0,)
def get_encode_port(self):
if self.mode is False:
return GLib.Variant('(i)', (3002,))
else:
return (0,)
def get_audio_port(self):
if self.mode is False:
return GLib.Variant('(i)', (4000,))
else:
return (0,)
def get_preview_ports(self):
if self.mode is False:
return GLib.Variant('(s)', ('[(3002, 1, 7), (3003, 1, 8)]',))
else:
return (0,)
class TestGetComposePort(object):
def test_unpack(self):
controller = Controller(address='unix:abstract=abcdefghijk')
controller.connection = MockConnection(True)
with pytest.raises(ConnectionError):
controller.get_compose_port()
def test_normal_unpack(self):
controller = Controller(address='unix:abstract=abcdef')
controller.connection = MockConnection(False)
assert controller.get_compose_port() == 3001
class TestGetEncodePort(object):
def test_unpack(self):
controller = Controller(address='unix:abstract=abcdefghijk')
controller.connection = MockConnection(True)
with pytest.raises(ConnectionError):
controller.get_encode_port()
def test_normal_unpack(self):
controller = Controller(address='unix:abstract=abcdef')
controller.connection = MockConnection(False)
assert controller.get_encode_port() == 3002
class TestGetAudioPort(object):
def test_unpack(self):
controller = Controller(address='unix:abstract=abcdefghijk')
controller.connection = MockConnection(True)
with pytest.raises(ConnectionError):
controller.get_audio_port()
def test_normal_unpack(self):
controller = Controller(address='unix:abstract=abcdef')
controller.connection = MockConnection(False)
assert controller.get_audio_port() == 4000
class TestGetPreviewPorts(object):
def test_unpack(self):
controller = Controller(address='unix:abstract=abcdefghijk')
controller.connection = MockConnection(True)
with pytest.raises(ConnectionError):
controller.get_preview_ports()
def test_normal_unpack(self):
controller = Controller(address='unix:abstract=abcdef')
controller.connection = MockConnection(False)
controller._parse_preview_ports = Mock(return_value=[3001, 3002])
assert controller.get_preview_ports() == [3001, 3002]