def test_from_socket_mock(self, context, socket_path): socket_path = str(socket_path) new_from_socket = 'udev_monitor_new_from_socket' with pytest.patch_libudev(new_from_socket) as new_from_socket: new_from_socket.return_value = mock.sentinel.pointer monitor = Monitor.from_socket(context, socket_path) new_from_socket.assert_called_with( context, socket_path.encode(sys.getfilesystemencoding())) assert monitor._as_parameter_ is mock.sentinel.pointer Monitor.from_socket(context, 'foobar') new_from_socket.assert_called_with(context, b'foobar') assert isinstance(new_from_socket.call_args[0][1], bytes)
def test_enable_receiving_bound_socket(self, context, socket_path): sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) # cause an error by binding the socket, thus testing error handling in # this method sock.bind(str(socket_path)) monitor = Monitor.from_socket(context, str(socket_path)) with pytest.raises(EnvironmentError) as exc_info: monitor.enable_receiving() pytest.assert_env_error(exc_info.value, errno.EADDRINUSE, str(socket_path))
def test_from_socket(self, context, socket_path): monitor = Monitor.from_socket(context, str(socket_path)) assert monitor._as_parameter_
def test_enable_receiving_socket(self, context, socket_path): monitor = Monitor.from_socket(context, str(socket_path)) monitor.enable_receiving()