<s> from __future__ import print_function , unicode_literals <EOL> import unittest <EOL> import mocker <EOL> import test . unit . configuration as configuration_module <EOL> import voodoo . configuration as ConfigurationManager <EOL> import weblab . experiment . devices . gpib . gpib as Gpib <EOL> import weblab . experiment . devices . gpib . exc as GpibErrors <EOL> class WrappedLauncherPopen ( Gpib . Launcher ) : <EOL> _fail_in_create_popen = False <EOL> def __init__ ( self , popen_mock , * args , ** kargs ) : <EOL> self . raise_exception = False <EOL> self . _popen_mock = popen_mock <EOL> Gpib . Launcher . __init__ ( self , * args , ** kargs ) <EOL> def _create_popen ( self , cmd_file ) : <EOL> if self . _fail_in_create_popen : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return self . _popen_mock <EOL> class GpibLauncherTestCase ( mocker . MockerTestCase ) : <EOL> def setUp ( self ) : <EOL> self . cfg_manager = ConfigurationManager . ConfigurationManager ( ) <EOL> self . cfg_manager . append_module ( configuration_module ) <EOL> def test_error_creating_popen_not_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _fail_in_create_popen = True <EOL> self . mocker . replay ( ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorProgrammingDeviceError , <EOL> launcher . execute , <EOL> '<STR_LIT>' , <EOL> False <EOL> ) <EOL> def test_error_creating_popen_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _fail_in_create_popen = True <EOL> self . mocker . replay ( ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorProgrammingDeviceError , <EOL> launcher . execute , <EOL> '<STR_LIT>' , <EOL> True <EOL> ) <EOL> def test_error_waiting_not_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _popen_mock . poll ( ) <EOL> self . mocker . throw ( Exception ( "<STR_LIT>" ) ) <EOL> self . mocker . replay ( ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorWaitingForProgrammingFinishedError , <EOL> launcher . execute , <EOL> '<STR_LIT>' , <EOL> False <EOL> ) <EOL> def test_error_waiting_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _popen_mock . poll ( ) <EOL> self . mocker . throw ( Exception ( "<STR_LIT>" ) ) <EOL> self . mocker . replay ( ) <EOL> result_execute = launcher . execute ( "<STR_LIT>" , True ) <EOL> self . assertEquals ( None , result_execute ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorWaitingForProgrammingFinishedError , <EOL> launcher . poll <EOL> ) <EOL> def test_error_reading_not_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _popen_mock . poll ( ) <EOL> self . mocker . result ( <NUM_LIT:0> ) <EOL> launcher . _popen_mock . stdout . read ( ) <EOL> self . mocker . throw ( Exception ( '<STR_LIT>' ) ) <EOL> self . mocker . replay ( ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorRetrievingOutputFromProgrammingProgramError , <EOL> launcher . execute , <EOL> '<STR_LIT>' , <EOL> False <EOL> ) <EOL> def test_error_reading_background ( self ) : <EOL> launcher = WrappedLauncherPopen ( self . mocker . mock ( ) , self . cfg_manager ) <EOL> launcher . _popen_mock . poll ( ) <EOL> self . mocker . result ( <NUM_LIT:0> ) <EOL> launcher . _popen_mock . stdout . read ( ) <EOL> self . mocker . throw ( Exception ( '<STR_LIT>' ) ) <EOL> self . mocker . replay ( ) <EOL> result_execute = launcher . execute ( "<STR_LIT>" , True ) <EOL> self . assertEquals ( None , result_execute ) <EOL> self . assertRaises ( <EOL> GpibErrors . ErrorRetrievingOutputFromProgrammingProgramError , <EOL> launcher . poll <EOL> ) <EOL> def tearDown ( self ) : <EOL> self . cfg_manager . reload ( ) <EOL> def suite ( ) : <EOL> return unittest . makeSuite ( GpibLauncherTestCase ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
