2015-04-25 16:30:32 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-12-11 01:20:26 -05:00
|
|
|
import argparse
|
|
|
|
import glob
|
2015-04-25 16:30:32 -04:00
|
|
|
import os
|
|
|
|
import os.path as p
|
2018-12-11 01:20:26 -05:00
|
|
|
import subprocess
|
2015-04-25 16:30:32 -04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) )
|
|
|
|
DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
|
|
|
|
|
2018-12-11 01:20:26 -05:00
|
|
|
# We don't include python-future (not to be confused with pythonfutures) because
|
|
|
|
# it needs to be inserted in sys.path AFTER the standard library imports but we
|
|
|
|
# can't do that with PYTHONPATH because the std lib paths are always appended to
|
|
|
|
# PYTHONPATH. We do it correctly inside Vim because we have access to the right
|
|
|
|
# sys.path. So for dev, we rely on python-future being installed correctly with
|
|
|
|
#
|
|
|
|
# pip install -r python/test_requirements.txt
|
|
|
|
#
|
|
|
|
# Pip knows how to install this correctly so that it doesn't matter where in
|
|
|
|
# sys.path the path is.
|
|
|
|
python_path = [ p.join( DIR_OF_THIRD_PARTY, 'pythonfutures' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests-futures' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'chardet' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'certifi' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'idna' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'requests' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'urllib3', 'src' ),
|
|
|
|
p.join( DIR_OF_THIRD_PARTY, 'ycmd' ) ]
|
2015-04-25 16:30:32 -04:00
|
|
|
if os.environ.get( 'PYTHONPATH' ):
|
|
|
|
python_path.append( os.environ[ 'PYTHONPATH' ] )
|
|
|
|
os.environ[ 'PYTHONPATH' ] = os.pathsep.join( python_path )
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
|
2015-04-25 16:30:32 -04:00
|
|
|
def RunFlake8():
|
|
|
|
print( 'Running flake8' )
|
2018-11-23 05:39:35 -05:00
|
|
|
args = [ sys.executable,
|
|
|
|
'-m',
|
|
|
|
'flake8',
|
|
|
|
p.join( DIR_OF_THIS_SCRIPT, 'python' ) ]
|
|
|
|
root_dir_scripts = glob.glob( p.join( DIR_OF_THIS_SCRIPT, '*.py' ) )
|
|
|
|
args.extend( root_dir_scripts )
|
|
|
|
subprocess.check_call( args )
|
2015-04-25 16:30:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
def ParseArguments():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument( '--skip-build', action = 'store_true',
|
2016-10-11 21:18:08 -04:00
|
|
|
help = 'Do not build ycmd before testing' )
|
|
|
|
parser.add_argument( '--coverage', action = 'store_true',
|
|
|
|
help = 'Enable coverage report' )
|
2016-04-24 09:20:15 -04:00
|
|
|
parser.add_argument( '--no-flake8', action = 'store_true',
|
|
|
|
help = 'Do not run flake8' )
|
2015-04-25 16:30:32 -04:00
|
|
|
|
2016-10-11 21:18:08 -04:00
|
|
|
parsed_args, nosetests_args = parser.parse_known_args()
|
|
|
|
|
|
|
|
if 'COVERAGE' in os.environ:
|
|
|
|
parsed_args.coverage = ( os.environ[ 'COVERAGE' ] == 'true' )
|
|
|
|
|
|
|
|
return parsed_args, nosetests_args
|
2015-04-25 16:30:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
def BuildYcmdLibs( args ):
|
|
|
|
if not args.skip_build:
|
|
|
|
subprocess.check_call( [
|
|
|
|
sys.executable,
|
|
|
|
p.join( DIR_OF_THIS_SCRIPT, 'third_party', 'ycmd', 'build.py' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
|
2016-10-11 21:18:08 -04:00
|
|
|
def NoseTests( parsed_args, extra_nosetests_args ):
|
|
|
|
# Always passing --with-id to nosetests enables non-surprising usage of
|
|
|
|
# its --failed flag.
|
|
|
|
nosetests_args = [ '-v', '--with-id' ]
|
|
|
|
|
|
|
|
if parsed_args.coverage:
|
|
|
|
nosetests_args += [ '--with-coverage',
|
|
|
|
'--cover-erase',
|
|
|
|
'--cover-package=ycm',
|
|
|
|
'--cover-html' ]
|
|
|
|
|
|
|
|
if extra_nosetests_args:
|
|
|
|
nosetests_args.extend( extra_nosetests_args )
|
|
|
|
else:
|
|
|
|
nosetests_args.append( p.join( DIR_OF_THIS_SCRIPT, 'python' ) )
|
|
|
|
|
2018-01-24 11:54:57 -05:00
|
|
|
subprocess.check_call( [ sys.executable, '-m', 'nose' ] + nosetests_args )
|
2015-04-25 16:30:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
def Main():
|
2016-10-11 21:18:08 -04:00
|
|
|
( parsed_args, nosetests_args ) = ParseArguments()
|
2016-04-24 09:20:15 -04:00
|
|
|
if not parsed_args.no_flake8:
|
|
|
|
RunFlake8()
|
2015-04-25 16:30:32 -04:00
|
|
|
BuildYcmdLibs( parsed_args )
|
2016-10-11 21:18:08 -04:00
|
|
|
NoseTests( parsed_args, nosetests_args )
|
2015-04-25 16:30:32 -04:00
|
|
|
|
2018-11-23 05:39:35 -05:00
|
|
|
|
2015-04-25 16:30:32 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
Main()
|