blob: 4dc1fb86e33a940f9138a355ba452a3aed685ffd [file] [log] [blame]
# Copyright (c) 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Set of Mocks and Stubs for test SCPI & RF Switch.
Implement a set of Mocks and Stubs which will be used in
unittest for SCPI and RF Switch.
import socket
from autotest_lib.client.common_lib.test_utils import mock
from import rf_switch
from import scpi
class SocketMock(mock.mock_class):
"""Mock socket for scpi test."""
def __init__(self, cls, name, *args, **kwargs):
mock.mock_class.__init__(self, cls, name, *args, **kwargs) = None
self.port = None
self.recv_buffer = ''
self.send_data = ''
def close(self):
def connect(self, host, port): = host
self.port = port
def send(self, data):
self.send_data = data
def recv(self, size):
if len(self.recv_val) > size:
return self.recv_val[:size]
return self.recv_val
class ScpiMock(scpi.Scpi):
"""Mock object for Scpi."""
def __init__(self, host='', port=12345, test_interface=False):
if test_interface:
self.socket = SocketMock(socket, socket)
self.socket.connect(host, port)
scpi.Scpi.__init__(self, host, port)
class RfSwitchMock(rf_switch.RfSwitch):
"""Mock object for RfSwitch."""
def __init__(self, host=''):
self.socket = SocketMock(socket, socket)
self.socket.connect(host, scpi.Scpi.SCPI_PORT)