Browse Source

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

Also, replace subproces.call with a mockup, as notify-send is not
available on travis.
Marek Marczykowski-Górecki 7 years ago
parent
commit
07be216a0d
7 changed files with 62 additions and 1 deletions
  1. 3 0
      .coveragerc
  2. 2 0
      .gitignore
  3. 21 1
      .travis.yml
  4. 6 0
      ci/requirements.txt
  5. 17 0
      qubesagent/test_firewall.py
  6. 13 0
      run-tests
  7. 0 0
      test-packages/qubesdb.py

+ 3 - 0
.coveragerc

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

+ 2 - 0
.gitignore

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

+ 21 - 1
.travis.yml

@@ -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 - 0
ci/requirements.txt

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

+ 17 - 0
qubesagent/test_firewall.py

@@ -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 - 0
run-tests

@@ -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 - 0
test-packages/qubesdb.py