Skip to content

Commit

Permalink
try to fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 23, 2025
1 parent c1415e9 commit 9143e06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,15 @@ def conn_to_ntuple(fd, fam, type_, laddr, raddr, status, status_map, pid=None):
def broadcast_addr(addr):
import ipaddress

if not addr.address or not addr.netmask:
return None
if addr.family == socket.AF_INET:
return str(
ipaddress.IPv4Network(
f"{addr.address}/{addr.netmask}", strict=False
).broadcast_address
)
elif addr.family == socket.AF_INET6:
if addr.family == socket.AF_INET6:
return str(
ipaddress.IPv6Network(
f"{addr.address}/{addr.netmask}", strict=False
Expand Down
9 changes: 5 additions & 4 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,11 @@ def test_net_if_addrs(self):
assert addr.broadcast is None

# check broadcast address
if addr.broadcast and addr.family in {
socket.AF_INET,
socket.AF_INET6,
}:
if (
addr.broadcast
and addr.netmask
and addr.family in {socket.AF_INET, socket.AF_INET6}
):
assert addr.broadcast == broadcast_addr(addr)

if BSD or MACOS or SUNOS:
Expand Down

0 comments on commit 9143e06

Please sign in to comment.