Browse Source

Convert run_tests script to python

Translate the run_tests.sh script in python to make it platform independent.
micbou 10 years ago
parent
commit
c99aa85de2
2 changed files with 66 additions and 43 deletions
  1. 66 0
      run_tests.py
  2. 0 43
      run_tests.sh

+ 66 - 0
run_tests.py

@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import os
+import subprocess
+import os.path as p
+import sys
+import argparse
+
+DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) )
+DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
+DIR_OF_YCMD_THIRD_PARTY = p.join( DIR_OF_THIRD_PARTY, 'ycmd', 'third_party' )
+
+python_path = []
+for folder in os.listdir( DIR_OF_THIRD_PARTY ):
+  python_path.append( p.abspath( p.join( DIR_OF_THIRD_PARTY, folder ) ) )
+for folder in os.listdir( DIR_OF_YCMD_THIRD_PARTY ):
+  python_path.append( p.abspath( p.join( DIR_OF_YCMD_THIRD_PARTY, folder ) ) )
+if os.environ.get( 'PYTHONPATH' ):
+  python_path.append( os.environ[ 'PYTHONPATH' ] )
+os.environ[ 'PYTHONPATH' ] = os.pathsep.join( python_path )
+
+sys.path.insert( 1, p.abspath( p.join( DIR_OF_THIRD_PARTY, 'argparse' ) ) )
+
+
+def RunFlake8():
+  print( 'Running flake8' )
+  subprocess.check_call( [
+    'flake8',
+    '--select=F,C9',
+    '--max-complexity=10',
+    p.join( DIR_OF_THIS_SCRIPT, 'python' )
+  ] )
+
+
+def ParseArguments():
+  parser = argparse.ArgumentParser()
+  parser.add_argument( '--skip-build', action = 'store_true',
+                       help = 'Do not build ycmd before testing.' )
+
+  return parser.parse_args()
+
+
+def BuildYcmdLibs( args ):
+  if not args.skip_build:
+    subprocess.check_call( [
+      sys.executable,
+      p.join( DIR_OF_THIS_SCRIPT, 'third_party', 'ycmd', 'build.py' )
+    ] )
+
+
+def NoseTests():
+  subprocess.check_call( [
+    'nosetests',
+    '-v',
+    p.join( DIR_OF_THIS_SCRIPT, 'python' )
+  ] )
+
+
+def Main():
+  parsed_args = ParseArguments()
+  RunFlake8()
+  BuildYcmdLibs( parsed_args )
+  NoseTests()
+
+if __name__ == "__main__":
+  Main()

+ 0 - 43
run_tests.sh

@@ -1,43 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-function usage {
-  echo "Usage: $0 [--skip-build]"
-  exit 0
-}
-
-flake8 --select=F,C9 --max-complexity=10 "${SCRIPT_DIR}/python"
-skip_build=false
-
-for flag in $@; do
-  case "$flag" in
-    --skip-build)
-      skip_build=true
-      ;;
-    *)
-      usage
-      ;;
-  esac
-done
-
-if ! $skip_build; then
-    "${SCRIPT_DIR}/third_party/ycmd/build.py"
-fi
-
-for directory in "${SCRIPT_DIR}"/third_party/*; do
-  if [ -d "${directory}" ]; then
-    export PYTHONPATH=${directory}:$PYTHONPATH
-  fi
-done
-
-
-for directory in "${SCRIPT_DIR}"/third_party/ycmd/third_party/*; do
-  if [ -d "${directory}" ]; then
-    export PYTHONPATH=${directory}:$PYTHONPATH
-  fi
-done
-
-nosetests -v "${SCRIPT_DIR}/python"