def test_formatting_error(self): class BadStr(object): def __repr__(self): raise Exception,"can't format this object to string" assertions.warn('a problem', bad=BadStr()) self.mock_logger.Warn.assert_called_with('ASSERTION. NO INFO - ERROR WHILE FORMATTING ARGS!')
def test_bad_format(self): class BadStr(object): def __repr__(self): raise Exception,"can't format this object to string" assertions.warn(bad=BadStr()) s = self.helper.get_output() start = "WARNING: (NO INFO - ERROR WHILE FORMATTING ARGS!)" self.assert_(s.startswith(start),'s=%s'%s)
def __init__(self, wrapped, timeout = None): DynamicProxy.__init__(self) self._timeout = timeout self._wrapped = wrapped if hasattr(wrapped,'logger'): name = wrapped.logger.name + '.Sync' self.logger = log.get_logger(name) else: self.logger = log.get_logger('AO.Sync') # will propagate to root logger assertions.warn('%s - No logger found for %s' % (self,wrapped))
def start(self): self.logger.Info("AO started") # If self.obj has start method, call it obj_start = getattr(self.obj, 'start', None) if callable(obj_start): try: obj_start() except Exception, e: assertions.warn('Got exception while starting AO. %s' % fmt_exc(e)) raise
def _run(self): with self.thread_start_hook_lock: self.thread_start_hook(ao=self, thread=None, thread_number=None, b_before_starting_thread=False) self.run_hook(RunStage.Start) while True: cmd = self.q.get() try: rc = cmd() if rc: break except Exception, e: #print('Uncaught Exception: %s' % fmt_exc(e)) assertions.warn('Uncaught Exception:',ao=self, details=fmt_exc(e)) self.run_hook(RunStage.Exception)
def _notify_observers(self,b_progress, b_allow_regression = False): lst = self._lst_observers self._lst_observers = [] for obs_info in lst: obs,b_notify_on_progress,b_notify_once = obs_info b_keep = True if b_notify_on_progress or not b_progress: if b_notify_once: b_keep = False try: obs(self, b_allow_regression = b_allow_regression) except Exception, e: assertions.warn("Future got exception while calling observer.", observer=obs, exc=fmt_exc(e)) if b_keep: self._lst_observers.append(obs_info)
def quit(self): #@ReservedAssignment self.logger.Info("AO stopped (quit called)") # If self.obj has quit method, call it try: if self.is_active: obj_quit = self.obj.quit if callable(obj_quit): try: obj_quit() except Exception, e: assertions.warn('Got exception while quitting AO. %s' % fmt_exc(e)) except AttributeError: pass # no quit method self.logger.Debug('user quit hook finished') self.is_active = False
def test_warn(self): assertions.warn(3,name='john') s = self.helper.get_output() self.assert_(s.startswith("WARNING: INFO:3 KW:name=john\nStack:\n"),s) self.assertEquals(assertions.Assertions.had_assertion,True)
def test_warn(self): assertions.warn('problem',name='john') self.assertEquals(assertions.Assertions.had_assertion,True) self.alert_sender.assert_called_with(self.mock_logger, assertions.MsgType.Warning, 'problem', name='john')
def test_basic_formatting(self): assertions.warn('problem',name='john') self.mock_logger.Warn.assert_called_with('problem. name=john') self.assertRaises(assertions.AssertionException, assertions.fail, 'another problem', name='jane') self.mock_logger.Error.assert_called_with('another problem. name=jane')