def test_get_avail_port(self, sock): out = WhateverIO() sock.return_value.accept.return_value = (Mock(), ['helu']) Rdb(out=out) with patch('celery.contrib.rdb.current_process') as curproc: curproc.return_value.name = 'PoolWorker-10' Rdb(out=out) err = sock.return_value.bind.side_effect = socket.error() err.errno = errno.ENOENT with self.assertRaises(socket.error): Rdb(out=out) err.errno = errno.EADDRINUSE with self.assertRaises(Exception): Rdb(out=out) called = [0] def effect(*a, **kw): try: if called[0] > 50: return True raise err finally: called[0] += 1 sock.return_value.bind.side_effect = effect Rdb(out=out)
def get_avail_port(self, *args, **kwargs): try: socket.gethostbyname('docker.for.mac.localhost') host = 'docker.for.mac.localhost' except Exception: host = os.popen('ip route').read().split(' ')[2] sock, port = Rdb.get_avail_port(self, *args, **kwargs) socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(str(port), (host, 6899)) return (sock, port)
def do_list(self, args): lines = 60 context = (lines - 2) / 2 if not args: first = max(1, self.curframe.f_lineno - context) last = first + context * 2 - 1 args = "(%s, %s)" % (first, last) self.lineno = None with style(self, (self.curframe.f_code.co_filename, self.curframe.f_lineno - context)): return Rdb.do_list(self, args)
def test_rdb(self, get_avail_port): sock = Mock() get_avail_port.return_value = (sock, 8000) sock.accept.return_value = (Mock(), ['helu']) out = WhateverIO() with Rdb(out=out) as rdb: get_avail_port.assert_called() assert 'helu' in out.getvalue() # set_quit with patch('sys.settrace') as settrace: rdb.set_quit() settrace.assert_called_with(None) # set_trace with patch('celery.contrib.rdb.Pdb.set_trace') as pset: with patch('celery.contrib.rdb._frame'): rdb.set_trace() rdb.set_trace(Mock()) pset.side_effect = SockErr pset.side_effect.errno = errno.ENOENT with pytest.raises(SockErr): rdb.set_trace() # _close_session rdb._close_session() rdb.active = True rdb._handle = None rdb._client = None rdb._sock = None rdb._close_session() # do_continue rdb.set_continue = Mock() rdb.do_continue(Mock()) rdb.set_continue.assert_called_with() # do_quit rdb.set_quit = Mock() rdb.do_quit(Mock()) rdb.set_quit.assert_called_with()
def test_rdb(self, get_avail_port): sock = Mock() get_avail_port.return_value = (sock, 8000) sock.accept.return_value = (Mock(), ['helu']) out = WhateverIO() rdb = Rdb(out=out) self.assertTrue(get_avail_port.called) self.assertIn('helu', out.getvalue()) # set_quit with patch('sys.settrace') as settrace: rdb.set_quit() settrace.assert_called_with(None) # set_trace with patch('celery.contrib.rdb.Pdb.set_trace') as pset: with patch('celery.contrib.rdb._frame'): rdb.set_trace() rdb.set_trace(Mock()) pset.side_effect = socket.error pset.side_effect.errno = errno.ECONNRESET rdb.set_trace() pset.side_effect.errno = errno.ENOENT with self.assertRaises(socket.error): rdb.set_trace() # _close_session rdb._close_session() # do_continue rdb.set_continue = Mock() rdb.do_continue(Mock()) rdb.set_continue.assert_called_with() # do_quit rdb.set_quit = Mock() rdb.do_quit(Mock()) rdb.set_quit.assert_called_with()
def test_rdb(self, get_avail_port): sock = Mock() get_avail_port.return_value = (sock, 8000) sock.accept.return_value = (Mock(), ['helu']) out = WhateverIO() rdb = Rdb(out=out) self.assertTrue(get_avail_port.called) self.assertIn('helu', out.getvalue()) # set_quit with patch('sys.settrace') as settrace: rdb.set_quit() settrace.assert_called_with(None) # set_trace with patch('celery.contrib.rdb.Pdb.set_trace') as pset: with patch('celery.contrib.rdb._frame'): rdb.set_trace() rdb.set_trace(Mock()) pset.side_effect = SockErr pset.side_effect.errno = errno.ECONNRESET rdb.set_trace() pset.side_effect.errno = errno.ENOENT with self.assertRaises(SockErr): rdb.set_trace() # _close_session rdb._close_session() # do_continue rdb.set_continue = Mock() rdb.do_continue(Mock()) rdb.set_continue.assert_called_with() # do_quit rdb.set_quit = Mock() rdb.do_quit(Mock()) rdb.set_quit.assert_called_with()
def displayhook(self, obj): if obj is not None and not isinstance(obj, list): return pprint.pprint(obj) return Rdb.displayhook(self, obj)
def default(self, line): with style(self): return Rdb.default(self, line)
def set_step(self): os.system('clear') Rdb.set_step(self)
def set_return(self, arg): os.system('clear') Rdb.set_return(self, arg)
def set_next(self, curframe): os.system('clear') Rdb.set_next(self, curframe)
def print_stack_entry(self, *args, **kwargs): with style(self): return Rdb.print_stack_entry(self, *args, **kwargs)
def format_stack_entry(self, *args, **kwargs): entry = Rdb.format_stack_entry(self, *args, **kwargs) return '\n'.join( filter(lambda x: not x.startswith('->'), entry.splitlines()))