<s> import unittest2 as unittest <EOL> import mock <EOL> from winchester import debugging <EOL> class TestDebugManager ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestDebugManager , self ) . setUp ( ) <EOL> self . debug_manager = debugging . DebugManager ( ) <EOL> def test_get_debugger_none ( self ) : <EOL> debugger = self . debug_manager . get_debugger ( None ) <EOL> self . assertEqual ( "<STR_LIT>" , debugger . _name ) <EOL> self . assertEqual ( <NUM_LIT:2> , debugger . _debug_level ) <EOL> def test_get_debugger_off ( self ) : <EOL> tdef = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> tdef . name = "<STR_LIT>" <EOL> tdef . debug_level = <NUM_LIT:0> <EOL> debugger = self . debug_manager . get_debugger ( tdef ) <EOL> self . assertTrue ( isinstance ( debugger , debugging . NoOpDebugger ) ) <EOL> self . assertEqual ( debugger , <EOL> self . debug_manager . _debuggers [ '<STR_LIT>' ] ) <EOL> debugger2 = self . debug_manager . get_debugger ( tdef ) <EOL> self . assertEqual ( debugger , debugger2 ) <EOL> def test_get_debugger_on ( self ) : <EOL> tdef = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> tdef . name = "<STR_LIT>" <EOL> tdef . debug_level = <NUM_LIT:1> <EOL> debugger = self . debug_manager . get_debugger ( tdef ) <EOL> self . assertTrue ( isinstance ( debugger , debugging . DetailedDebugger ) ) <EOL> self . assertEqual ( debugger , <EOL> self . debug_manager . _debuggers [ '<STR_LIT>' ] ) <EOL> debugger2 = self . debug_manager . get_debugger ( tdef ) <EOL> self . assertEqual ( debugger , debugger2 ) <EOL> def test_dump_group_level1 ( self ) : <EOL> debugger = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . get_debug_level . return_value = <NUM_LIT:1> <EOL> group = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> group . _name = "<STR_LIT>" <EOL> group . _match = <NUM_LIT:1> <EOL> group . _mismatch = <NUM_LIT:2> <EOL> debugger . get_group . return_value = group <EOL> with mock . patch . object ( debugging , "<STR_LIT>" ) as log : <EOL> self . debug_manager . dump_group ( debugger , "<STR_LIT>" ) <EOL> log . info . assert_called_once_with ( <EOL> "<STR_LIT>" ) <EOL> def test_dump_group_level2 ( self ) : <EOL> debugger = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . get_debug_level . return_value = <NUM_LIT:2> <EOL> group = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> group . _name = "<STR_LIT>" <EOL> group . _match = <NUM_LIT:1> <EOL> group . _mismatch = <NUM_LIT:2> <EOL> group . _reasons = { "<STR_LIT:foo>" : <NUM_LIT:12> } <EOL> debugger . get_group . return_value = group <EOL> with mock . patch . object ( debugging , "<STR_LIT>" ) as log : <EOL> self . debug_manager . dump_group ( debugger , "<STR_LIT>" ) <EOL> self . assertEqual ( log . info . call_args_list , <EOL> [ mock . call ( <EOL> "<STR_LIT>" ) , <EOL> mock . call ( "<STR_LIT>" ) ] ) <EOL> def test_dump_counters ( self ) : <EOL> debugger = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . _counters = { '<STR_LIT:foo>' : <NUM_LIT:12> } <EOL> with mock . patch . object ( debugging , "<STR_LIT>" ) as log : <EOL> self . debug_manager . dump_counters ( debugger ) <EOL> log . info . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_dump_debuggers_off ( self ) : <EOL> debugger = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . get_debug_level . return_value = <NUM_LIT:0> <EOL> self . debug_manager . _debuggers = { "<STR_LIT:foo>" : debugger } <EOL> with mock . patch . object ( debugging , "<STR_LIT>" ) as log : <EOL> self . debug_manager . dump_debuggers ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , log . info . call_count ) <EOL> def test_dump_debuggers_on ( self ) : <EOL> debugger = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . get_debug_level . return_value = <NUM_LIT:1> <EOL> debugger . _name = "<STR_LIT>" <EOL> group = mock . MagicMock ( name = "<STR_LIT>" ) <EOL> debugger . _groups = { "<STR_LIT>" : group } <EOL> self . debug_manager . _debuggers = { "<STR_LIT:foo>" : debugger } <EOL> with mock . patch . object ( self . debug_manager , "<STR_LIT>" ) as ctr : <EOL> with mock . patch . object ( self . debug_manager , "<STR_LIT>" ) as grp : <EOL> with mock . patch . object ( debugging , "<STR_LIT>" ) as log : <EOL> self . debug_manager . dump_debuggers ( ) <EOL> self . assertEqual ( <EOL> log . info . call_args_list , <EOL> [ mock . call ( <EOL> "<STR_LIT>" ) , <EOL> mock . call ( <EOL> "<STR_LIT>" ) ] ) <EOL> grp . assert_called_once_with ( debugger , "<STR_LIT>" ) <EOL> ctr . assert_called_once_with ( debugger ) <EOL> debugger . reset . assert_called_once_with ( ) <EOL> class TestDetailedDebugger ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestDetailedDebugger , self ) . setUp ( ) <EOL> self . debugger = debugging . DetailedDebugger ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> def test_constructor ( self ) : <EOL> with mock . patch ( "<STR_LIT>" ) as reset : <EOL> debugging . DetailedDebugger ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> reset . assert_called_once_with ( ) <EOL> self . assertEqual ( self . debugger . _name , "<STR_LIT>" ) <EOL> self . assertEqual ( self . debugger . _debug_level , <NUM_LIT:2> ) <EOL> def test_reset ( self ) : <EOL> self . assertEqual ( self . debugger . _groups , { } ) <EOL> self . assertEqual ( self . debugger . _counters , { } ) <EOL> def test_get_group ( self ) : <EOL> self . assertEqual ( self . debugger . _groups , { } ) <EOL> g = self . debugger . get_group ( "<STR_LIT:foo>" ) <EOL> self . assertEqual ( g . _name , "<STR_LIT:foo>" ) <EOL> self . assertTrue ( self . debugger . _groups [ '<STR_LIT:foo>' ] ) <EOL> def test_bump_counter ( self ) : <EOL> self . assertEqual ( self . debugger . _counters , { } ) <EOL> self . debugger . bump_counter ( "<STR_LIT:foo>" ) <EOL> self . assertEqual ( self . debugger . _counters [ '<STR_LIT:foo>' ] , <NUM_LIT:1> ) <EOL> self . debugger . bump_counter ( "<STR_LIT:foo>" , <NUM_LIT:2> ) <EOL> self . assertEqual ( self . debugger . _counters [ '<STR_LIT:foo>' ] , <NUM_LIT:3> ) <EOL> def test_get_debug_level ( self ) : <EOL> self . assertEqual ( self . debugger . get_debug_level ( ) , <NUM_LIT:2> ) <EOL> class TestNoOpDebugger ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNoOpDebugger , self ) . setUp ( ) <EOL> self . debugger = debugging . NoOpDebugger ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> def test_reset ( self ) : <EOL> self . debugger . reset ( ) <EOL> def test_get_group ( self ) : <EOL> g = self . debugger . get_group ( "<STR_LIT:foo>" ) <EOL> self . assertEqual ( g , self . debugger . noop_group ) <EOL> def test_bump_counter ( self ) : <EOL> self . debugger . bump_counter ( "<STR_LIT:foo>" ) <EOL> self . debugger . bump_counter ( "<STR_LIT:foo>" , <NUM_LIT:2> ) <EOL> def test_get_debug_level ( self ) : <EOL> self . assertEqual ( self . debugger . get_debug_level ( ) , <NUM_LIT:0> ) <EOL> class TestGroup ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestGroup , self ) . setUp ( ) <EOL> self . group = debugging . Group ( "<STR_LIT>" ) <EOL> def test_constructor ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . group . _name ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . group . _match ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . group . _mismatch ) <EOL> self . assertEqual ( { } , self . group . _reasons ) <EOL> def test_match ( self ) : <EOL> self . assertTrue ( self . group . match ( ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _match ) <EOL> def test_mismatch ( self ) : <EOL> self . assertFalse ( self . group . mismatch ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _mismatch ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _reasons [ '<STR_LIT>' ] ) <EOL> def test_check ( self ) : <EOL> self . assertTrue ( self . group . check ( True , "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _match ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . group . _mismatch ) <EOL> self . assertEqual ( { } , self . group . _reasons ) <EOL> self . assertTrue ( self . group . check ( True , "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . group . _match ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . group . _mismatch ) <EOL> self . assertEqual ( { } , self . group . _reasons ) <EOL> self . assertFalse ( self . group . check ( False , "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . group . _match ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _mismatch ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . group . _reasons [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( self . group . check ( False , "<STR_LIT>" ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . group . _match ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . group . _mismatch ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . group . _reasons [ '<STR_LIT>' ] ) <EOL> class TestNoOpGroup ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNoOpGroup , self ) . setUp ( ) <EOL> self . group = debugging . NoOpGroup ( ) <EOL> def test_match ( self ) : <EOL> self . assertTrue ( self . group . match ( ) ) <EOL> def test_mismatch ( self ) : <EOL> self . assertFalse ( self . group . mismatch ( "<STR_LIT>" ) ) <EOL> def test_check ( self ) : <EOL> self . assertTrue ( self . group . check ( True , "<STR_LIT>" ) ) <EOL> self . assertFalse ( self . group . check ( False , "<STR_LIT>" ) ) </s>
