run_tests.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python
  2. import os
  3. import subprocess
  4. import os.path as p
  5. import sys
  6. DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) )
  7. DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
  8. DIR_OF_YCMD_THIRD_PARTY = p.join( DIR_OF_THIRD_PARTY, 'ycmd', 'third_party' )
  9. python_path = []
  10. for folder in os.listdir( DIR_OF_THIRD_PARTY ):
  11. python_path.append( p.abspath( p.join( DIR_OF_THIRD_PARTY, folder ) ) )
  12. for folder in os.listdir( DIR_OF_YCMD_THIRD_PARTY ):
  13. # We skip python-future because it needs to be inserted in sys.path AFTER
  14. # the standard library imports but we can't do that with PYTHONPATH because
  15. # the std lib paths are always appended to PYTHONPATH. We do it correctly in
  16. # prod in ycmd/utils.py because we have access to the right sys.path.
  17. # So for dev, we rely on python-future being installed correctly with
  18. # pip install -r test_requirements.txt
  19. #
  20. # Pip knows how to install this correctly so that it doesn't matter where in
  21. # sys.path the path is.
  22. if folder == 'python-future':
  23. continue
  24. python_path.append( p.abspath( p.join( DIR_OF_YCMD_THIRD_PARTY, folder ) ) )
  25. if os.environ.get( 'PYTHONPATH' ):
  26. python_path.append( os.environ[ 'PYTHONPATH' ] )
  27. os.environ[ 'PYTHONPATH' ] = os.pathsep.join( python_path )
  28. sys.path.insert( 1, p.abspath( p.join( DIR_OF_YCMD_THIRD_PARTY,
  29. 'argparse' ) ) )
  30. import argparse
  31. def RunFlake8():
  32. print( 'Running flake8' )
  33. subprocess.check_call( [
  34. 'flake8',
  35. '--select=F,C9',
  36. '--max-complexity=10',
  37. p.join( DIR_OF_THIS_SCRIPT, 'python' )
  38. ] )
  39. def ParseArguments():
  40. parser = argparse.ArgumentParser()
  41. parser.add_argument( '--skip-build', action = 'store_true',
  42. help = 'Do not build ycmd before testing.' )
  43. return parser.parse_known_args()
  44. def BuildYcmdLibs( args ):
  45. if not args.skip_build:
  46. subprocess.check_call( [
  47. sys.executable,
  48. p.join( DIR_OF_THIS_SCRIPT, 'third_party', 'ycmd', 'build.py' )
  49. ] )
  50. def NoseTests( extra_args ):
  51. subprocess.check_call( [
  52. 'nosetests',
  53. '-v',
  54. '-w',
  55. p.join( DIR_OF_THIS_SCRIPT, 'python' )
  56. ] + extra_args )
  57. def Main():
  58. ( parsed_args, extra_args ) = ParseArguments()
  59. RunFlake8()
  60. BuildYcmdLibs( parsed_args )
  61. NoseTests( extra_args )
  62. if __name__ == "__main__":
  63. Main()