aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Cowie <brad@wand.net.nz>2019-08-14 15:04:29 +1200
committerGitHub <noreply@github.com>2019-08-14 15:04:29 +1200
commit398b7c54ddac271af89cc5cd6690d54807e8d4ca (patch)
treea0b5ee8c332a73f6b8faf473e20324491c559414
parent043741274e7cee39d80a75d6d0f5d8c1d64c9f96 (diff)
parente16b57a362e3d0a5cd4dfbca6557672d53a3575e (diff)
downloadbeka-398b7c54ddac271af89cc5cd6690d54807e8d4ca.tar.gz
beka-398b7c54ddac271af89cc5cd6690d54807e8d4ca.tar.bz2
beka-398b7c54ddac271af89cc5cd6690d54807e8d4ca.zip
Merge pull request #26 from gizmoguy/travisHEADmaster
Convert travis to using jobs.
-rw-r--r--.travis.yml66
-rw-r--r--beka/peering.py5
-rwxr-xr-xrun_tests.sh54
-rw-r--r--test-requirements.txt5
-rwxr-xr-xtest/codecheck/min_pylint.sh23
-rwxr-xr-xtest/codecheck/pylint.sh6
-rwxr-xr-xtest/codecheck/src_files.sh4
-rw-r--r--test/unit/test_beka.py (renamed from test/test_beka.py)0
-rw-r--r--test/unit/test_bgp_message.py (renamed from test/test_bgp_message.py)0
-rw-r--r--test/unit/test_chopper.py (renamed from test/test_chopper.py)0
-rw-r--r--test/unit/test_ip.py (renamed from test/test_ip.py)0
-rw-r--r--test/unit/test_peering.py (renamed from test/test_peering.py)2
-rw-r--r--test/unit/test_state_machine.py (renamed from test/test_state_machine.py)0
-rw-r--r--test/unit/test_timer.py (renamed from test/test_timer.py)0
-rwxr-xr-xtravis/runtests.sh22
15 files changed, 159 insertions, 28 deletions
diff --git a/.travis.yml b/.travis.yml
index 786bae6..85c2388 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,28 +1,44 @@
-dist: trusty
-language: python
-python:
- - '3.6'
-env:
- global:
- - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
- - CC_TEST_REPORTER_ID=e654e7d421925f6944eb7dd9c9440bd948fc0ca5451334a10e4ce244ed7486c4
+dist: xenial
+sudo: required
cache:
pip: true
-install:
- - pip3 install -q -r requirements.txt -r test-requirements.txt
-before_script:
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/cc-test-reporter
- - chmod +x /tmp/cc-test-reporter
- - /tmp/cc-test-reporter before-build
+stages:
+ - test
+ - name: deploy
+ if: repo = faucetsdn/beka AND tag IS present
script:
- - ./run_tests.sh
-after_script:
- - /tmp/cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
-deploy:
- provider: pypi
- user: faucet
- password:
- secure: WzvFx8DXe7mjYlCWyHeUmyhdO5sFrjc064piVrviuxegTnLNhTRyQ9/UnfedBGeMdYwvSlHamh6dLooh40KvcNI706HBHmV/qCsq0x4ZCwtWSBzhhAJgxP741JdXwucwSMG4HDMXN+OBQLnX8Q2vF3zPg3dYGGzzvDZrJH0wdACvTLPnja+jlBna2tEa5X5xl4JLDImhe8N0E9EJYYvvPWModJ41IfSaQIetmdjiUDbZgNdjaY6wypVS9MIoKpMARxpUCKdDry4KVWaPqRybJGrTpM/mWbwr5LDVSer2LTIFqUtRdG4phahEbcco0IbJ7o1CoRldLrwSTHDQ9/m8vKvAThSWs6FYMT09PMSd6Ar+huN0mx6iK7pl/c9xoF9FsIax6D2WW3TID31GpC4th4l86ctGtb1PLuorOVZAVxqiGa/DXlicZFyep0Vb/5vbpd8OlgXYIXOLDoo3pkNxBgY6EhHUVG8wgzB6f2dew/wNsplGYd6ONudNeDW+Sesu8eSHZhsdbYepYwDqHDQTGaTHwm2bkETtmBK+rhj5vspcNMCSjriBmouqRViA4DkPyRu6R9Q/Tb6b0NehpnUFP5PdEzJIC+0buZ+Cv17kVgRcWOaklUhul8ZOO6Jux6NXAa7E/Ag7vO6/jG6v1HiEjLqNwhrc33/O4rJEQB0CrzM=
- on:
- repo: faucetsdn/beka
- tags: true
+ - ./travis/runtests.sh
+matrix:
+ include:
+jobs:
+ include:
+ - stage: test
+ language: python
+ python: 3.5
+ env:
+ - TRAVIS_SHARD=unittest
+ - stage: test
+ language: python
+ python: 3.6
+ env:
+ - TRAVIS_SHARD=unittest
+ - CODE_CHECK=true
+ - CODE_COV=true
+ - stage: test
+ language: python
+ python: 3.7
+ env: TRAVIS_SHARD=unittest
+ - stage: deploy
+ language: python
+ python: 3.6
+ install: skip
+ before_script: skip
+ script: skip
+ after_script: skip
+ deploy:
+ provider: pypi
+ on:
+ tags: true
+ user: faucet
+ password:
+ secure: GJd7A0WGoWmabqcmu+6vAnn9fzG6v6/ux3LFJQPNXM+b2WROP6QuKAIBnA9jBZRAun2rwziR3E0Y6TZZiL24CHLJepLe1CrgtEIxNgNMdcTwPG2j84hyOlVCmRUXRZpkEM/oEt+3GuuQyxMRjRN6juDy1vmflb2MY5IukcYxazm+s4LEDDcBwXU9NLBZhhOrYthBhy1jEAll3wTb83mZngb4a83qvj+uDu+RL9vUBkyzq8YbrJVWzdnn7byJ6WBhps49pxF1rZj5BmH2my50Ql+ZkMHlOcrpUOI0Qe5GrNN/BVNbYNLWf4KqE6klESC0K3eRPbc9g0tsAH6ej1uIYpjisFGc78uBifF+m2oMqBBeM0zKujebZxY6F7uuaWkYtSGhOAoWsY/ppy3UpxkN9wFJoyjkAtU3BGifrPPA9Nrn7MDtf3dUJzU7CMBjfgY2pFpfBwGu9WJ2+gHuaLcjMFH2MiiVJTWScnQ1xQ7GDPsWKvhZj3qrLK+3IrzCTPrjFAkOlgcN8qGcGBXbdg61jD3iF5paOy/TJDRlhw8DmuUkLhl+sbmWYrpnktEZZwf9XkFmYHQZTXbMnfPJd4Ve/6JPHWk3cSsV8sNtdjRrZFPbEI1lohGc1PR7JDELbmXc/Wg/VwEjPQVP91NjYPayCP+PFD0MFV68W/vjbNbqT4c=
diff --git a/beka/peering.py b/beka/peering.py
index 1f323c3..b475f54 100644
--- a/beka/peering.py
+++ b/beka/peering.py
@@ -11,7 +11,12 @@ from .error import SocketClosedError, IdleError
import time
class Peering(object):
+
def __init__(self, state_machine, peer_address, socket, route_handler, error_handler=None):
+ self.chopper = None
+ self.eventlets = None
+ self.parser = None
+ self.packer = None
self.state_machine = state_machine
self.peer_address = peer_address[0]
self.peer_port = peer_address[1]
diff --git a/run_tests.sh b/run_tests.sh
index 405ba71..5dd5eff 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -1 +1,53 @@
-PYTHONPATH=./ pytest --cov=beka --cov-report=xml:coverage.xml test/
+#!/bin/bash
+FILE_NAME=$(readlink -f "$0")
+set -e # quit on error
+
+BEKA_ROOT=$(dirname "$FILE_NAME")
+
+PIP_INSTALL=0
+UNIT_TEST=0
+CODE_CHECK=0
+
+# allow user to skip parts of test
+while getopts "nuz" o $BEKA_TESTS; do
+ case "${o}" in
+ n)
+ CODE_CHECK=1
+ ;;
+ u)
+ UNIT_TEST=1
+ ;;
+ z)
+ PIP_INSTALL=1
+ ;;
+ *)
+ echo "Provided unsupported option. Exiting with code 1"
+ exit 1
+ ;;
+ esac
+done
+
+# ============================= PIP Install =============================
+if [ "$PIP_INSTALL" == 1 ] ; then
+ echo "=============== Installing Pypi Dependencies ================="
+ pip3 install --upgrade --cache-dir=/var/tmp/pip-cache \
+ -r ${BEKA_ROOT}/test-requirements.txt -r ${BEKA_ROOT}/requirements.txt
+fi
+
+# ============================= Unit Tests =============================
+if [ "$UNIT_TEST" == 1 ] ; then
+ echo "=============== Running Unit Tests ================="
+ time env PYTHONPATH=${BEKA_ROOT} pytest -v --cov=beka \
+ ${BEKA_ROOT}/test/unit/test_*.py
+fi
+
+# ============================= Code Checks =============================
+if [ "$CODE_CHECK" == 1 ] ; then
+
+ echo "=============== Running PyType ===================="
+ time PYTHONPATH=${BEKA_ROOT} pytype --config ${BEKA_ROOT}/setup.cfg \
+ ${BEKA_ROOT}/beka/*py
+
+ echo "=============== Running Pylint ===================="
+ time ${BEKA_ROOT}/test/codecheck/pylint.sh
+fi
diff --git a/test-requirements.txt b/test-requirements.txt
index 632b014..1472cd6 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,2 +1,5 @@
+codecov
+pylint
+pytest
pytest-cov
-coverage \ No newline at end of file
+pytype==2019.8.9
diff --git a/test/codecheck/min_pylint.sh b/test/codecheck/min_pylint.sh
new file mode 100755
index 0000000..ebf36ce
--- /dev/null
+++ b/test/codecheck/min_pylint.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+BEKAHOME=`dirname $0`"/../.."
+PYTHONPATH=$BEKAHOME
+MINRATING=8.0
+
+lintfile=`mktemp`.lint
+
+for f in $* ; do
+ f=$(realpath $f)
+ PYTHONPATH=$PYTHONPATH pylint --rcfile=$BEKAHOME/.pylintrc $f > $lintfile
+ rating=`cat $lintfile | grep -ohE "rated at [0-9\.]+" | sed "s/rated at //g"`
+ echo pylint $f: $rating
+ failing=$(bc <<< "$rating < $MINRATING")
+ if [ "$failing" -ne 0 ]; then
+ cat $lintfile
+ echo "$rating below min ($MINRATING), results in $lintfile"
+ exit 1
+ fi
+ rm $lintfile
+done
+
+exit 0
diff --git a/test/codecheck/pylint.sh b/test/codecheck/pylint.sh
new file mode 100755
index 0000000..b76ae61
--- /dev/null
+++ b/test/codecheck/pylint.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+CURR_DIR=`dirname $0`
+CHEWIEHOME=$CURR_DIR"/../.."
+SRCFILES="$CHEWIEHOME/test/codecheck/src_files.sh"
+$SRCFILES | xargs -n 1 -P 8 $CURR_DIR/min_pylint.sh || exit 1
+exit 0 \ No newline at end of file
diff --git a/test/codecheck/src_files.sh b/test/codecheck/src_files.sh
new file mode 100755
index 0000000..ca661cf
--- /dev/null
+++ b/test/codecheck/src_files.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+BEKAHOME=`dirname $0`"/../.."
+for i in beka test ; do find $BEKAHOME/$i/ -type f -name '[a-z]*.py' ; done
diff --git a/test/test_beka.py b/test/unit/test_beka.py
index 066fd0a..066fd0a 100644
--- a/test/test_beka.py
+++ b/test/unit/test_beka.py
diff --git a/test/test_bgp_message.py b/test/unit/test_bgp_message.py
index e4fe688..e4fe688 100644
--- a/test/test_bgp_message.py
+++ b/test/unit/test_bgp_message.py
diff --git a/test/test_chopper.py b/test/unit/test_chopper.py
index 2617dd6..2617dd6 100644
--- a/test/test_chopper.py
+++ b/test/unit/test_chopper.py
diff --git a/test/test_ip.py b/test/unit/test_ip.py
index 122a322..122a322 100644
--- a/test/test_ip.py
+++ b/test/unit/test_ip.py
diff --git a/test/test_peering.py b/test/unit/test_peering.py
index d8e2d14..534d5c3 100644
--- a/test/test_peering.py
+++ b/test/unit/test_peering.py
@@ -63,4 +63,4 @@ class PeeringTestCase(unittest.TestCase):
call(self.peering.kick_timers),
call(self.peering.receive_messages),
])
- GreenPool().waitall.assert_called_once()
+ assert GreenPool().waitall.call_count == 1
diff --git a/test/test_state_machine.py b/test/unit/test_state_machine.py
index d0c2484..d0c2484 100644
--- a/test/test_state_machine.py
+++ b/test/unit/test_state_machine.py
diff --git a/test/test_timer.py b/test/unit/test_timer.py
index 6fbc0d8..6fbc0d8 100644
--- a/test/test_timer.py
+++ b/test/unit/test_timer.py
diff --git a/travis/runtests.sh b/travis/runtests.sh
new file mode 100755
index 0000000..65f7e33
--- /dev/null
+++ b/travis/runtests.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+set -e # quit on error
+
+# See https://docs.travis-ci.com/user/environment-variables/#convenience-variables
+echo TRAVIS_BRANCH: $TRAVIS_BRANCH
+echo TRAVIS_COMMIT: $TRAVIS_COMMIT
+
+if [ "$TRAVIS_SHARD" == "unittest" ]; then
+ env BEKA_TESTS="-z" ./run_tests.sh
+
+ env BEKA_TESTS="-u" ./run_tests.sh
+
+ if [ "$CODE_COV" == "true" ]; then
+ codecov || true
+ fi
+
+ if [ "$CODE_CHECK" == "true" ]; then
+ env BEKA_TESTS="-n" ./run_tests.sh
+ fi
+
+ exit 0
+fi