From 448261394f35b242eff6d6f806b478f692f6d267 Mon Sep 17 00:00:00 2001 From: bendikro Date: Mon, 13 Oct 2014 16:57:46 +0200 Subject: [PATCH] [Tests] Changes to tests and test configs of Travis/tox * Added pip chaching * Added disable_new_release_check to tracker icons tests * Fixed test_torrentview * Require minimum tox version 1.8 * Fixed GTKUI tests and testcoverage by using xvfb on travis * Separated the apt dependencies for commands requiering GTKUI deps --- .travis.yml | 45 +++++++++++++++++++----------- deluge/tests/test_authmanager.py | 13 ++++++--- deluge/tests/test_client.py | 10 ++++--- deluge/tests/test_torrentview.py | 32 ++++++++++++++++----- deluge/tests/test_tracker_icons.py | 5 ++-- tox.ini | 2 +- 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d5b49103..021ecf6af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,37 +1,50 @@ language: python python: -# - "2.6" - "2.7" -# command to install dependencies -install: - - pip install tox +# Cache packages download with apt +cache: + directories: + - $HOME/.pip-cache/ + +before_install: - lsb_release -a - sudo add-apt-repository ppa:deluge-team/ppa -y - sudo apt-get update - - sudo apt-get install python-libtorrent -script: - - tox +# command to install dependencies +install: + - bash -c "echo $APTPACKAGES" + - sudo apt-get install $APTPACKAGES + - pip install "tox>=1.8" --download-cache $HOME/.pip-cache env: - - TOX_ENV=pydef - - TOX_ENV=trial - - TOX_ENV=todo -# - TOX_ENV=plugins - - TOX_ENV=flake8 - - TOX_ENV=flake8-complexity - - TOX_ENV=isort - - TOX_ENV=docs - - TOX_ENV=testcoverage + global: + - PIP_DOWNLOAD_CACHE=$HOME/.pip-cache/ + - APTPACKAGES="python-libtorrent" + - APTPACKAGES_GTKUI="python-gobject python-glade2" + matrix: + - TOX_ENV=pydef + - TOX_ENV=flake8 + - TOX_ENV=flake8-complexity + - TOX_ENV=isort + - TOX_ENV=docs + - TOX_ENV=todo + - TOX_ENV=trial APTPACKAGES="$APTPACKAGES $APTPACKAGES_GTKUI" + - TOX_ENV=pygtkui APTPACKAGES="$APTPACKAGES $APTPACKAGES_GTKUI" + - TOX_ENV=testcoverage APTPACKAGES="$APTPACKAGES $APTPACKAGES_GTKUI" +# - TOX_ENV=plugins virtualenv: system_site_packages: true +# We use xvfb for the GTKUI tests before_script: - export PYTHONPATH=$PYTHONPATH:$PWD - python -c "import libtorrent as lt; print lt.version" + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start script: - tox -e $TOX_ENV diff --git a/deluge/tests/test_authmanager.py b/deluge/tests/test_authmanager.py index 6b9d0b3b5..7f34e370b 100644 --- a/deluge/tests/test_authmanager.py +++ b/deluge/tests/test_authmanager.py @@ -1,13 +1,18 @@ -from twisted.trial import unittest - +import deluge.component as component from deluge.core.authmanager import AUTH_LEVEL_ADMIN, AuthManager +from .basetest import BaseTestCase -class AuthManagerTestCase(unittest.TestCase): - def setUp(self): # NOQA + +class AuthManagerTestCase(BaseTestCase): + def set_up(self): self.auth = AuthManager() self.auth.start() + def tear_down(self): + # We must ensure that the components in component registry are removed + return component.shutdown() + def test_authorize(self): from deluge.ui import common self.assertEquals( diff --git a/deluge/tests/test_client.py b/deluge/tests/test_client.py index 94ef34ce6..8f2a2c1a9 100644 --- a/deluge/tests/test_client.py +++ b/deluge/tests/test_client.py @@ -1,12 +1,13 @@ from twisted.internet import defer from twisted.internet.error import CannotListenError -from twisted.trial import unittest +import deluge.component as component from deluge import error from deluge.core.authmanager import AUTH_LEVEL_ADMIN from deluge.ui.client import Client, DaemonSSLProxy, client from . import common +from .basetest import BaseTestCase class NoVersionSendingDaemonSSLProxy(DaemonSSLProxy): @@ -63,9 +64,9 @@ class NoVersionSendingClient(Client): self.disconnect_callback() -class ClientTestCase(unittest.TestCase): +class ClientTestCase(BaseTestCase): - def setUp(self): # NOQA + def set_up(self): self.listen_port = 58846 tries = 10 error = None @@ -82,8 +83,9 @@ class ClientTestCase(unittest.TestCase): if error: raise error - def tearDown(self): # NOQA + def tear_down(self): self.core.terminate() + return component.shutdown() def test_connect_no_credentials(self): d = client.connect( diff --git a/deluge/tests/test_torrentview.py b/deluge/tests/test_torrentview.py index 36f8e359c..52293fd02 100644 --- a/deluge/tests/test_torrentview.py +++ b/deluge/tests/test_torrentview.py @@ -1,16 +1,28 @@ import pytest -import gobject from twisted.trial import unittest import deluge.common import deluge.component as component -from deluge.ui.gtkui.mainwindow import MainWindow -from deluge.ui.gtkui.menubar import MenuBar -from deluge.ui.gtkui.torrentdetails import TorrentDetails -from deluge.ui.gtkui.torrentview import TorrentView +from deluge.configmanager import ConfigManager +from . import common from .basetest import BaseTestCase +libs_available = True +# Allow running other tests without GTKUI dependencies available +try: + from gobject import TYPE_UINT64 + from deluge.ui.gtkui.mainwindow import MainWindow + from deluge.ui.gtkui.menubar import MenuBar + from deluge.ui.gtkui.torrentdetails import TorrentDetails + from deluge.ui.gtkui.torrentview import TorrentView + from deluge.ui.gtkui.gtkui import DEFAULT_PREFS +except ImportError as err: + libs_available = False + TYPE_UINT64 = "Whatever" + import traceback + traceback.print_exc() + deluge.common.setup_translations() @@ -23,13 +35,19 @@ class TorrentviewTestCase(BaseTestCase): u'Up Speed', u'Down Limit', u'Up Limit', u'ETA', u'Ratio', u'Avail', u'Added', u'Completed', u'Complete Seen', u'Tracker', u'Download Folder', u'Owner', u'Shared'] - default_liststore_columns = [bool, str, bool, int, str, str, gobject.TYPE_UINT64, - gobject.TYPE_UINT64, gobject.TYPE_UINT64, gobject.TYPE_UINT64, + default_liststore_columns = [bool, str, bool, int, str, str, TYPE_UINT64, + TYPE_UINT64, TYPE_UINT64, TYPE_UINT64, float, str, int, int, int, int, float, float, float, float, float, int, float, float, float, float, float, str, str, str, str, bool] def set_up(self): + if libs_available is False: + raise unittest.SkipTest("GTKUI dependencies not available") + + common.set_tmp_config_dir() + # MainWindow loads this config file, so lets make sure it contains the defaults + ConfigManager("gtkui.conf", defaults=DEFAULT_PREFS) self.mainwindow = MainWindow() self.torrentview = TorrentView() self.torrentdetails = TorrentDetails() diff --git a/deluge/tests/test_tracker_icons.py b/deluge/tests/test_tracker_icons.py index 40b4fa025..f6d4b880f 100644 --- a/deluge/tests/test_tracker_icons.py +++ b/deluge/tests/test_tracker_icons.py @@ -4,12 +4,13 @@ import deluge.component as component import deluge.ui.tracker_icons from deluge.ui.tracker_icons import TrackerIcon, TrackerIcons +from . import common from .basetest import BaseTestCase -from .common import set_tmp_config_dir -set_tmp_config_dir() +common.set_tmp_config_dir() dirname = os.path.dirname(__file__) deluge.ui.tracker_icons.PIL_INSTALLED = False +common.disable_new_release_check() class TrackerIconsTestCase(BaseTestCase): diff --git a/tox.ini b/tox.ini index fe98758a9..dd60edaae 100644 --- a/tox.ini +++ b/tox.ini @@ -120,7 +120,7 @@ whitelist_externals = {[testenv]whitelist_externals} coverage commands = - coverage run --branch --source=deluge -m py.test "not (todo or gtkui)" deluge/tests/ + coverage run --branch --source=deluge -m py.test -m "not todo" deluge/tests/ [testenv:testcoverage] deps = {[testcoveragebase]deps}