<s> from __future__ import unicode_literals <EOL> from mock import patch , Mock <EOL> from nose . tools import raises , ok_ <EOL> from sprinter . exceptions import SprinterException <EOL> from sprinter . testtools import FormulaTest <EOL> import subprocess <EOL> import sprinter . lib as lib <EOL> source_config = """<STR_LIT>""" <EOL> target_config = """<STR_LIT>""" <EOL> def create_mock_call ( ) : <EOL> m = Mock ( ) <EOL> m . return_value = ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> return m <EOL> class TestCommandFormula ( FormulaTest ) : <EOL> """<STR_LIT>""" <EOL> def setup ( self ) : <EOL> super ( TestCommandFormula , self ) . setup ( source_config = source_config , <EOL> target_config = target_config ) <EOL> def teardown ( self ) : <EOL> del ( self . environment ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_install ( self , call ) : <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_update ( self , call ) : <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_remove ( self , call ) : <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_deactivate ( self , call ) : <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_activate ( self , call ) : <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> @ raises ( SprinterException ) <EOL> def test_failure ( self , call ) : <EOL> """<STR_LIT>""" <EOL> call . return_value = ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_failure_no_fail_on_error ( self , call ) : <EOL> """<STR_LIT>""" <EOL> call . return_value = ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert not self . environment . error_occured <EOL> @ patch . object ( lib , '<STR_LIT>' ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_shell ( self , call , is_affirmative ) : <EOL> """<STR_LIT>""" <EOL> is_affirmative . return_value = True <EOL> self . environment . run_feature ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = True , stdout = subprocess . PIPE ) <EOL> @ patch . object ( lib , '<STR_LIT>' , new_callable = create_mock_call ) <EOL> def test_shell_redirect_to_stdout ( self , call ) : <EOL> """<STR_LIT>""" <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> call . assert_called_once_with ( "<STR_LIT>" , shell = False , stdout = None ) </s>
