forked from timvideos/gst-switch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,80 @@ def __init__( | |
self.object_path = object_path | ||
self.default_interface = default_interface | ||
|
||
@property | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
def address(self): | ||
return self._address | ||
|
||
@property | ||
def bus_name(self): | ||
if self._bus_name is None: | ||
return None | ||
return self._bus_name | ||
|
||
@property | ||
def object_path(self): | ||
return self._object_path | ||
|
||
@property | ||
def default_interface(self): | ||
return self._default_interface | ||
|
||
@address.setter | ||
def address(self, address): | ||
"""Set the Address | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#addresses | ||
""" | ||
if not address: | ||
raise ValueError("Address '{0}' cannot be blank") | ||
else: | ||
a = str(address) | ||
if a.find(':') > 0: | ||
self._address = a | ||
else: | ||
raise ValueError("""Address must follow specifications mentioned at | ||
This comment has been minimized.
Sorry, something went wrong.
mithro
Collaborator
|
||
http://dbus.freedesktop.org/doc/dbus-specification.html#addresses""") | ||
|
||
@bus_name.setter | ||
def bus_name(self, bus_name): | ||
"""Set the Bus Name | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus | ||
""" | ||
if bus_name is None: | ||
self._bus_name = None | ||
return | ||
a = str(bus_name) | ||
self._bus_name = a | ||
|
||
@object_path.setter | ||
def object_path(self, object_path): | ||
"""Set the object_path | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path | ||
""" | ||
if not object_path: | ||
raise ValueError("object_path '{0} cannot be blank'") | ||
else: | ||
a = str(object_path) | ||
if a[0] == '/': | ||
self._object_path = a | ||
else: | ||
raise ValueError("""object_path must follow specifications mentioned at | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path""") | ||
|
||
@default_interface.setter | ||
def default_interface(self, default_interface): | ||
"""Set the default_interface | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface | ||
""" | ||
if not default_interface: | ||
raise ValueError("default_interface '{0} cannot be blank'") | ||
else: | ||
a = str(default_interface) | ||
if a.count('.') > 1: | ||
self._default_interface = a | ||
else: | ||
raise ValueError("""default_interface must follow specifications mentioned at | ||
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface""") | ||
|
||
def establish_connection(self): | ||
"""Establishes a fresh connection to the dbus | ||
Connection stored as self.connection | ||
|
@@ -30,10 +104,10 @@ def establish_connection(self): | |
:returns: None | ||
""" | ||
self.connection = Connection( | ||
self.address, | ||
self.bus_name, | ||
self.object_path, | ||
self.default_interface) | ||
address=self.address, | ||
bus_name=self.bus_name, | ||
object_path=self.object_path, | ||
default_interface=self.default_interface) | ||
|
||
self.connection.connect_dbus() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from controller import Controller | ||
from exception import * | ||
import pytest | ||
from mock import Mock, patch | ||
|
||
|
||
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 |
Group the @Property, @xxx.setter together.