# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ycmd.  If not, see <http://www.gnu.org/licenses/>.

import inspect
from unittest.mock import patch

from hamcrest import (assert_that, calling, equal_to, has_length, has_property,
                      none, raises, same_instance)
from ycmd import extra_conf_store
from ycmd.responses import UnknownExtraConf
from ycmd.tests import IsolatedYcmd, PathToTestFile
from ycmd.tests.test_utils import TemporarySymlink, UnixOnly, WindowsOnly

GLOBAL_EXTRA_CONF = PathToTestFile('extra_conf', 'global_extra_conf.py')
ERRONEOUS_EXTRA_CONF = PathToTestFile('extra_conf', 'erroneous_extra_conf.py')
NO_EXTRA_CONF = PathToTestFile('extra_conf', 'no_extra_conf.py')
PROJECT_EXTRA_CONF = PathToTestFile('extra_conf', 'project',
                                    '.ycm_extra_conf.py')


@IsolatedYcmd()
def ExtraConfStore_ModuleForSourceFile_UnknownExtraConf_test(app):
    filename = PathToTestFile('extra_conf', 'project', 'some_file')
    assert_that(
        calling(extra_conf_store.ModuleForSourceFile).with_args(filename),
        raises(UnknownExtraConf, 'Found .*\\.ycm_extra_conf\\.py\\. Load?'))


@IsolatedYcmd({'confirm_extra_conf': 0})
def ExtraConfStore_ModuleForSourceFile_UnknownExtraConf_test(app):
    filename = PathToTestFile('extra_conf', 'project', 'some_file')
    assert_that(
        calling(extra_conf_store.ModuleForSourceFile).with_args(filename),
        raises(UnknownExtraConf, 'Found .*\\.ycm_extra_conf\\.py\\. Load?'))
Ejemplo n.º 3
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
# Not installing aliases from python-future; it's unreliable and slow.
from builtins import *  # noqa

from hamcrest import assert_that, calling, equal_to, raises
from mock import patch

from ycmd.server_utils import GetStandardLibraryIndexInSysPath
from ycmd.tests import PathToTestFile


@patch('sys.path', [
    PathToTestFile('python-future', 'some', 'path'),
    PathToTestFile('python-future', 'another', 'path')
])
def GetStandardLibraryIndexInSysPath_ErrorIfNoStandardLibrary_test(*args):
    assert_that(
        calling(GetStandardLibraryIndexInSysPath),
        raises(RuntimeError,
               'Could not find standard library path in Python path.'))


@patch('sys.path', [
    PathToTestFile('python-future', 'some', 'path'),
    PathToTestFile('python-future', 'standard_library'),
    PathToTestFile('python-future', 'another', 'path')
])
def GetStandardLibraryIndexInSysPath_FindFullStandardLibrary_test(*args):
Ejemplo n.º 4
0
  ok_( PathToNearestThirdPartyFolder( os.path.abspath( __file__ ) ) )


def PathToNearestThirdPartyFolder_Failure_test():
  ok_( not PathToNearestThirdPartyFolder( os.path.expanduser( '~' ) ) )


def AddNearestThirdPartyFoldersToSysPath_Failure_test():
  assert_that(
    calling( AddNearestThirdPartyFoldersToSysPath ).with_args(
      os.path.expanduser( '~' ) ),
    raises( RuntimeError, '.*third_party folder.*' ) )


@patch( 'sys.path', [
  PathToTestFile( 'python-future', 'some', 'path' ),
  PathToTestFile( 'python-future', 'standard_library' ),
  PathToTestFile( 'python-future', 'standard_library', 'site-packages' ),
  PathToTestFile( 'python-future', 'another', 'path' ) ] )
def AddNearestThirdPartyFoldersToSysPath_FutureAfterStandardLibrary_test(
  *args ):
  AddNearestThirdPartyFoldersToSysPath( __file__ )
  assert_that( sys.path[ : len( THIRD_PARTY_FOLDERS ) ], contains_inanyorder(
    *THIRD_PARTY_FOLDERS
  ) )
  assert_that( sys.path[ len( THIRD_PARTY_FOLDERS ) : ], contains(
    PathToTestFile( 'python-future', 'some', 'path' ),
    PathToTestFile( 'python-future', 'standard_library' ),
    os.path.join( DIR_OF_THIRD_PARTY, 'python-future', 'src' ),
    PathToTestFile( 'python-future', 'standard_library', 'site-packages' ),
    PathToTestFile( 'python-future', 'another', 'path' )
Ejemplo n.º 5
0
def MiscHandlers_IgnoreExtraConfFile_AlwaysJsonResponse_test( app ):
  filepath = PathToTestFile( 'extra_conf', 'project', '.ycm_extra_conf.py' )
  extra_conf_data = BuildRequest( filepath = filepath )

  assert_that( app.post_json( '/ignore_extra_conf_file', extra_conf_data ).json,
               equal_to( True ) )
Ejemplo n.º 6
0
def RemoveIfExists_DoesntExist_test():
    tempfile = PathToTestFile('remove-if-exists')
    ok_(not os.path.exists(tempfile))
    utils.RemoveIfExists(tempfile)
    ok_(not os.path.exists(tempfile))
Ejemplo n.º 7
0
def RemoveIfExists_Exists_test():
    tempfile = PathToTestFile('remove-if-exists')
    open(tempfile, 'a').close()
    ok_(os.path.exists(tempfile))
    utils.RemoveIfExists(tempfile)
    ok_(not os.path.exists(tempfile))
Ejemplo n.º 8
0
def FilterUnchangedTagFiles_KeepGoodFiles_test():
    ident_completer = IdentifierCompleter(DefaultOptions())
    tag_file = PathToTestFile('basic.tags')
    eq_([tag_file], list(ident_completer._FilterUnchangedTagFiles([tag_file])))
Ejemplo n.º 9
0
def ExtraConfStore_ModuleForSourceFile_Blacklisted_test( app ):
  filename = PathToTestFile( 'extra_conf', 'project', 'some_file' )
  assert_that( extra_conf_store.ModuleForSourceFile( filename ), none() )