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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions probert/tests/rtnetlink/test_addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

class MyMockAddr(WithGetAttrMixin, MockAddress):
"""Subclass of pyroute2's MockAddr that makes it behave like a nlmsg"""
# MockAddress in pyroute2 0.9 has default values for index and address but
# the version in pyroute2 0.7.11 (noble) does not.
def __init__(self, index=0, address=None, *args, **kwargs) -> None:
super().__init__(index, address, *args, **kwargs)


class TestAddrBuildEventData(unittest.TestCase):
Expand Down
4 changes: 4 additions & 0 deletions probert/tests/rtnetlink/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

class MyMockLink(WithGetAttrMixin, MockLink):
"""Subclass of pyroute2's MockLink that makes it behave like a nlmsg"""
# MockLink in pyroute2 0.9 has default values for index and ifname but
# the version in pyroute2 0.7.11 (noble) does not.
def __init__(self, index=0, ifname="", *args, **kwargs) -> None:
super().__init__(index, ifname, *args, **kwargs)


class TestLinkBuildEventData(unittest.TestCase):
Expand Down
13 changes: 11 additions & 2 deletions probert/tests/rtnetlink/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import importlib.metadata
import socket
import unittest
from unittest import mock
Expand Down Expand Up @@ -201,8 +202,16 @@ def test_data_ready(self):
m_handle.mock_calls)

def test_fileno(self):
# We need to patch the class, not the instance for some reason.
with mock.patch.object(IPRoute, "fileno", return_value=42):
version_str = importlib.metadata.version("pyroute2")
pyroute2_version = tuple(int(x) for x in version_str.split("."))

if pyroute2_version < (0, 9):
target = self.listener.ipr
else:
# We need to patch the class, not the instance for some reason.
target = IPRoute

with mock.patch.object(target, "fileno", return_value=42):
self.assertEqual(42, self.listener.fileno())

def test_set_link_flags(self):
Expand Down
7 changes: 5 additions & 2 deletions probert/tests/rtnetlink/test_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
class MyMockRoute(WithGetAttrMixin, MockRoute):
"""Subclass of pyroute2's MockRoute that makes it behave like a nlmsg...
and works around a bug"""
def __init__(self, *args, **kwargs):
# MockRoute in pyroute2 0.9 has default values for dst and oif but the
# version in pyroute2 0.7.11 (noble) does not.
def __init__(self, dst=None, oif=0, *args, **kwargs) -> None:
# Workaround ambiguity with route type.
# See https://github.com/svinota/pyroute2/pull/1409
if "type" in kwargs:
Expand All @@ -34,7 +36,8 @@ def __init__(self, *args, **kwargs):
kwargs["type"] = kwargs["route_type"]
else:
kwargs["type"] = rtypes["RTN_UNICAST"]
super().__init__(*args, **kwargs)

super().__init__(dst, oif, *args, **kwargs)


class TestGetIfindex(unittest.TestCase):
Expand Down