<s> """<STR_LIT>""" <EOL> from unittest import TestCase <EOL> from testfixtures import TempDirectory <EOL> from nose . tools import eq_ <EOL> from . . hook import default_before_hook <EOL> from . . hook import default_after_hook <EOL> from . . hook import hook <EOL> from ... config import Config <EOL> class TestHooks ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . temp_directory = TempDirectory ( ) <EOL> config = Config ( ) <EOL> config . etl [ '<STR_LIT>' ] = self . temp_directory . path <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . temp_directory . cleanup ( ) <EOL> @ staticmethod <EOL> def test_default_before_hook_simple ( ) : <EOL> """<STR_LIT>""" <EOL> args , kwargs = default_before_hook ( <NUM_LIT:1> , '<STR_LIT:2>' , three = <NUM_LIT:3> ) <EOL> eq_ ( args , ( <NUM_LIT:1> , '<STR_LIT:2>' ) ) <EOL> eq_ ( kwargs , { '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> @ staticmethod <EOL> def test_default_before_hook_no_params ( ) : <EOL> """<STR_LIT>""" <EOL> args , kwargs = default_before_hook ( ) <EOL> eq_ ( args , ( ) ) <EOL> eq_ ( kwargs , { } ) <EOL> @ staticmethod <EOL> def test_default_before_hook_only_args ( ) : <EOL> """<STR_LIT>""" <EOL> args , kwargs = default_before_hook ( <NUM_LIT:1> , '<STR_LIT:2>' ) <EOL> eq_ ( args , ( <NUM_LIT:1> , '<STR_LIT:2>' ) ) <EOL> eq_ ( kwargs , { } ) <EOL> @ staticmethod <EOL> def test_default_before_hook_only_kwargs ( ) : <EOL> """<STR_LIT>""" <EOL> args , kwargs = default_before_hook ( one = <NUM_LIT:1> , two = '<STR_LIT:2>' ) <EOL> eq_ ( args , ( ) ) <EOL> eq_ ( kwargs , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT:2>' } ) <EOL> @ staticmethod <EOL> def test_default_after_hook_simple ( ) : <EOL> """<STR_LIT>""" <EOL> result = default_after_hook ( '<STR_LIT:test>' ) <EOL> eq_ ( result , '<STR_LIT:test>' ) <EOL> def test_config_not_found_default_hooks ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> config = Config ( ) <EOL> del config . etl [ '<STR_LIT>' ] <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> def test_hook_file_not_found_default_hooks ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> def test_before_hook_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:2> ) <EOL> def test_after_hook_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:3> ) <EOL> def test_both_before_and_after_hook ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:4> ) <EOL> def test_that_hooks_do_not_leak ( self ) : <EOL> """<STR_LIT>""" <EOL> hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def test_hook ( number ) : <EOL> return number <EOL> eq_ ( test_hook ( <NUM_LIT:1> ) , <NUM_LIT:4> ) <EOL> second_hook_file = '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . temp_directory . write ( '<STR_LIT>' , second_hook_file ) <EOL> @ hook ( '<STR_LIT>' ) <EOL> def second_test_hook ( number ) : <EOL> return number <EOL> eq_ ( second_test_hook ( <NUM_LIT:1> ) , <NUM_LIT> ) </s>
