# 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 ChangeSpecificOptions( options ):
#   current_options = dict( user_options_store.GetAll() )
#   current_options.update( options )
#   handlers.UpdateUserOptions( current_options )
# 
# 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 )


from ..server_utils import SetUpPythonPath
from .test_utils import ( Setup, BuildRequest, PathToTestFile,
                          ChangeSpecificOptions, StopOmniSharpServer,
                          WaitUntilOmniSharpServerReady )
from webtest import TestApp, AppError
from nose.tools import eq_, with_setup
from hamcrest import ( assert_that, has_item, has_items, has_entry,
                       contains_inanyorder, empty, greater_than )
from ..responses import ( BuildCompletionData, UnknownExtraConf,
                          NoExtraConfDetected )
from .. import handlers
import httplib
import bottle
  completion_data = BuildRequest( contents =  'oo ',
                                  column_num = 3 )

  eq_( [ BuildCompletionData( 'foo' ),
         BuildCompletionData( 'zoo' ) ],
       app.post_json( '/completions', completion_data ).json[ 'completions' ] )


@with_setup( Setup )
def GetCompletions_UltiSnipsCompleter_Works_test():
  app = TestApp( handlers.app )
  event_data = BuildRequest(
    event_name = 'BufferVisit',
    ultisnips_snippets = [
        {'trigger': 'foo', 'description': 'bar'},
        {'trigger': 'zoo', 'description': 'goo'},
    ] )

  app.post_json( '/event_notification', event_data )

  completion_data = BuildRequest( contents =  'oo ',
                                  column_num = 3 )

  eq_( [ BuildCompletionData( 'foo', '<snip> bar' ),
         BuildCompletionData( 'zoo', '<snip> goo' ) ],
       app.post_json( '/completions', completion_data ).json[ 'completions' ] )


@with_setup( Setup )
def GetCompletions_UltiSnipsCompleter_UnusedWhenOffWithOption_test():

# 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 ChangeSpecificOptions( options ):
#   current_options = dict( user_options_store.GetAll() )
#   current_options.update( options )
#   handlers.UpdateUserOptions( current_options )
# 
# 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 )


# Path: third_party/ycmd/ycmd/tests/get_completions_test.py
from ..server_utils import SetUpPythonPath
from .test_utils import ( Setup, BuildRequest, PathToTestFile,
                          ChangeSpecificOptions, StopOmniSharpServer,
                          WaitUntilOmniSharpServerReady )
from webtest import TestApp, AppError
from nose.tools import eq_, with_setup
from hamcrest import ( assert_that, has_item, has_items, has_entry,
                       contains_inanyorder, empty, greater_than )
from ..responses import ( BuildCompletionData, UnknownExtraConf,
                          NoExtraConfDetected )
from .. import handlers
import httplib
import bottle

  completion_data = BuildRequest( contents =  'oo ',
                                  column_num = 3 )

  eq_( [ BuildCompletionData( 'foo' ),
         BuildCompletionData( 'zoo' ) ],
       app.post_json( '/completions', completion_data ).json[ 'completions' ] )


@with_setup( Setup )
def GetCompletions_UltiSnipsCompleter_Works_test():
  app = TestApp( handlers.app )
  event_data = BuildRequest(
    event_name = 'BufferVisit',
    ultisnips_snippets = [
        {'trigger': 'foo', 'description': 'bar'},
        {'trigger': 'zoo', 'description': 'goo'},
    ] )

  app.post_json( '/event_notification', event_data )

  completion_data = BuildRequest( contents =  'oo ',
                                  column_num = 3 )

  eq_( [ BuildCompletionData( 'foo', '<snip> bar' ),
         BuildCompletionData( 'zoo', '<snip> goo' ) ],
       app.post_json( '/completions', completion_data ).json[ 'completions' ] )


@with_setup( Setup )
def GetCompletions_UltiSnipsCompleter_UnusedWhenOffWithOption_test():

  ChangeSpecificOptions( { 'use_ultisnips_completer': False } )