# Path: third_party/ycmd/ycmd/tests/test_utils.py
# def Setup():
#   handlers.SetServerStateToDefaults()
# 
# def BuildRequest( **kwargs ):
#   filepath = kwargs[ 'filepath' ] if 'filepath' in kwargs else '/foo'
#   contents = kwargs[ 'contents' ] if 'contents' in kwargs else ''
#   filetype = kwargs[ 'filetype' ] if 'filetype' in kwargs else 'foo'
# 
#   request = {
#     'line_num': 1,
#     'column_num': 1,
#     'filepath': filepath,
#     'file_data': {
#       filepath: {
#         'contents': contents,
#         'filetypes': [ filetype ]
#       }
#     }
#   }
# 
#   for key, value in kwargs.iteritems():
#     if key in [ 'contents', 'filetype', 'filepath' ]:
#       continue
#     request[ key ] = value
# 
#   return request
# 
# def PathToTestFile( test_basename ):
#   return os.path.join( PathToTestDataDir(), test_basename )
# 
# def StopOmniSharpServer( app ):
#   app.post_json( '/run_completer_command',
#                  BuildRequest( completer_target = 'filetype_default',
#                                command_arguments = ['StopServer'],
#                                filetype = 'cs' ) )
# 
# def WaitUntilOmniSharpServerReady( app ):
#   while True:
#     result = app.get( '/ready', { 'include_subservers': 1 } ).json
#     if result:
#       break
#     time.sleep( 0.2 )
# 
# def ChangeSpecificOptions( options ):
#   current_options = dict( user_options_store.GetAll() )
#   current_options.update( options )
#   handlers.UpdateUserOptions( current_options )


from ..server_utils import SetUpPythonPath
from .test_utils import ( Setup, BuildRequest, PathToTestFile, StopOmniSharpServer,
                          WaitUntilOmniSharpServerReady, ChangeSpecificOptions )
from webtest import TestApp, AppError
from nose.tools import eq_, with_setup
from .. import handlers
import bottle
import re
import os.path
                            column_num = 13,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  try:
    app.post_json( '/run_completer_command', goto_data ).json
    raise Exception("Expected a 'No implementations found' error")
  except AppError as e:
    if 'No implementations found' in str(e):
      pass
    else:
      raise
  finally:
    StopOmniSharpServer( app )


@with_setup( Setup )
def RunCompleterCommand_GoToImplementation_CsCompleter_InvalidLocation_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy/GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )

# Path: third_party/ycmd/ycmd/tests/test_utils.py
# def Setup():
#   handlers.SetServerStateToDefaults()
# 
# def BuildRequest( **kwargs ):
#   filepath = kwargs[ 'filepath' ] if 'filepath' in kwargs else '/foo'
#   contents = kwargs[ 'contents' ] if 'contents' in kwargs else ''
#   filetype = kwargs[ 'filetype' ] if 'filetype' in kwargs else 'foo'
# 
#   request = {
#     'line_num': 1,
#     'column_num': 1,
#     'filepath': filepath,
#     'file_data': {
#       filepath: {
#         'contents': contents,
#         'filetypes': [ filetype ]
#       }
#     }
#   }
# 
#   for key, value in kwargs.iteritems():
#     if key in [ 'contents', 'filetype', 'filepath' ]:
#       continue
#     request[ key ] = value
# 
#   return request
# 
# def PathToTestFile( test_basename ):
#   return os.path.join( PathToTestDataDir(), test_basename )
# 
# def StopOmniSharpServer( app ):
#   app.post_json( '/run_completer_command',
#                  BuildRequest( completer_target = 'filetype_default',
#                                command_arguments = ['StopServer'],
#                                filetype = 'cs' ) )
# 
# def WaitUntilOmniSharpServerReady( app ):
#   while True:
#     result = app.get( '/ready', { 'include_subservers': 1 } ).json
#     if result:
#       break
#     time.sleep( 0.2 )
# 
# def ChangeSpecificOptions( options ):
#   current_options = dict( user_options_store.GetAll() )
#   current_options.update( options )
#   handlers.UpdateUserOptions( current_options )


# Path: third_party/ycmd/ycmd/tests/subcommands_test.py
from ..server_utils import SetUpPythonPath
from .test_utils import ( Setup, BuildRequest, PathToTestFile, StopOmniSharpServer,
                          WaitUntilOmniSharpServerReady, ChangeSpecificOptions )
from webtest import TestApp, AppError
from nose.tools import eq_, with_setup
from .. import handlers
import bottle
import re
import os.path

                            column_num = 13,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  try:
    app.post_json( '/run_completer_command', goto_data ).json
    raise Exception("Expected a 'No implementations found' error")
  except AppError as e:
    if 'No implementations found' in str(e):
      pass
    else:
      raise
  finally:
    StopOmniSharpServer( app )


@with_setup( Setup )
def RunCompleterCommand_GoToImplementation_CsCompleter_InvalidLocation_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy/GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )

  WaitUntilOmniSharpServerReady( app )