<s> from mock import Mock , MagicMock <EOL> from nose . tools import ok_ <EOL> from pylease . ctxmgmt import Caution , ReplacedSetup <EOL> from tests import PyleaseTest , MockedSetupPy <EOL> class ContextManagersTest ( PyleaseTest ) : <EOL> def test_replaced_setup_must_replace_the_setuptools_setup_with_provided_callback ( self ) : <EOL> key1 = '<STR_LIT>' <EOL> val1 = '<STR_LIT>' <EOL> key2 = '<STR_LIT>' <EOL> val2 = '<STR_LIT>' <EOL> kwargs = { key1 : val1 , key2 : val2 } <EOL> setup_py = """<STR_LIT>""" . format ( key1 , key2 , ** kwargs ) <EOL> callback = Mock ( ) <EOL> with ReplacedSetup ( callback ) : <EOL> with MockedSetupPy ( setup_py , self ) : <EOL> __import__ ( '<STR_LIT>' ) <EOL> callback . assert_called_once_with ( ** kwargs ) <EOL> def test_caution_context_manager_must_rollback_everything_if_error_occurs ( self ) : <EOL> rb1 = MagicMock ( ) <EOL> rb2 = MagicMock ( ) <EOL> rb3 = MagicMock ( ) <EOL> with Caution ( ) as caution : <EOL> caution . add_rollback ( rb1 ) <EOL> caution . add_rollback ( rb2 ) <EOL> raise Exception ( ) <EOL> rb1 . assert_called_once_with ( ) <EOL> rb2 . assert_called_once_with ( ) <EOL> ok_ ( not rb3 . called ) <EOL> def test_caution_context_manager_should_leave_everythin_as_is_if_no_error_occurs ( self ) : <EOL> rb1 = MagicMock ( ) <EOL> with Caution ( ) as caution : <EOL> caution . add_rollback ( rb1 ) <EOL> ok_ ( not rb1 . called ) </s>
