Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions pydbus/tests/context.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
from pydbus import SessionBus, connect
import os

DBUS_SESSION_BUS_ADDRESS = os.getenv("DBUS_SESSION_BUS_ADDRESS")
import pytest

with connect(DBUS_SESSION_BUS_ADDRESS) as bus:
bus.dbus

del bus._dbus
try:
bus.dbus
assert(False)
except RuntimeError:
pass
def test_remove_dbus():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called test_bus_closure - as it tests if connected buses are automatically closed when going outside of the with statement.

DBUS_SESSION_BUS_ADDRESS = os.getenv("DBUS_SESSION_BUS_ADDRESS")

with connect(DBUS_SESSION_BUS_ADDRESS) as bus:
bus.dbus

with SessionBus() as bus:
pass
del bus._dbus
with pytest.raises(RuntimeError):
bus.dbus

# SessionBus() and SystemBus() are not closed automatically, so this should work:
bus.dbus

with bus.request_name("net.lew21.Test"):
pass
def test_use_exited_bus():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called test_standard_bus_object_preservation, or something like that, in line with the comment "SessionBus() and SystemBus() are not closed automatically, so this should work"

"""Test using a bus instance after its context manager."""
with SessionBus() as bus:
pass

# SessionBus() and SystemBus() are not closed automatically, so this should work:
bus.dbus

with bus.request_name("net.lew21.Test"):
pass
with bus.request_name("net.lew21.Test"):
pass

with bus.request_name("net.lew21.Test"):
try:
bus.request_name("net.lew21.Test")
assert(False)
except RuntimeError:
with bus.request_name("net.lew21.Test"):
pass

with bus.watch_name("net.lew21.Test"):
pass
with bus.request_name("net.lew21.Test"):
with pytest.raises(RuntimeError):
bus.request_name("net.lew21.Test")

with bus.subscribe(sender="net.lew21.Test"):
pass
with bus.watch_name("net.lew21.Test"):
pass

with bus.subscribe(sender="net.lew21.Test"):
pass
18 changes: 6 additions & 12 deletions pydbus/tests/identifier.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from __future__ import print_function
import pytest

from pydbus.identifier import filter_identifier
import sys

tests = [
@pytest.mark.parametrize("input, output", [
("abc", "abc"),
("a_bC", "a_bC"),
("a-b_c", "a_b_c"),
("a@bc", "abc"),
("!@#$%^&*", ""),
]

ret = 0
for input, output in tests:
if not filter_identifier(input) == output:
print("ERROR: filter(" + input + ") returned: " + filter_identifier(input), file=sys.stderr)
ret = 1

sys.exit(ret)
])
def test_filter_identifier(input, output):
assert filter_identifier(input) == output
2 changes: 1 addition & 1 deletion tests/py2.7-ubuntu-14.04.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN apt-get update

RUN apt-get install -y dbus python-gi python-pip psmisc python-dev
RUN python2 --version
RUN pip2 install greenlet
RUN pip2 install greenlet pytest

ADD . /root/
RUN cd /root && python2 setup.py install
Expand Down
2 changes: 1 addition & 1 deletion tests/py2.7-ubuntu-16.04.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN apt-get update

RUN apt-get install -y dbus python-gi python-pip psmisc
RUN python2 --version
RUN pip2 install greenlet
RUN pip2 install greenlet pytest

ADD . /root/
RUN cd /root && python2 setup.py install
Expand Down
2 changes: 1 addition & 1 deletion tests/py3.4-ubuntu-14.04.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN apt-get update

RUN apt-get install -y dbus python3-gi python3-pip psmisc python3-dev
RUN python3 --version
RUN pip3 install greenlet
RUN pip3 install greenlet pytest

ADD . /root/
RUN cd /root && python3 setup.py install
Expand Down
2 changes: 1 addition & 1 deletion tests/py3.5-ubuntu-16.04.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN apt-get update

RUN apt-get install -y dbus python3-gi python3-pip psmisc
RUN python3 --version
RUN pip3 install greenlet
RUN pip3 install greenlet pytest

ADD . /root/
RUN cd /root && python3 setup.py install
Expand Down
5 changes: 3 additions & 2 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
set -e

cd "$(dirname "$(dirname "$0")")"

ADDRESS_FILE=$(mktemp /tmp/pydbustest.XXXXXXXXX)
PID_FILE=$(mktemp /tmp/pydbustest.XXXXXXXXX)

Expand All @@ -15,8 +17,7 @@ rm "$ADDRESS_FILE" "$PID_FILE"

PYTHON=${1:-python}

"$PYTHON" -m pydbus.tests.context
"$PYTHON" -m pydbus.tests.identifier
"$PYTHON" -m pytest -v pydbus/tests/identifier.py pydbus/tests/context.py
if [ "$2" != "dontpublish" ]
then
"$PYTHON" -m pydbus.tests.publish
Expand Down