Skip to content

Commit 72032d6

Browse files
authored
Move notify listener tests to test_core (#591)
1 parent fd70ac1 commit 72032d6

2 files changed

Lines changed: 41 additions & 43 deletions

File tree

tests/test_core.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
# -*- coding: utf-8 -*-
33

44

5-
""" Unit tests for zeroconf.core """
5+
""" Unit tests for zeroconf._core """
66

77
import itertools
88
import logging
99
import os
10+
import pytest
1011
import socket
1112
import time
1213
import unittest
1314
import unittest.mock
1415
from typing import cast
1516

1617
import zeroconf as r
17-
from zeroconf import _core
18-
from zeroconf import const
18+
from zeroconf import _core, const, ServiceBrowser, Zeroconf
1919

2020
from . import has_working_ipv6, _inject_response
2121

@@ -234,3 +234,41 @@ def mock_split_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNS
234234

235235
finally:
236236
zeroconf.close()
237+
238+
239+
def test_notify_listeners():
240+
"""Test adding and removing notify listeners."""
241+
# instantiate a zeroconf instance
242+
zc = Zeroconf(interfaces=['127.0.0.1'])
243+
notify_called = 0
244+
245+
class TestNotifyListener(r.NotifyListener):
246+
def notify_all(self):
247+
nonlocal notify_called
248+
notify_called += 1
249+
250+
with pytest.raises(NotImplementedError):
251+
r.NotifyListener().notify_all()
252+
253+
notify_listener = TestNotifyListener()
254+
255+
zc.add_notify_listener(notify_listener)
256+
257+
def on_service_state_change(zeroconf, service_type, state_change, name):
258+
"""Dummy service callback."""
259+
260+
# start a browser
261+
browser = ServiceBrowser(zc, "_http._tcp.local.", [on_service_state_change])
262+
browser.cancel()
263+
264+
assert notify_called
265+
zc.remove_notify_listener(notify_listener)
266+
267+
notify_called = 0
268+
# start a browser
269+
browser = ServiceBrowser(zc, "_http._tcp.local.", [on_service_state_change])
270+
browser.cancel()
271+
272+
assert not notify_called
273+
274+
zc.close()

tests/test_init.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import unittest.mock
1212
from typing import Optional # noqa # used in type hints
1313

14-
import pytest
15-
1614
import zeroconf as r
1715
from zeroconf import ServiceBrowser, ServiceInfo, Zeroconf, const
1816

@@ -246,41 +244,3 @@ def generate_host(zc, host_name, type_):
246244
0,
247245
)
248246
zc.send(out)
249-
250-
251-
def test_notify_listeners():
252-
"""Test adding and removing notify listeners."""
253-
# instantiate a zeroconf instance
254-
zc = Zeroconf(interfaces=['127.0.0.1'])
255-
notify_called = 0
256-
257-
class TestNotifyListener(r.NotifyListener):
258-
def notify_all(self):
259-
nonlocal notify_called
260-
notify_called += 1
261-
262-
with pytest.raises(NotImplementedError):
263-
r.NotifyListener().notify_all()
264-
265-
notify_listener = TestNotifyListener()
266-
267-
zc.add_notify_listener(notify_listener)
268-
269-
def on_service_state_change(zeroconf, service_type, state_change, name):
270-
"""Dummy service callback."""
271-
272-
# start a browser
273-
browser = ServiceBrowser(zc, "_http._tcp.local.", [on_service_state_change])
274-
browser.cancel()
275-
276-
assert notify_called
277-
zc.remove_notify_listener(notify_listener)
278-
279-
notify_called = 0
280-
# start a browser
281-
browser = ServiceBrowser(zc, "_http._tcp.local.", [on_service_state_change])
282-
browser.cancel()
283-
284-
assert not notify_called
285-
286-
zc.close()

0 commit comments

Comments
 (0)