Moving logging and QApplication to conftest

As discussed in #8
This commit is contained in:
Bruno Oliveira 2015-04-02 19:05:20 -03:00
parent 47b9ea1f88
commit 751b62e344
4 changed files with 44 additions and 24 deletions

View File

@ -18,18 +18,3 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""The qutebrowser test suite.""" """The qutebrowser test suite."""
import atexit
from PyQt5.QtWidgets import QApplication
from qutebrowser.test import log
# We create a singleton QApplication here.
qApp = QApplication([])
qApp.setApplicationName('qutebrowser')
qApp.processEvents()
atexit.register(qApp.processEvents)
atexit.register(qApp.quit)
log.init()

View File

@ -0,0 +1,32 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""The qutebrowser test suite contest file."""
import pytest
@pytest.fixture(scope='session', autouse=True)
def app_and_logging(qapp):
"""
Initializes our logging system and ensures that a QApplication is created
and used by all tests.
"""
from .log import init
init()

View File

@ -26,12 +26,13 @@ import shutil
import unittest import unittest
import tempfile import tempfile
from PyQt5.QtWidgets import QApplication
from qutebrowser.utils import standarddir from qutebrowser.utils import standarddir
from qutebrowser.test import helpers, qApp from qutebrowser.test import helpers
class GetStandardDirLinuxTests(unittest.TestCase): class GetStandardDirLinuxTests(unittest.TestCase):
"""Tests for standarddir under Linux. """Tests for standarddir under Linux.
Attributes: Attributes:
@ -41,8 +42,8 @@ class GetStandardDirLinuxTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.temp_dir = tempfile.mkdtemp() self.temp_dir = tempfile.mkdtemp()
self.old_name = qApp.applicationName() self.old_name = QApplication.instance().applicationName()
qApp.setApplicationName('qutebrowser') QApplication.instance().setApplicationName('qutebrowser')
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux") @unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
def test_data_explicit(self): def test_data_explicit(self):
@ -97,12 +98,11 @@ class GetStandardDirLinuxTests(unittest.TestCase):
self.assertEqual(standarddir.cache(), expected) self.assertEqual(standarddir.cache(), expected)
def tearDown(self): def tearDown(self):
qApp.setApplicationName(self.old_name) QApplication.instance().setApplicationName(self.old_name)
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
class GetStandardDirWindowsTests(unittest.TestCase): class GetStandardDirWindowsTests(unittest.TestCase):
"""Tests for standarddir under Windows. """Tests for standarddir under Windows.
Attributes: Attributes:
@ -110,13 +110,13 @@ class GetStandardDirWindowsTests(unittest.TestCase):
""" """
def setUp(self): def setUp(self):
self.old_name = qApp.applicationName() self.old_name = QApplication.instance().applicationName()
# We can't store the files in a temp dir, so we don't chose qutebrowser # We can't store the files in a temp dir, so we don't chose qutebrowser
qApp.setApplicationName('qutebrowser_test') QApplication.instance().setApplicationName('qutebrowser_test')
standarddir.init(None) standarddir.init(None)
def tearDown(self): def tearDown(self):
qApp.setApplicationName(self.old_name) QApplication.instance().setApplicationName(self.old_name)
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_data(self): def test_data(self):

View File

@ -103,3 +103,6 @@ commands =
{envpython} scripts/src2asciidoc.py {envpython} scripts/src2asciidoc.py
git --no-pager diff --exit-code --stat git --no-pager diff --exit-code --stat
{envpython} scripts/asciidoc2html.py {posargs} {envpython} scripts/asciidoc2html.py {posargs}
[pytest]
norecursedirs = .tox .venv