本文整理汇总了Python中mock.MagicMock.client_address方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.client_address方法的具体用法?Python MagicMock.client_address怎么用?Python MagicMock.client_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.client_address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handler_invalid_client
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_handler_invalid_client():
with patch('compoundpi.server.NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('foo', 1)
compoundpi.server.CompoundPiServerProtocol(
(b'0 LIST', socket), ('localhost', 1), server)
m.assert_called_once_with(
socket, ('localhost', 1),
b'0 ERROR\nlocalhost: Invalid client or protocol error')
示例2: test_handler_invalid_client
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_handler_invalid_client():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
with patch.object(compoundpi.server.warnings, 'warn') as w:
socket = Mock()
server = MagicMock()
server.client_address = ('foo', 1)
compoundpi.server.CameraRequestHandler(
(b'0 LIST', socket), ('localhost', 1), server)
assert w.call_count == 1
assert isinstance(
w.call_args[0][0], compoundpi.exc.CompoundPiInvalidClient)
示例3: test_hello_handler_stale_time
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_hello_handler_stale_time():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
with patch.object(compoundpi.server.warnings, 'warn') as w:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.client_timestamp = 2000.0
handler = compoundpi.server.CameraRequestHandler(
(b'0 HELLO 1000.0', socket), ('localhost', 1), server)
assert w.call_count == 1
assert isinstance(
w.call_args[0][0], compoundpi.exc.CompoundPiStaleClientTime)
示例4: test_awb_handler_auto
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_awb_handler_auto():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 AWB auto 1.0 1.0', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.awb_mode == 'auto'
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例5: test_resolution_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_resolution_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 RESOLUTION 1920 1080', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.resolution == (1920, 1080)
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例6: test_blink_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_blink_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
with patch('threading.Thread') as thread:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 0
handler = compoundpi.server.CameraRequestHandler(
(b'1 BLINK', socket), ('localhost', 1), server)
assert server.seqno == 1
m.assert_called_once_with(
socket, ('localhost', 1), '1 OK\n')
thread.assert_called_once_with(target=handler.blink_led, args=(5,))
示例7: test_hello_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_hello_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = None
handler = compoundpi.server.CameraRequestHandler(
(b'0 HELLO 1000.0', socket), ('localhost', 1), server)
assert server.client_address == ('localhost', 1)
assert server.client_timestamp == 1000.0
assert server.seqno == 0
m.assert_called_once_with(
socket, ('localhost', 1),
'0 OK\nVERSION %s' % compoundpi.__version__)
示例8: test_hello_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_hello_handler():
with patch('compoundpi.server.NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = None
handler = compoundpi.server.CompoundPiServerProtocol(
(b'0 HELLO 1000.0', socket), ('localhost', 1), server)
m.assert_called_once_with(
socket, ('localhost', 1),
('0 OK\nVERSION %s' % compoundpi.__version__).encode('utf-8'))
assert server.client_address == ('localhost', 1)
assert server.client_timestamp == 1000.0
assert server.seqno == 0
示例9: test_iso_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_iso_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 ISO 400', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.iso == 400
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例10: test_metering_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_metering_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 METERING spot', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.meter_mode == 'spot'
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例11: test_flip_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_flip_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 FLIP 1 0', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.hflip == True
assert server.camera.vflip == False
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例12: test_awb_handler_manual
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_awb_handler_manual():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 AWB off 1.5 1.3', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.awb_mode == 'off'
assert server.camera.awb_gains == (1.5, 1.3)
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例13: test_exposure_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_exposure_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 EXPOSURE auto 20.0 24', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.exposure_mode == 'auto'
assert server.camera.shutter_speed == 20000.0
assert server.camera.exposure_compensation == 24
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例14: test_levels_handler
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_levels_handler():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
handler = compoundpi.server.CameraRequestHandler(
(b'2 LEVELS 1 2 3', socket), ('localhost', 1), server)
assert server.seqno == 2
assert server.camera.brightness == 1
assert server.camera.contrast == 2
assert server.camera.saturation == 3
m.assert_called_once_with(
socket, ('localhost', 1),
'2 OK\n')
示例15: test_capture_handler_past_sync
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import client_address [as 别名]
def test_capture_handler_past_sync():
with patch.object(compoundpi.server, 'NetworkRepeater') as m:
with patch.object(compoundpi.server.time, 'time') as now:
with patch.object(compoundpi.server.time, 'sleep') as sleep:
socket = Mock()
server = MagicMock()
server.client_address = ('localhost', 1)
server.seqno = 1
now.return_value = 1000.0
with patch.object(compoundpi.server.CameraRequestHandler, 'stream_generator') as gen:
handler = compoundpi.server.CameraRequestHandler(
(b'2 CAPTURE 1 0 900.0', socket), ('localhost', 1), server)
assert m.call_count == 1
args, kwargs = m.call_args
assert args[0] == socket
assert args[1] == ('localhost', 1)
assert args[2].startswith('2 ERROR\n')