|
8 | 8 | import socket |
9 | 9 | import threading |
10 | 10 | import unittest |
11 | | -from collections.abc import Iterable |
12 | 11 | from ipaddress import ip_address |
13 | 12 | from threading import Event |
14 | 13 | from unittest.mock import patch |
|
23 | 22 | from zeroconf._utils.net import IPVersion |
24 | 23 | from zeroconf.asyncio import AsyncZeroconf |
25 | 24 |
|
26 | | -from .. import QUICK_REQUEST_TIMEOUT_MS, _inject_response, has_working_ipv6 |
| 25 | +from .. import QUICK_REQUEST_TIMEOUT_MS, _inject_response, has_working_ipv6, mock_incoming_msg |
27 | 26 |
|
28 | 27 | log = logging.getLogger("zeroconf") |
29 | 28 | original_logging_level = logging.NOTSET |
@@ -279,14 +278,6 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()): |
279 | 278 | # patch the zeroconf send |
280 | 279 | with patch.object(zc, "async_send", send): |
281 | 280 |
|
282 | | - def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming: |
283 | | - generated = r.DNSOutgoing(const._FLAGS_QR_RESPONSE) |
284 | | - |
285 | | - for record in records: |
286 | | - generated.add_answer_at_time(record, 0) |
287 | | - |
288 | | - return r.DNSIncoming(generated.packets()[0]) |
289 | | - |
290 | 281 | def get_service_info_helper(zc, type, name): |
291 | 282 | nonlocal service_info |
292 | 283 | service_info = zc.get_service_info(type, name) |
@@ -422,14 +413,6 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()): |
422 | 413 | # patch the zeroconf send |
423 | 414 | with patch.object(zc, "async_send", send): |
424 | 415 |
|
425 | | - def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming: |
426 | | - generated = r.DNSOutgoing(const._FLAGS_QR_RESPONSE) |
427 | | - |
428 | | - for record in records: |
429 | | - generated.add_answer_at_time(record, 0) |
430 | | - |
431 | | - return r.DNSIncoming(generated.packets()[0]) |
432 | | - |
433 | 416 | def get_service_info_helper(zc, type, name, timeout): |
434 | 417 | nonlocal service_info |
435 | 418 | service_info = zc.get_service_info(type, name, timeout) |
@@ -552,12 +535,6 @@ def test_get_info_single(self): |
552 | 535 | ), |
553 | 536 | ] |
554 | 537 |
|
555 | | - def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming: |
556 | | - generated = r.DNSOutgoing(const._FLAGS_QR_RESPONSE) |
557 | | - for record in records: |
558 | | - generated.add_answer_at_time(record, 0) |
559 | | - return r.DNSIncoming(generated.packets()[0]) |
560 | | - |
561 | 538 | sent_queries: list[r.DNSOutgoing] = [] |
562 | 539 |
|
563 | 540 | def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()): |
|
0 commit comments