def _trapCheck(response): traps = tuple(words for reply_word, words in response if reply_word == '!trap') if len(traps) > 1: traps = tuple( TrapError(message=trap['message'], category=trap.get('category')) for trap in traps ) raise MultiTrapError(*traps) elif len(traps) == 1: trap = traps[0] raise TrapError(message=trap['message'], category=trap.get('category'))
def test_connect_raises_when_failed_login(transport_mock): failed = Mock(name='failed', side_effect=TrapError(message='failed to login')) with pytest.raises(TrapError): connect(host='127.0.0.1', username='******', password='', login_method=failed)
def _readResponse(self): """ Yield each sentence untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received. """ traps = [] reply_word = None while reply_word != '!done': reply_word, words = self._readSentence() if reply_word == '!trap': traps.append(TrapError(**words)) elif reply_word in ('!re', '!done') and words: yield words if len(traps) > 1: raise MultiTrapError(*traps) elif len(traps) == 1: raise traps[0]
def test_TrapError_newlines(): r"""Assert that string representation replaces \r\n with comma.""" error = TrapError(message='some\r\n string') assert str(error) == 'some, string'