<s> import sys <EOL> import unittest <EOL> from StringIO import StringIO <EOL> class CrashMailTests ( unittest . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from superlance . crashmail import CrashMail <EOL> return CrashMail <EOL> def _makeOne ( self , * opts ) : <EOL> return self . _getTargetClass ( ) ( * opts ) <EOL> def setUp ( self ) : <EOL> import tempfile <EOL> self . tempdir = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> import shutil <EOL> shutil . rmtree ( self . tempdir ) <EOL> def _makeOnePopulated ( self , programs , any , response = None ) : <EOL> import os <EOL> sendmail = '<STR_LIT>' % os . path . join ( self . tempdir , '<STR_LIT>' ) <EOL> email = '<STR_LIT>' <EOL> header = '<STR_LIT>' <EOL> prog = self . _makeOne ( programs , any , email , sendmail , header ) <EOL> prog . stdin = StringIO ( ) <EOL> prog . stdout = StringIO ( ) <EOL> prog . stderr = StringIO ( ) <EOL> return prog <EOL> def test_runforever_not_process_state_exited ( self ) : <EOL> programs = { '<STR_LIT:foo>' : <NUM_LIT:0> , '<STR_LIT:bar>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> groups = { } <EOL> any = None <EOL> prog = self . _makeOnePopulated ( programs , any ) <EOL> prog . stdin . write ( '<STR_LIT>' ) <EOL> prog . stdin . seek ( <NUM_LIT:0> ) <EOL> prog . runforever ( test = True ) <EOL> self . assertEqual ( prog . stderr . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_runforever_expected_exit ( self ) : <EOL> programs = [ '<STR_LIT:foo>' ] <EOL> any = None <EOL> prog = self . _makeOnePopulated ( programs , any ) <EOL> payload = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> prog . stdin . write ( <EOL> '<STR_LIT>' % len ( payload ) ) <EOL> prog . stdin . write ( payload ) <EOL> prog . stdin . seek ( <NUM_LIT:0> ) <EOL> prog . runforever ( test = True ) <EOL> self . assertEqual ( prog . stderr . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_runforever_unexpected_exit ( self ) : <EOL> programs = [ '<STR_LIT:foo>' ] <EOL> any = None <EOL> prog = self . _makeOnePopulated ( programs , any ) <EOL> payload = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> prog . stdin . write ( <EOL> '<STR_LIT>' % len ( payload ) ) <EOL> prog . stdin . write ( payload ) <EOL> prog . stdin . seek ( <NUM_LIT:0> ) <EOL> prog . runforever ( test = True ) <EOL> output = prog . stderr . getvalue ( ) <EOL> lines = output . split ( '<STR_LIT:\n>' ) <EOL> self . assertEqual ( lines [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( lines [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( lines [ <NUM_LIT:2> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( lines [ <NUM_LIT:3> ] , '<STR_LIT>' ) <EOL> self . failUnless ( '<STR_LIT>' in lines [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( lines [ <NUM_LIT:5> ] , '<STR_LIT>' ) <EOL> self . failUnless ( <EOL> '<STR_LIT>' in lines [ <NUM_LIT:6> ] ) <EOL> import os <EOL> mail = open ( os . path . join ( self . tempdir , '<STR_LIT>' ) , '<STR_LIT:r>' ) . read ( ) <EOL> self . failUnless ( <EOL> '<STR_LIT>' in mail ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
