diff --git a/ycmd/tests/cs/debug_info_test.py b/ycmd/tests/cs/debug_info_test.py index 8f6258ffbd..ceb3364a05 100644 --- a/ycmd/tests/cs/debug_info_test.py +++ b/ycmd/tests/cs/debug_info_test.py @@ -17,12 +17,19 @@ from hamcrest import ( assert_that, contains_exactly, empty, equal_to, has_entries, has_entry, instance_of ) + +from subprocess import Popen as _mockable_popen + from unittest.mock import patch from unittest import TestCase +from ycmd.completers.cs.cs_completer import PATH_TO_OMNISHARP_ROSLYN_BINARY from ycmd.completers.cs.hook import GetCompleter from ycmd.tests.cs import setUpModule, tearDownModule # noqa -from ycmd.tests.cs import PathToTestFile, SharedYcmd +from ycmd.tests.cs import ( PathToTestFile, + SharedYcmd, + IsolatedYcmd, + WrapOmniSharpServer ) from ycmd.tests.test_utils import ( BuildRequest, WaitUntilCompleterServerReady ) from ycmd import user_options_store @@ -197,14 +204,22 @@ def test_GetCompleter_RoslynNotFound( *args ): assert_that( not GetCompleter( user_options_store.GetAll() ) ) - @patch( 'ycmd.completers.cs.cs_completer.FindExecutableWithFallback', - wraps = lambda x, fb: x if x == 'roslyn' else fb ) + def _RoslynFromUserOption_popen_mock(*args, **kwargs): + assert_that( args[0][1], equal_to( 'my_roslyn.exe' ) ) + args[0][1] = PATH_TO_OMNISHARP_ROSLYN_BINARY + return _mockable_popen(*args, **kwargs) + @patch( 'os.path.isfile', return_value = True ) - def test_GetCompleter_RoslynFromUserOption( *args ): - user_options = user_options_store.GetAll().copy( - roslyn_binary_path = 'roslyn' ) - assert_that( GetCompleter( user_options )._roslyn_path, - equal_to( 'roslyn' ) ) + @patch( 'subprocess.Popen', wraps = _RoslynFromUserOption_popen_mock ) + @IsolatedYcmd( { 'roslyn_binary_path': 'my_roslyn.exe' } ) + def test_GetCompleter_RoslynFromUserOption( self, app, *args ): + filepath = PathToTestFile( 'testy', 'Program.cs' ) + contents = ReadFile( filepath ) + import subprocess + with WrapOmniSharpServer( app, filepath ): + request = BuildRequest( filepath = filepath, filetype = 'cs' ) + response = app.post_json( '/debug_info', request ) + subprocess.Popen.assert_called() @patch( 'os.path.isfile', return_value = False )