test(vpcs): mock read_channel in the strip-ansi test

The send_command read loop polls read_channel (netmiko decorates it
with a session-lock wrapper that only __init__ can satisfy), so the
old read_until_pattern mock died with AttributeError on instances
built via __new__.
This commit is contained in:
yueguobin committed 2026-11-01 23:09:38 +08:00
1 parent b184ea4c70
commit abb59b3d06
1 file changed
+4 -2
@@ -429,10 +429,12 @@ IP/MASK : 192.168.1.20/24"""
instance = self.VPCSTelnet.__new__(self.VPCSTelnet)
# Mock necessary attributes
# Mock necessary attributes. The read loop polls read_channel
# (netmiko's decorated method needs the session lock, which only
# __init__ creates), not read_until_pattern.
instance.remote_conn = MagicMock()
instance.remote_conn.write = MagicMock()
instance.read_until_pattern = MagicMock(return_value="\x1b[1mNAME\x1b[0m : PC2\nPC2>")
instance.read_channel = MagicMock(return_value="\x1b[1mNAME\x1b[0m : PC2\nPC2>")
# Mock _strip_ansi_codes to verify it's called
instance._strip_ansi_codes = Mock(return_value="NAME : PC2\nPC2>")