| |
@@ -0,0 +1,80 @@
|
| |
+ #!/usr/bin/bash
|
| |
+
|
| |
+ which virtualenv > /dev/null 2>&1
|
| |
+ if [[ $? -ne 0 ]]; then
|
| |
+ echo "Please install python virtualenv package before running the test"
|
| |
+ exit 1
|
| |
+ fi
|
| |
+
|
| |
+ function run() {
|
| |
+ # Function to show the command line it will execute,
|
| |
+ # otherwise it only shows command output
|
| |
+ if [[ -z $1 ]]; then
|
| |
+ echo "run() requires command as argument"
|
| |
+ return 1
|
| |
+ fi
|
| |
+ echo "Running: $1"
|
| |
+ eval $1
|
| |
+ return $?
|
| |
+ }
|
| |
+
|
| |
+ test_path=$(readlink -f $0)
|
| |
+ tests_dir=$(dirname $test_path)
|
| |
+ # Use the directory above tests to search for python scripts
|
| |
+ source_dir=$(dirname $tests_dir)
|
| |
+
|
| |
+ echo "Searching for python scripts under ${source_dir}..."
|
| |
+ all_files=$(find $source_dir -type f -not -path "*.git*")
|
| |
+ python_files=""
|
| |
+ # Check what files are python scripts
|
| |
+ for my_file in $all_files; do
|
| |
+ file -i ${my_file} | grep -q x-python
|
| |
+ if [[ $? -eq 0 || ${my_file: -3} == ".py" ]]; then
|
| |
+ python_files+="${my_file} "
|
| |
+ fi
|
| |
+ done
|
| |
+
|
| |
+ error=0
|
| |
+
|
| |
+ virt_env_dir=$(mktemp -d)
|
| |
+ if [[ -z $virt_env_dir ]]; then
|
| |
+ echo "FAIL: Could not create tmp directory"
|
| |
+ exit 1;
|
| |
+ fi
|
| |
+
|
| |
+ virtualenv ${virt_env_dir}
|
| |
+ source ${virt_env_dir}/bin/activate --system-site-packages
|
| |
+
|
| |
+ pip install inspektor
|
| |
+ if [[ $? -ne 0 ]]; then
|
| |
+ deactivate
|
| |
+ echo "FAIL: Could not install inspektor"
|
| |
+ rm -rf ${virt_env_dir}
|
| |
+ exit 1
|
| |
+ fi
|
| |
+
|
| |
+ plint_enable="W0611,W0612,W0622"
|
| |
+ # Disabling E0611, because pylint has problems importing distutils modules on virtualenv
|
| |
+ plint_disable="W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611"
|
| |
+
|
| |
+ for pyfile in $python_files; do
|
| |
+ run "inspekt indent ${pyfile}"
|
| |
+ error=$((error + $?))
|
| |
+ run "inspekt lint --enable $plint_enable --disable $plint_disable ${pyfile}"
|
| |
+ error=$((error + $?))
|
| |
+ run "pycodestyle --max-line-length=120 ${pyfile}"
|
| |
+ error=$((error + $?))
|
| |
+ done
|
| |
+
|
| |
+ deactivate
|
| |
+
|
| |
+ if [[ -z "$KEEP_VIRT_ENV" ]]; then
|
| |
+ rm -rf ${virt_env_dir}
|
| |
+ fi
|
| |
+
|
| |
+ if [[ ${error} -ne 0 ]]; then
|
| |
+ echo "FAIL: problem with python syntax"
|
| |
+ exit 1
|
| |
+ fi
|
| |
+
|
| |
+ exit 0
|
| |
Current results: