当前位置: 首页>>代码示例>>Python>>正文


Python Mock.read方法代码示例

本文整理汇总了Python中unittest.mock.Mock.read方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.read方法的具体用法?Python Mock.read怎么用?Python Mock.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_observer

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import read [as 别名]
    def test_observer(self):
        hardware_device = Mock()
        hardware_device.read = Mock(return_value=0)
        observer = Mock()
        sensor_group = DigitalSensorGroup(8, hardware_device)
        sensor_group.register_observer(observer, 0)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=1)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)
        observer.notify.assert_called_once_with(sensor_group)
        observer.notify.reset_mock()

        hardware_device.read = Mock(return_value=4)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=5)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=7)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)
        observer.notify.assert_called_once_with(sensor_group)
        observer.notify.reset_mock()
开发者ID:munnik,项目名称:ShipControl,代码行数:30,代码来源:test_sensor.py

示例2: test_notify

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import read [as 别名]
 def test_notify(self):
     hardware_device = Mock()
     hardware_device.read = Mock(return_value=0)
     sensor_group = DigitalSensorGroup(1, hardware_device)
     sensor = DigitalSensor("test", sensor_group, 0)
     assert sensor.state == DigitalSensor.HIGH
     hardware_device.read = Mock(return_value=1)
     sensor_group.notify(self)
     assert sensor.state == DigitalSensor.LOW
开发者ID:munnik,项目名称:ShipControl,代码行数:11,代码来源:test_sensor.py

示例3: mock_urlopen

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import read [as 别名]
 def mock_urlopen(url, data=None):
     headers = {"Replay-Nonce": "MockNonce"}
     response = Mock()
     response.status = 200
     if url.endswith("/new-reg"):
         headers["Location"] = "mock://reg-location"
         response.status = 201
     response.headers = headers
     response.read = Mock(return_value=b'{"mock": true}')
     return response
开发者ID:drdaeman,项目名称:le_client,代码行数:12,代码来源:tests.py

示例4: __mockConnection

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import read [as 别名]
def __mockConnection(connection_mock, response_data='', response_status=200, response_reason='OK', raise_=None):
    # http response mock
    response_mock = Mock(spec=http.client.HTTPResponse)
    response_mock.read = io.BytesIO(response_data.encode()).read
    response_mock.status = response_status
    response_mock.reason = response_reason

    # connectionmock
    connection_mock.getresponse.return_value = response_mock
    if raise_:
        connection_mock.request = __createRaiser(raise_)

    # class mock
    class_mock = Mock()
    class_mock.return_value = connection_mock

    return class_mock
开发者ID:Turgon37,项目名称:DynUpdate,代码行数:19,代码来源:connexionmock.py

示例5: test_send_states_to_hardware_device

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import read [as 别名]
 def test_send_states_to_hardware_device(self):
     hardware_device = Mock()
     hardware_device.read = Mock(return_value=37)
     sensor_group = DigitalSensorGroup(8, hardware_device)
     sensor0 = DigitalSensor("sensor0", sensor_group, 0)
     sensor1 = DigitalSensor("sensor1", sensor_group, 1)
     sensor2 = DigitalSensor("sensor2", sensor_group, 2)
     sensor3 = DigitalSensor("sensor3", sensor_group, 3)
     sensor4 = DigitalSensor("sensor4", sensor_group, 4)
     sensor5 = DigitalSensor("sensor5", sensor_group, 5)
     sensor6 = DigitalSensor("sensor6", sensor_group, 6)
     sensor7 = DigitalSensor("sensor7", sensor_group, 7)
     assert sensor0.state == DigitalSensor.LOW
     assert sensor1.state == DigitalSensor.HIGH
     assert sensor2.state == DigitalSensor.LOW
     assert sensor3.state == DigitalSensor.HIGH
     assert sensor4.state == DigitalSensor.HIGH
     assert sensor5.state == DigitalSensor.LOW
     assert sensor6.state == DigitalSensor.HIGH
     assert sensor7.state == DigitalSensor.HIGH
开发者ID:munnik,项目名称:ShipControl,代码行数:22,代码来源:test_sensor.py


注:本文中的unittest.mock.Mock.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。