FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: add an add_question_batch helper for the packet count tests by bdraco · Pull Request #1882 · python-zeroconf/python-zeroconf · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 16 additions & 0 deletions tests/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def suppresses(self, question: DNSQuestion, now: float, known_answers: set[DNSRe
return False


def add_question_batch(
out: DNSOutgoing, count: int, *, stem: str = "specimen", type_: int = const._TYPE_SRV
) -> list[DNSQuestion]:
"""Add count questions named <stem><i>.local. and return them.

Packet count assertions in the protocol tests depend on the encoded
name length, so the default stem must stay eight characters.
"""
questions = []
for i in range(count):
question = DNSQuestion(f"{stem}{i}.local.", type_, const._CLASS_IN)
out.add_question(question)
questions.append(question)
return questions


def make_service_info(
type_: str,
name: str,
Expand Down
14 changes: 4 additions & 10 deletions tests/test_protocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from zeroconf._logger import _MAX_SEEN_LOGS
from zeroconf._protocol import incoming as _incoming_module

from . import has_working_ipv6
from . import add_question_batch, has_working_ipv6

log = logging.getLogger("zeroconf")
original_logging_level = logging.NOTSET
Expand Down Expand Up @@ -282,11 +282,7 @@ def test_dns_hinfo():
def test_many_questions():
"""Test many questions get separated into multiple packets."""
generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
questions = []
for i in range(100):
question = r.DNSQuestion(f"specimen{i}.local.", const._TYPE_SRV, const._CLASS_IN)
generated.add_question(question)
questions.append(question)
add_question_batch(generated, 100)
assert len(generated.questions) == 100

packets = generated.packets()
Expand Down Expand Up @@ -445,11 +441,9 @@ def test_questions_do_not_end_up_every_packet():
"""

generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
for i in range(35):
question = r.DNSQuestion(f"specimen{i}.local.", const._TYPE_SRV, const._CLASS_IN)
generated.add_question(question)
for i, question in enumerate(add_question_batch(generated, 35)):
answer = r.DNSService(
f"specimen{i}.local.",
question.name,
const._TYPE_SRV,
const._CLASS_IN | const._CLASS_UNIQUE,
const._DNS_HOST_TTL,
Expand Down
Loading

Back | FazBrowse Home | New Git URL