Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaszews committed Dec 9, 2023
1 parent 5588025 commit d7eca35
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions ycmd/tests/cs/debug_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@

from hamcrest import ( assert_that, contains_exactly, empty, equal_to,
has_entries, has_entry, instance_of )
from unittest.mock import patch

from subprocess import Popen as _mockable_popen

from unittest.mock import patch, ANY
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
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit d7eca35

Please sign in to comment.