<s> import string <EOL> import six <EOL> import testtools <EOL> from taskflow import exceptions as exc <EOL> from taskflow import test <EOL> class TestExceptions ( test . TestCase ) : <EOL> def test_cause ( self ) : <EOL> capture = None <EOL> try : <EOL> raise exc . TaskFlowException ( "<STR_LIT>" , cause = IOError ( "<STR_LIT>" ) ) <EOL> except Exception as e : <EOL> capture = e <EOL> self . assertIsNotNone ( capture ) <EOL> self . assertIsInstance ( capture , exc . TaskFlowException ) <EOL> self . assertIsNotNone ( capture . cause ) <EOL> self . assertIsInstance ( capture . cause , IOError ) <EOL> def test_cause_pformat ( self ) : <EOL> capture = None <EOL> try : <EOL> raise exc . TaskFlowException ( "<STR_LIT>" , cause = IOError ( "<STR_LIT>" ) ) <EOL> except Exception as e : <EOL> capture = e <EOL> self . assertIsNotNone ( capture ) <EOL> self . assertGreater ( <NUM_LIT:0> , len ( capture . pformat ( ) ) ) <EOL> def test_raise_with ( self ) : <EOL> capture = None <EOL> try : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> except Exception : <EOL> try : <EOL> exc . raise_with_cause ( exc . TaskFlowException , '<STR_LIT>' ) <EOL> except Exception as e : <EOL> capture = e <EOL> self . assertIsNotNone ( capture ) <EOL> self . assertIsInstance ( capture , exc . TaskFlowException ) <EOL> self . assertIsNotNone ( capture . cause ) <EOL> self . assertIsInstance ( capture . cause , IOError ) <EOL> def test_no_looping ( self ) : <EOL> causes = [ ] <EOL> for a in string . ascii_lowercase : <EOL> try : <EOL> cause = causes [ - <NUM_LIT:1> ] <EOL> except IndexError : <EOL> cause = None <EOL> causes . append ( exc . TaskFlowException ( '<STR_LIT>' % a , cause = cause ) ) <EOL> e = causes [ <NUM_LIT:0> ] <EOL> last_e = causes [ - <NUM_LIT:1> ] <EOL> e . _cause = last_e <EOL> self . assertIsNotNone ( e . pformat ( ) ) <EOL> def test_pformat_str ( self ) : <EOL> ex = None <EOL> try : <EOL> try : <EOL> try : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> except IOError : <EOL> exc . raise_with_cause ( exc . TaskFlowException , <EOL> "<STR_LIT>" ) <EOL> except exc . TaskFlowException : <EOL> exc . raise_with_cause ( exc . TaskFlowException , "<STR_LIT>" ) <EOL> except exc . TaskFlowException as e : <EOL> ex = e <EOL> self . assertIsNotNone ( ex ) <EOL> self . assertIsInstance ( ex , exc . TaskFlowException ) <EOL> self . assertIsInstance ( ex . cause , exc . TaskFlowException ) <EOL> self . assertIsInstance ( ex . cause . cause , IOError ) <EOL> p_msg = ex . pformat ( ) <EOL> p_str_msg = str ( ex ) <EOL> for msg in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertIn ( msg , p_msg ) <EOL> self . assertIn ( msg , p_str_msg ) <EOL> def test_pformat_root_class ( self ) : <EOL> ex = exc . TaskFlowException ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> ex . pformat ( show_root_class = True ) ) <EOL> self . assertNotIn ( "<STR_LIT>" , <EOL> ex . pformat ( show_root_class = False ) ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> ex . pformat ( show_root_class = True ) ) <EOL> def test_invalid_pformat_indent ( self ) : <EOL> ex = exc . TaskFlowException ( "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , ex . pformat , indent = - <NUM_LIT:100> ) <EOL> @ testtools . skipIf ( not six . PY3 , '<STR_LIT>' ) <EOL> def test_raise_with_cause ( self ) : <EOL> capture = None <EOL> try : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> except Exception : <EOL> try : <EOL> exc . raise_with_cause ( exc . TaskFlowException , '<STR_LIT>' ) <EOL> except Exception as e : <EOL> capture = e <EOL> self . assertIsNotNone ( capture ) <EOL> self . assertIsInstance ( capture , exc . TaskFlowException ) <EOL> self . assertIsNotNone ( capture . cause ) <EOL> self . assertIsInstance ( capture . cause , IOError ) <EOL> self . assertIsNotNone ( capture . __cause__ ) <EOL> self . assertIsInstance ( capture . __cause__ , IOError ) </s>
