class Test_run(unittest.TestCase): def setUp(self): self.vi_run = ViRunCommand(mock.Mock()) @mock.patch('Vintageous.run.VintageState') def testFinallySection(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) @mock.patch('Vintageous.run.VintageState') def testFinallySectionWhenXposMustBeUpdated(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': True, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(thing.update_xpos.call_count, 1) @mock.patch('Vintageous.run.VintageState') def testFinallySectionWhenMustScrollIntoView(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': True, 'scroll_command': None, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.vi_run.view.show.assert_called_with(500) @mock.patch('Vintageous.run.VintageState') def testCanCreateJumpIfRequestedAtCurrentPosition(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': True, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) addtjl.assert_called_once_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanCreateJumpIfRequestedAsJump(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': True, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) addtjl.assert_called_once_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanDoMotionOnly(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) @mock.patch('Vintageous.run.VintageState') def testSignalsErrorIfLoneMotionFails(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': MODE_NORMAL, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) self.assertEqual(ut.blink.call_count, 1) # test lone action + non-empty sels # test lone action + empty sels # test action abortion branch @mock.patch('Vintageous.run.VintageState') def testCanDoLoneAction(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': None, 'motion': None, 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 0) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assert_called_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanDoLoneAction(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': None, 'motion': None, 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 0) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assert_called_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testAbortsActionIfMotionFailedInModeInternalNormal(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': _MODE_INTERNAL_NORMAL, 'cancel_action_if_motion_fails': True, 'motion': 'bar', 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [sublime.Region(0, 2)] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 2) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assertEqual(doac.call_count, 0) self.assertEqual(ut.blink.call_count, 1) @mock.patch('Vintageous.run.VintageState') def testAbortsActionIfMotionFailedInModeVisual(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': MODE_VISUAL, 'cancel_action_if_motion_fails': True, 'motion': 'bar', 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [sublime.Region(0, 2)] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 2) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assertEqual(doac.call_count, 0) self.assertEqual(ut.blink.call_count, 1)
class Test_run(unittest.TestCase): def setUp(self): self.vi_run = ViRunCommand(mock.Mock()) @mock.patch('Vintageous.run.VintageState') def testFinallySection(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) @mock.patch('Vintageous.run.VintageState') def testFinallySectionWhenXposMustBeUpdated(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': True, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(thing.update_xpos.call_count, 1) @mock.patch('Vintageous.run.VintageState') def testFinallySectionWhenMustScrollIntoView(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': True, 'scroll_command': None, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.vi_run.view.show.assert_called_with(500) @mock.patch('Vintageous.run.VintageState') def testCanCreateJumpIfRequestedAtCurrentPosition(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': True, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) addtjl.assert_called_once_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanCreateJumpIfRequestedAsJump(self, mocked_state): vi_cmd_data = { '_repeat_action': True, 'creates_jump_at_current_position': False, 'is_jump': True, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) addtjl.assert_called_once_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanDoMotionOnly(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) @mock.patch('Vintageous.run.VintageState') def testSignalsErrorIfLoneMotionFails(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': None, 'mode': MODE_NORMAL, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) self.assertEqual(ut.blink.call_count, 1) # test lone action + non-empty sels # test lone action + empty sels # test action abortion branch @mock.patch('Vintageous.run.VintageState') def testCanDoLoneAction(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': None, 'motion': None, 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 0) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assert_called_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testCanDoLoneAction(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': None, 'motion': None, 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, # FIXME: In reality, this will be 'False' most of the time. 'keep_selection_as_is': True, } self.vi_run.view.sel.return_value = [] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 0) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 1) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assert_called_with(vi_cmd_data) @mock.patch('Vintageous.run.VintageState') def testAbortsActionIfMotionFailedInModeInternalNormal(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': _MODE_INTERNAL_NORMAL, 'cancel_action_if_motion_fails': True, 'motion': 'bar', 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [sublime.Region(0, 2)] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 2) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assertEqual(doac.call_count, 0) self.assertEqual(ut.blink.call_count, 1) @mock.patch('Vintageous.run.VintageState') def testAbortsActionIfMotionFailedInModeVisual(self, mocked_state): vi_cmd_data = { 'creates_jump_at_current_position': False, 'is_jump': False, 'action': 'foo', 'mode': MODE_VISUAL, 'cancel_action_if_motion_fails': True, 'motion': 'bar', 'motion_required': None, 'must_update_xpos': False, 'scroll_into_view': False, 'next_mode': 10, 'follow_up_mode': 100, } self.vi_run.view.sel.return_value = [sublime.Region(0, 2)] thing = mock.Mock() thing.next_mode = 0 mocked_state.return_value = thing self.vi_run.view.sel.return_value = [500] with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \ mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \ mock.patch.object(self.vi_run, 'debug') as debug, \ mock.patch.object(self.vi_run, 'do_post_action') as doposac, \ mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \ mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \ mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \ mock.patch.object(self.vi_run, 'do_action') as doac, \ mock.patch('Vintageous.run.utils') as ut: self.vi_run.run(None, **vi_cmd_data) self.assertEqual(savec.call_count, 1) self.assertEqual(dowhm.call_count, 1) self.assertEqual(debug.call_count, 1) self.assertEqual(doposac.call_count, 1) self.assertEqual(domodsel.call_count, 1) self.assertEqual(restorc.call_count, 2) self.assertEqual(thing.next_mode, 10) self.assertEqual(thing.next_mode_command, 100) self.assertEqual(addtjl.call_count, 0) doac.assertEqual(doac.call_count, 0) self.assertEqual(ut.blink.call_count, 1)