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

chore: rework the remaining echoes flagged by the seventh independent audit by bdraco · Pull Request #1890 · 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) .rst  (1) All 2 file types 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
6 changes: 3 additions & 3 deletions README.rst
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 @@ -20,9 +20,9 @@ python-zeroconf

`Documentation <https://python-zeroconf.readthedocs.io/en/latest/>`_.

This is fork of pyzeroconf, Multicast DNS Service Discovery for Python,
originally by Paul Scott-Murphy (https://github.com/paulsm/pyzeroconf),
modified by William McBrine (https://github.com/wmcbrine/pyzeroconf).
This project is a fork of pyzeroconf, originally by Paul Scott-Murphy
(https://github.com/paulsm/pyzeroconf), modified by William McBrine
(https://github.com/wmcbrine/pyzeroconf).

Compatible with:

Expand Down
2 changes: 1 addition & 1 deletion src/zeroconf/_handlers/record_manager.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 @@ -27,7 +27,7 @@


class RecordManager:
"""Process records into the cache and notify listeners."""
"""Apply incoming records to the cache and deliver the updates to listeners."""

__slots__ = ("cache", "listeners", "zc")

Expand Down
68 changes: 22 additions & 46 deletions tests/test_core.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 @@ -57,32 +57,23 @@ async def make_query():
asyncio.run_coroutine_threadsafe(make_query(), zc.loop).result()


@pytest.mark.parametrize("unicast", [False, True])
@pytest.mark.parametrize("interfaces", [r.InterfaceChoice.All, r.InterfaceChoice.Default])
def test_open_and_close_cleanly(interfaces):
r.Zeroconf(interfaces=interfaces).close()
def test_open_and_close_cleanly(interfaces: r.InterfaceChoice, unicast: bool) -> None:
r.Zeroconf(interfaces=interfaces, unicast=unicast).close()


def test_launch_and_close_context_manager():
with r.Zeroconf(interfaces=r.InterfaceChoice.All) as rv:
assert rv.done is False
assert rv.done is True

with r.Zeroconf(interfaces=r.InterfaceChoice.Default) as rv: # type: ignore[unreachable]
assert rv.done is False
assert rv.done is True


def test_launch_and_close_unicast():
rv = r.Zeroconf(interfaces=r.InterfaceChoice.All, unicast=True)
rv.close()
rv = r.Zeroconf(interfaces=r.InterfaceChoice.Default, unicast=True)
rv.close()
@pytest.mark.parametrize("interfaces", [r.InterfaceChoice.All, r.InterfaceChoice.Default])
def test_context_manager_marks_done(interfaces: r.InterfaceChoice) -> None:
with r.Zeroconf(interfaces=interfaces) as zc:
assert zc.done is False
assert zc.done is True


def test_close_multiple_times():
rv = r.Zeroconf(interfaces=r.InterfaceChoice.Default)
rv.close()
rv.close()
zc = r.Zeroconf(interfaces=r.InterfaceChoice.Default)
zc.close()
zc.close()


def test_close_releases_owned_event_loop():
Expand All @@ -93,11 +84,11 @@ def test_close_releases_owned_event_loop():
Zeroconf construct/close cycle and the process eventually exhausts
its FD limit.
"""
rv = r.Zeroconf(interfaces=["127.0.0.1"])
loop = rv.loop
zc = r.Zeroconf(interfaces=["127.0.0.1"])
loop = zc.loop
assert loop is not None
assert loop.is_running()
rv.close()
zc.close()
assert loop.is_closed()


Expand All @@ -123,38 +114,23 @@ def _fd_count() -> int:

@pytest.mark.skipif(not has_working_ipv6(), reason="Requires IPv6")
@pytest.mark.skipif(os.environ.get("SKIP_IPV6"), reason="IPv6 tests disabled")
def test_launch_and_close_v4_v6():
rv = r.Zeroconf(interfaces=r.InterfaceChoice.All, ip_version=r.IPVersion.All)
rv.close()
with warnings.catch_warnings(record=True) as warned:
rv = r.Zeroconf(interfaces=r.InterfaceChoice.Default, ip_version=r.IPVersion.All)
rv.close()
first_warning = warned[0]
assert "IPv6 multicast requests can't be sent using default interface" in str(first_warning.message)


@pytest.mark.skipif(not has_working_ipv6(), reason="Requires IPv6")
@pytest.mark.skipif(os.environ.get("SKIP_IPV6"), reason="IPv6 tests disabled")
def test_launch_and_close_v6_only():
rv = r.Zeroconf(interfaces=r.InterfaceChoice.All, ip_version=r.IPVersion.V6Only)
rv.close()
@pytest.mark.parametrize("ip_version", [r.IPVersion.All, r.IPVersion.V6Only])
def test_default_interface_warns_when_ipv6_requested(ip_version: r.IPVersion) -> None:
r.Zeroconf(interfaces=r.InterfaceChoice.All, ip_version=ip_version).close()
with warnings.catch_warnings(record=True) as warned:
rv = r.Zeroconf(interfaces=r.InterfaceChoice.Default, ip_version=r.IPVersion.V6Only)
rv.close()
first_warning = warned[0]
assert "IPv6 multicast requests can't be sent using default interface" in str(first_warning.message)
r.Zeroconf(interfaces=r.InterfaceChoice.Default, ip_version=ip_version).close()
assert "IPv6 multicast requests can't be sent using default interface" in str(warned[0].message)


@pytest.mark.skipif(sys.platform == "darwin", reason="apple_p2p failure path not testable on mac")
def test_launch_and_close_apple_p2p_not_mac():
def test_apple_p2p_rejected_off_mac():
with pytest.raises(RuntimeError):
r.Zeroconf(apple_p2p=True)


@pytest.mark.skipif(sys.platform != "darwin", reason="apple_p2p happy path only testable on mac")
def test_launch_and_close_apple_p2p_on_mac():
rv = r.Zeroconf(apple_p2p=True)
rv.close()
def test_apple_p2p_binds_on_mac():
r.Zeroconf(apple_p2p=True).close()


def test_use_asyncio_false_forces_thread_when_loop_running():
Expand Down
Loading

Back | FazBrowse Home | New Git URL