Skip to content

Commit

Permalink
Added unittests for bus
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 21, 2013
1 parent a3d31f1 commit 7c6f1ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
12 changes: 6 additions & 6 deletions python-api/gstswitch/connection.py
Expand Up @@ -52,7 +52,7 @@ def address(self, address):
http://dbus.freedesktop.org/doc/dbus-specification.html#addresses
"""
if not address:
raise ValueError("Address '{0} cannot be blank'")
raise ValueError("Address '{0}' cannot be blank")
else:
try:
a = str(address)
Expand All @@ -62,7 +62,7 @@ def address(self, address):
raise ValueError("""Address must follow specifications mentioned at
http://dbus.freedesktop.org/doc/dbus-specification.html#addresses""")
except TypeError:
raise TypeError("Address should be a string or buffer, not '{0}'".format(type(address)))
raise TypeError("Address cannot be '{0}'".format(type(address)))

@bus_name.setter
def bus_name(self, bus_name):
Expand All @@ -76,7 +76,7 @@ def bus_name(self, bus_name):
a = str(bus_name)
self._bus_name = a
except TypeError:
raise TypeError("Bus Name should be a string or buffer, not '{0}'".format(type(bus_name)))
raise TypeError("Bus Name cannot be '{0}'".format(type(bus_name)))

@object_path.setter
def object_path(self, object_path):
Expand All @@ -94,8 +94,8 @@ def object_path(self, object_path):
raise ValueError("""object_path must follow specifications mentioned at
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path""")
except TypeError:
raise TypeError("object_path should be a string or buffer, not '{0}'".format(type(object_path)))
raise TypeError("object_path cannot be '{0}'".format(type(object_path)))

@default_interface.setter
def default_interface(self, default_interface):
"""Set the default_interface
Expand All @@ -112,7 +112,7 @@ def default_interface(self, default_interface):
raise ValueError("""default_interface must follow specifications mentioned at
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface""")
except TypeError:
raise TypeError("default_interface should be a string or buffer, not '{0}'".format(type(default_interface)))
raise TypeError("default_interface cannot be '{0}'".format(type(default_interface)))

def connect_dbus(self):
"""Make a new connection using the parameters belonging to the class
Expand Down
2 changes: 1 addition & 1 deletion python-api/gstswitch/server.py
Expand Up @@ -112,7 +112,7 @@ def record_file(self, record_file):
else:
raise ValueError("Record File: '{0}' cannot have forward slashes".format(rec))
except TypeError:
raise TypeError("Record File should be a string or buffer, not '{0}'".format(type(record_file)))
raise TypeError("Record File cannot be '{0}'".format(type(record_file)))

def run(self, gst_option=''):
"""Launch the server process
Expand Down
23 changes: 18 additions & 5 deletions python-api/gstswitch/test_connection.py
Expand Up @@ -16,9 +16,22 @@ def test_address_colon(self):
with pytest.raises(ValueError):
Connection(address=address)

def test_address_unknown(self):
address = [1, 2, 3]
with pytest.raises(ValueError):
Connection(address=address)
def test_address_normal(self):
address = ['unix:abstract=gstswitch', 'unix:temp=/tmp/abcd/xyz']
for x in address:
conn = Connection(address=x)
assert conn.address == x


class TestBusName(object):

def test_normal(self):
names = ['', 'abcd', 12345]
for bus in names:
conn = Connection(bus_name=bus)
assert conn.bus_name == str(bus)

class Test
def test_normal_none(self):
name = None
conn = Connection(bus_name=name)
assert conn.bus_name == name
1 change: 0 additions & 1 deletion python-api/gstswitch/test_server.py
Expand Up @@ -4,7 +4,6 @@


class TestPath(object):

# Path Tests
def test_invalid_path(self):
path = '/usr/'
Expand Down

0 comments on commit 7c6f1ea

Please sign in to comment.