<s> from contextlib import contextmanager <EOL> import threading <EOL> import unittest <EOL> import time <EOL> from robotide . contrib . testrunner . TestRunnerAgent import RobotDebugger <EOL> class TestDebugger ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _debugger = RobotDebugger ( ) <EOL> def test_pausing_and_resuming ( self ) : <EOL> self . assertFalse ( self . _debugger . is_paused ( ) ) <EOL> self . _debugger . pause ( ) <EOL> self . assertTrue ( self . _debugger . is_paused ( ) ) <EOL> self . _debugger . resume ( ) <EOL> self . assertFalse ( self . _debugger . is_paused ( ) ) <EOL> def test_is_breakpoint ( self ) : <EOL> self . assertTrue ( self . _debugger . is_breakpoint ( '<STR_LIT>' , { '<STR_LIT:args>' : [ '<STR_LIT>' ] } ) ) <EOL> self . assertFalse ( self . _debugger . is_breakpoint ( '<STR_LIT>' , { '<STR_LIT:args>' : [ '<STR_LIT>' ] } ) ) <EOL> self . assertFalse ( self . _debugger . is_breakpoint ( '<STR_LIT>' , { '<STR_LIT:args>' : [ '<STR_LIT>' ] } ) ) <EOL> self . assertFalse ( self . _debugger . is_breakpoint ( '<STR_LIT>' , { '<STR_LIT:args>' : [ ] } ) ) <EOL> def test_step_next ( self ) : <EOL> self . _debugger . pause ( ) <EOL> started = threading . Event ( ) <EOL> first_keyword_done = threading . Event ( ) <EOL> second_keyword_done = threading . Event ( ) <EOL> third_keyword_done = threading . Event ( ) <EOL> wait_for_step_next_before_entering_debugger = threading . Event ( ) <EOL> def test_execution ( ) : <EOL> started . set ( ) <EOL> with self . kw ( ) : <EOL> first_keyword_done . set ( ) <EOL> wait_for_step_next_before_entering_debugger . wait ( ) <EOL> with self . kw ( ) : <EOL> second_keyword_done . set ( ) <EOL> with self . kw ( ) : <EOL> third_keyword_done . set ( ) <EOL> with self . execution ( test_execution ) : <EOL> self . _verify_done ( started ) <EOL> self . assertFalse ( first_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_next ( ) <EOL> self . _verify_done ( first_keyword_done ) <EOL> self . assertFalse ( second_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_next ( ) <EOL> wait_for_step_next_before_entering_debugger . set ( ) <EOL> self . _verify_done ( second_keyword_done ) <EOL> self . assertFalse ( third_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_next ( ) <EOL> self . _verify_done ( third_keyword_done ) <EOL> def _verify_done ( self , event ) : <EOL> self . assertTrue ( event . wait ( timeout = <NUM_LIT> ) or event . isSet ( ) ) <EOL> @ contextmanager <EOL> def kw ( self , passes = True ) : <EOL> self . _debugger . start_keyword ( ) <EOL> yield <EOL> self . _debugger . end_keyword ( passes ) <EOL> @ contextmanager <EOL> def execution ( self , executed ) : <EOL> t = threading . Thread ( target = executed ) <EOL> t . setDaemon ( True ) <EOL> t . start ( ) <EOL> yield <EOL> t . join ( ) <EOL> def test_step_over ( self ) : <EOL> self . _debugger . pause ( ) <EOL> started = threading . Event ( ) <EOL> first_keyword_done = threading . Event ( ) <EOL> second_keyword_done = threading . Event ( ) <EOL> third_keyword_done = threading . Event ( ) <EOL> last_keyword_done = threading . Event ( ) <EOL> def test_execution ( ) : <EOL> started . set ( ) <EOL> with self . kw ( ) : <EOL> first_keyword_done . set ( ) <EOL> with self . kw ( ) : <EOL> with self . kw ( ) : <EOL> pass <EOL> with self . kw ( ) : <EOL> pass <EOL> second_keyword_done . set ( ) <EOL> with self . kw ( ) : <EOL> third_keyword_done . set ( ) <EOL> with self . kw ( ) : <EOL> last_keyword_done . set ( ) <EOL> with self . execution ( test_execution ) : <EOL> self . _verify_done ( started ) <EOL> self . assertFalse ( first_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_next ( ) <EOL> self . _verify_done ( first_keyword_done ) <EOL> self . assertFalse ( second_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_over ( ) <EOL> self . _verify_done ( second_keyword_done ) <EOL> self . assertFalse ( third_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_over ( ) <EOL> self . _verify_done ( third_keyword_done ) <EOL> self . assertFalse ( last_keyword_done . isSet ( ) ) <EOL> self . _debugger . step_over ( ) <EOL> self . _verify_done ( last_keyword_done ) <EOL> def test_pause_on_failure ( self ) : <EOL> self . _debugger . pause_on_failure ( True ) <EOL> before_failure = threading . Event ( ) <EOL> after_failure = threading . Event ( ) <EOL> def test_execution ( ) : <EOL> with self . kw ( ) : <EOL> pass <EOL> with self . kw ( ) : <EOL> pass <EOL> before_failure . set ( ) <EOL> with self . kw ( False ) : <EOL> pass <EOL> with self . kw ( ) : <EOL> pass <EOL> after_failure . set ( ) <EOL> with self . execution ( test_execution ) : <EOL> self . _verify_done ( before_failure ) <EOL> self . assertFalse ( after_failure . isSet ( ) ) <EOL> self . _debugger . resume ( ) <EOL> time . sleep ( <NUM_LIT:0> ) <EOL> self . _verify_done ( after_failure ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
