@@ -57,32 +57,23 @@ async def make_query():
5757 asyncio .run_coroutine_threadsafe (make_query (), zc .loop ).result ()
5858
5959
60+ @pytest .mark .parametrize ("unicast" , [False , True ])
6061@pytest .mark .parametrize ("interfaces" , [r .InterfaceChoice .All , r .InterfaceChoice .Default ])
61- def test_open_and_close_cleanly (interfaces ) :
62- r .Zeroconf (interfaces = interfaces ).close ()
62+ def test_open_and_close_cleanly (interfaces : r . InterfaceChoice , unicast : bool ) -> None :
63+ r .Zeroconf (interfaces = interfaces , unicast = unicast ).close ()
6364
6465
65- def test_launch_and_close_context_manager ():
66- with r .Zeroconf (interfaces = r .InterfaceChoice .All ) as rv :
67- assert rv .done is False
68- assert rv .done is True
69-
70- with r .Zeroconf (interfaces = r .InterfaceChoice .Default ) as rv : # type: ignore[unreachable]
71- assert rv .done is False
72- assert rv .done is True
73-
74-
75- def test_launch_and_close_unicast ():
76- rv = r .Zeroconf (interfaces = r .InterfaceChoice .All , unicast = True )
77- rv .close ()
78- rv = r .Zeroconf (interfaces = r .InterfaceChoice .Default , unicast = True )
79- rv .close ()
66+ @pytest .mark .parametrize ("interfaces" , [r .InterfaceChoice .All , r .InterfaceChoice .Default ])
67+ def test_context_manager_marks_done (interfaces : r .InterfaceChoice ) -> None :
68+ with r .Zeroconf (interfaces = interfaces ) as zc :
69+ assert zc .done is False
70+ assert zc .done is True
8071
8172
8273def test_close_multiple_times ():
83- rv = r .Zeroconf (interfaces = r .InterfaceChoice .Default )
84- rv .close ()
85- rv .close ()
74+ zc = r .Zeroconf (interfaces = r .InterfaceChoice .Default )
75+ zc .close ()
76+ zc .close ()
8677
8778
8879def test_close_releases_owned_event_loop ():
@@ -93,11 +84,11 @@ def test_close_releases_owned_event_loop():
9384 Zeroconf construct/close cycle and the process eventually exhausts
9485 its FD limit.
9586 """
96- rv = r .Zeroconf (interfaces = ["127.0.0.1" ])
97- loop = rv .loop
87+ zc = r .Zeroconf (interfaces = ["127.0.0.1" ])
88+ loop = zc .loop
9889 assert loop is not None
9990 assert loop .is_running ()
100- rv .close ()
91+ zc .close ()
10192 assert loop .is_closed ()
10293
10394
@@ -123,38 +114,23 @@ def _fd_count() -> int:
123114
124115@pytest .mark .skipif (not has_working_ipv6 (), reason = "Requires IPv6" )
125116@pytest .mark .skipif (os .environ .get ("SKIP_IPV6" ), reason = "IPv6 tests disabled" )
126- def test_launch_and_close_v4_v6 ():
127- rv = r .Zeroconf (interfaces = r .InterfaceChoice .All , ip_version = r .IPVersion .All )
128- rv .close ()
129- with warnings .catch_warnings (record = True ) as warned :
130- rv = r .Zeroconf (interfaces = r .InterfaceChoice .Default , ip_version = r .IPVersion .All )
131- rv .close ()
132- first_warning = warned [0 ]
133- assert "IPv6 multicast requests can't be sent using default interface" in str (first_warning .message )
134-
135-
136- @pytest .mark .skipif (not has_working_ipv6 (), reason = "Requires IPv6" )
137- @pytest .mark .skipif (os .environ .get ("SKIP_IPV6" ), reason = "IPv6 tests disabled" )
138- def test_launch_and_close_v6_only ():
139- rv = r .Zeroconf (interfaces = r .InterfaceChoice .All , ip_version = r .IPVersion .V6Only )
140- rv .close ()
117+ @pytest .mark .parametrize ("ip_version" , [r .IPVersion .All , r .IPVersion .V6Only ])
118+ def test_default_interface_warns_when_ipv6_requested (ip_version : r .IPVersion ) -> None :
119+ r .Zeroconf (interfaces = r .InterfaceChoice .All , ip_version = ip_version ).close ()
141120 with warnings .catch_warnings (record = True ) as warned :
142- rv = r .Zeroconf (interfaces = r .InterfaceChoice .Default , ip_version = r .IPVersion .V6Only )
143- rv .close ()
144- first_warning = warned [0 ]
145- assert "IPv6 multicast requests can't be sent using default interface" in str (first_warning .message )
121+ r .Zeroconf (interfaces = r .InterfaceChoice .Default , ip_version = ip_version ).close ()
122+ assert "IPv6 multicast requests can't be sent using default interface" in str (warned [0 ].message )
146123
147124
148125@pytest .mark .skipif (sys .platform == "darwin" , reason = "apple_p2p failure path not testable on mac" )
149- def test_launch_and_close_apple_p2p_not_mac ():
126+ def test_apple_p2p_rejected_off_mac ():
150127 with pytest .raises (RuntimeError ):
151128 r .Zeroconf (apple_p2p = True )
152129
153130
154131@pytest .mark .skipif (sys .platform != "darwin" , reason = "apple_p2p happy path only testable on mac" )
155- def test_launch_and_close_apple_p2p_on_mac ():
156- rv = r .Zeroconf (apple_p2p = True )
157- rv .close ()
132+ def test_apple_p2p_binds_on_mac ():
133+ r .Zeroconf (apple_p2p = True ).close ()
158134
159135
160136def test_use_asyncio_false_forces_thread_when_loop_running ():
0 commit comments