Skip to content

Commit

Permalink
Enable tests for events
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k committed Aug 24, 2019
1 parent 91b6039 commit 4ea2b50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions tests/aio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homekit.model.services import LightBulbService
from homekit.model import mixin as model_mixin
from homekit.aio.controller import Controller
from homekit.aio.controller.ip import IpPairing


@pytest.fixture
Expand Down Expand Up @@ -131,18 +132,17 @@ def pairing(controller_and_paired_accessory):


@pytest.fixture
def pairings(controller_and_paired_accessory):
def pairings(request, event_loop, controller_and_paired_accessory):
""" Returns a pairing of pairngs. """
left = controller_and_paired_accessory.get_pairings()['alias']

right = Controller()
right.pairings = controller_and_paired_accessory.pairings
right = IpPairing(left.pairing_data)

# This syntax is awkward. We can't use the syntax proposed by the pytest-asyncio
# docs because we have to support python 3.5
def cleanup():
async def async_cleanup():
await right.shutdown()
await right.close()
event_loop.run_until_complete(async_cleanup())
request.addfinalizer(cleanup)

Expand Down
31 changes: 13 additions & 18 deletions tests/aio/test_ip_pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ async def test_subscribe(pairing):

assert pairing.subscriptions == set(((1, 10), ))

# FIXME: Uncomment when accessory server supports events

"""
characteristics = await pairing.get_characteristics([
(1, 10),
], include_events=True)
Expand All @@ -101,17 +98,13 @@ async def test_subscribe(pairing):
'value': False,
}
}
"""


async def test_unsubscribe(pairing):
await pairing.subscribe([(1, 10)])

assert pairing.subscriptions == set(((1, 10), ))

# FIXME: Uncomment when accessory server supports events

"""
characteristics = await pairing.get_characteristics([
(1, 10),
], include_events=True)
Expand All @@ -122,15 +115,11 @@ async def test_unsubscribe(pairing):
'value': False,
}
}
"""

await pairing.unsubscribe([(1, 10)])

assert pairing.subscriptions == set()

# FIXME: Uncomment when accessory server supports events

"""
characteristics = await pairing.get_characteristics([
(1, 10),
], include_events=True)
Expand All @@ -141,7 +130,7 @@ async def test_unsubscribe(pairing):
'value': False,
}
}
"""


async def test_dispatcher_connect(pairing):
assert pairing.listeners == set()
Expand All @@ -154,8 +143,7 @@ async def test_dispatcher_connect(pairing):
assert pairing.listeners == set()


@pytest.mark.skip
async def test_subscribing(pairings):
async def test_receiving_events(pairings):
"""
Test that can receive events when change happens in another session.
Expand All @@ -167,10 +155,17 @@ async def test_subscribing(pairings):
"""
left, right = pairings

event_value = None
ev = asyncio.Event()

def handler(data):
print(data)
nonlocal event_value
event_value = data
ev.set()

# Set where to send events
right.dispatcher_connect(ev.set)
right.dispatcher_connect(handler)

# Set what events to get
await right.subscribe([(1, 10)])
Expand All @@ -179,11 +174,11 @@ async def test_subscribing(pairings):
await left.put_characteristics([(1, 10, True)])

# Wait for event to be received for up to 5s
event = await asyncio.wait_for(ev.wait(), 5)
await asyncio.wait_for(ev.wait(), 5)

assert event == {
assert event_value == {
(1, 10): {
'value': 10,
'value': True,
}
}

Expand Down

0 comments on commit 4ea2b50

Please sign in to comment.