#160 python syntax test
Merged 6 years ago by astepano. Opened 6 years ago by bgoncalv.
bgoncalv/standard-test-roles python-syntax-test  into  master

file modified
+10
@@ -94,6 +94,16 @@ 

                      '''

              }

          }

+         stage('Tests') {

+             steps {

+                 sh '''

+                     set -efux

+                     # Install test dependencies

+                     yum install -y gcc python-devel redhat-rpm-config python-virtualenv

+                     ./tests/python-syntax.sh

+                 '''

+             }

+         }

          stage('SRPM') {

              steps {

                  sh '''

@@ -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:

Running: inspekt indent /root/standard-test-roles/inventory/standard-inventory-docker
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/inventory/standard-inventory-docker
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/inventory/standard-inventory-docker
Running: inspekt indent /root/standard-test-roles/inventory/standard-inventory-rpm
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/inventory/standard-inventory-rpm
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/inventory/standard-inventory-rpm
Running: inspekt indent /root/standard-test-roles/inventory/standard-inventory-local
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/inventory/standard-inventory-local
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/inventory/standard-inventory-local
Running: inspekt indent /root/standard-test-roles/inventory/standard-inventory-vagrant
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/inventory/standard-inventory-vagrant
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/inventory/standard-inventory-vagrant
Running: inspekt indent /root/standard-test-roles/inventory/standard-inventory-qcow2
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/inventory/standard-inventory-qcow2
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/inventory/standard-inventory-qcow2
Running: inspekt indent /root/standard-test-roles/roles/standard-test-beakerlib/files/rpm.py
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/roles/standard-test-beakerlib/files/rpm.py
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/roles/standard-test-beakerlib/files/rpm.py
Running: inspekt indent /root/standard-test-roles/scripts/merge-standard-inventory
Indentation check PASS
Running: inspekt lint --enable W0611,W0612,W0622 --disable W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611 /root/standard-test-roles/scripts/merge-standard-inventory
Pylint disabled: W,R,C,E1002,E1101,E1103,E1120,F0401,I0011,E0611
Pylint enabled : W0611,W0612,W0622
Using config file /dev/null
Syntax check PASS
Running: pycodestyle --max-line-length=120 /root/standard-test-roles/scripts/merge-standard-inventory

I'm not sure if ./tests/install_test_dependencies.sh should be called on Jenkinsfile...

rebased onto c4ca841731d20cbf8c916fcd56e708bbaf49ff8b

6 years ago

Hi, let's

  1. remove this file completely.
  2. change dnf to yum tester is based in Centos: https://pagure.io/standard-test-roles/blob/master/f/ci/Dockerfile#_1
  3. Add this line just above ./tests/python-syntax.sh line at ci/Jenkinsfile
  1. Why remove the file, isn't good to have a file that we can run to install all dependencies required to run the tests?

  2. Okay, I will update it.

  3. Sure, I can do it.

It would be very cool if inform user what is source_dir (simple:
echo "Proceed dir $source_dir" (something like this)

Very good, but not enough

file -i /usr/lib/python2.7/site-packages/pexpect.py
/usr/lib/python2.7/site-packages/pexpect.py: text/plain; charset=us-ascii

There are more files that ends in .py but not are 'x-python' type.

I propose add to checking list also all files that ends in .py

What is purpose run command ?
if you remove it will be the same

rebased onto 20226ec

6 years ago

Thanks for the feedback, I've updated it with your suggestions.

pretty please pagure-ci rebuild

Commit 2b4331b fixes this pull-request

Pull-Request has been merged by astepano

6 years ago

Pull-Request has been merged by astepano

6 years ago