tests: add run-tests script, plug it into travis

Also, replace subproces.call with a mockup, as notify-send is not
available on travis.
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-20 13:05:54 +02:00
parent 5dfcf06ef4
commit 07be216a0d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
7 changed files with 62 additions and 1 deletions

3
.coveragerc Normal file
View File

@ -0,0 +1,3 @@
[run]
source = qubesagent
omit = qubesagent/test*

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ deb/*
*.pyo
*~
*.o
.coverage
*.egg-info

View File

@ -1,6 +1,7 @@
sudo: required
dist: trusty
language: generic
language: python
python: '3.5'
install: git clone https://github.com/QubesOS/qubes-builder ~/qubes-builder
script: ~/qubes-builder/scripts/travis-build
env:
@ -8,3 +9,22 @@ env:
- DISTS_VM=fc24 USE_QUBES_REPO_VERSION=3.2 USE_QUBES_REPO_TESTING=1
- DISTS_VM=jessie USE_QUBES_REPO_VERSION=3.2 USE_QUBES_REPO_TESTING=1
- DISTS_VM=stretch USE_QUBES_REPO_VERSION=3.2 USE_QUBES_REPO_TESTING=1
jobs:
include:
- python: '3.5'
install: pip install --quiet -r ci/requirements.txt
env: TESTS_ONLY=1
script:
- ./run-tests
after_success:
- codecov
- stage: deploy
python: '3.5'
env: DIST_DOM0=fc25 TESTS_ONLY=
script: ~/qubes-builder/scripts/travis-deploy
branches:
except:
- /.*_.*/

6
ci/requirements.txt Normal file
View File

@ -0,0 +1,6 @@
# WARNING: those requirements are used only for travis-ci.org
# they SHOULD NOT be used under normal conditions; use system package manager
docutils
pylint
codecov
python-daemon

View File

@ -1,6 +1,7 @@
import logging
import operator
from unittest import TestCase
from unittest.mock import patch
import qubesagent.firewall
@ -150,6 +151,11 @@ class TestIptablesWorker(TestCase):
def setUp(self):
super(TestIptablesWorker, self).setUp()
self.obj = IptablesWorker()
self.subprocess_patch = patch('subprocess.call')
self.subprocess_mock = self.subprocess_patch.start()
def tearDown(self):
self.subprocess_patch.stop()
def test_000_chain_for_addr(self):
self.assertEqual(
@ -296,6 +302,11 @@ class TestNftablesWorker(TestCase):
def setUp(self):
super(TestNftablesWorker, self).setUp()
self.obj = NftablesWorker()
self.subprocess_patch = patch('subprocess.call')
self.subprocess_mock = self.subprocess_patch.start()
def tearDown(self):
self.subprocess_patch.stop()
def test_000_chain_for_addr(self):
self.assertEqual(
@ -465,6 +476,12 @@ class TestFirewallWorker(TestCase):
self.obj.qdb.entries[
'/qubes-firewall/{}/{}'.format(addr, key)] = value
self.subprocess_patch = patch('subprocess.call')
self.subprocess_mock = self.subprocess_patch.start()
def tearDown(self):
self.subprocess_patch.stop()
def test_read_rules(self):
expected_rules1 = [
{'proto': 'tcp', 'dstports': '80-80', 'action': 'drop'},

13
run-tests Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
: "${PYTHON:=python3}"
: "${ROOTDIR:=.}"
: "${TESTPYTHONPATH:=$ROOTDIR/test-packages}"
PYTHONPATH="${TESTPYTHONPATH}:${PYTHONPATH}"
export PYTHONPATH
[ -r version ] || ln -s ${ROOTDIR}/version ./
[ -r setup.py ] || ln -s ${ROOTDIR}/setup.py ./
"${PYTHON}" ./setup.py egg_info --egg-base "${TESTPYTHONPATH}"
"${PYTHON}" -m coverage run -m unittest discover -p '*.py' -v "$@"

0
test-packages/qubesdb.py Normal file
View File