def test_build_bw_image(self): image = build_bw_image(self._white_pixels, self._width, self._height) pixels = image.load() print_debug('Computed pixels: {}'.format(image)) for i in range(self._width): for j in range(self._height): self.assertEqual(pixels[i, j], self._expected_pixels[i][j])
def connection_made(self, transport): print_debug('Made a new connection') self._transport = transport self._send_cmd(self.CMD_NICK.format(nick_name=self._nick_name)) self._send_cmd(self.CMD_USER.format( user_name=self._user_name, real_name=self._real_name, server_name=self._server_name, host_name=self._host_name))
def connect(cls, host='127.0.0.1', port=6667, wait=True, **kwargs): print_debug('Connecting to the IRC server {host}:{port}'.format( host=host, port=port)) loop = get_event_loop() def handler(): return cls(loop, **kwargs) connection = loop.create_connection(handler, host, port) _, protocol = loop.run_until_complete(connection) if wait: loop.run_forever() loop.close() return protocol
def _inner(): print_debug('Waiting {} second(s) before disconnect'.format(delay)) sleep(delay) print_debug('Sending disconnect') client.disconnect()
def _send_cmd(self, msg): data = '{}\r\n'.format(msg).encode() print_debug('Sending data: {!r}'.format(data.decode())) self._transport.write(data)
def connection_lost(self, exc): print_debug('Connection closed') self._loop.stop() self._disconnect_future.set_result(True)
def data_received(self, data): print_debug('Received new data: {}'.format(data.decode())) if self._rcv_handler: self._rcv_handler(self)
def disconnect(self): print_debug('Disconnecting') self._transport.close()