MCPcopy Create free account
hub / github.com/ycm-core/YouCompleteMe / MockVimModule

Function MockVimModule

python/ycm/tests/test_utils.py:683–712  ·  view source on GitHub ↗

The 'vim' module is something that is only present when running inside the Vim Python interpreter, so we replace it with a MagicMock for tests. If you need to add additional mocks to vim module functions, then use 'patch' from mock module, to ensure that the state of the vim mock is returned b

()

Source from the content-addressed store, hash-verified

681
682
683def MockVimModule():
684 """The 'vim' module is something that is only present when running inside the
685 Vim Python interpreter, so we replace it with a MagicMock for tests. If you
686 need to add additional mocks to vim module functions, then use 'patch' from
687 mock module, to ensure that the state of the vim mock is returned before the
688 next test. That is:
689
690 from ycm.tests.test_utils import MockVimModule
691 from unittest.mock import patch
692
693 # Do this once
694 MockVimModule()
695
696 @patch( 'vim.eval', return_value='test' )
697 @patch( 'vim.command', side_effect=ValueError )
698 def test( vim_command, vim_eval ):
699 # use vim.command via vim_command, e.g.:
700 vim_command.assert_has_calls( ... )
701
702 Failure to use this approach may lead to unexpected failures in other
703 tests."""
704
705 VIM_MOCK.command = MagicMock( side_effect = _MockVimCommand )
706 VIM_MOCK.eval = MagicMock( side_effect = _MockVimEval )
707 VIM_MOCK.error = VimError
708 VIM_MOCK.options = MagicMock()
709 VIM_MOCK.options.__getitem__.side_effect = _MockVimOptions
710 sys.modules[ 'vim' ] = VIM_MOCK
711
712 return VIM_MOCK
713
714
715class VimError( Exception ):

Callers 15

paths_test.pyFile · 0.90
command_test.pyFile · 0.90
__init__.pyFile · 0.90
vimsupport_test.pyFile · 0.90
completion_test.pyFile · 0.90
base_test.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected