Restructure test

This commit is contained in:
André Apitzsch 2018-11-11 01:31:50 +01:00 committed by Philipp Hörist
parent 8946af337a
commit 958e1390fd
21 changed files with 26 additions and 142 deletions

View File

@ -10,7 +10,7 @@ stages:
run-test: run-test:
stage: test stage: test
script: script:
- python3 setup.py test_nogui - python3 setup.py test -s test.no_gui -q
run-mypy: run-mypy:
stage: test stage: test

View File

@ -18,6 +18,7 @@ classifiers =
[options] [options]
python_requires = >=3.5 python_requires = >=3.5
packages = find: packages = find:
test_suite = test
install_requires = install_requires =
cssutils>=1.0.2 cssutils>=1.0.2
keyring keyring

View File

@ -176,27 +176,6 @@ class install(_install):
_install.run(self) _install.run(self)
class test(Command):
description = "Run all tests"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
exit(subprocess.call("./test/runtests.py"))
class test_nogui(test):
description = "Run tests without GUI"
def run(self):
exit(subprocess.call(["./test/runtests.py", "-n"]))
class update_po(Command): class update_po(Command):
description = "Update po files" description = "Update po files"
user_options = [] user_options = []
@ -229,8 +208,6 @@ setup(
cmdclass={ cmdclass={
'build_py': build, 'build_py': build,
'install': install, 'install': install,
'test': test,
'test_nogui': test_nogui,
'update_po': update_po, 'update_po': update_po,
}, },
entry_points={ entry_points={

View File

@ -167,8 +167,6 @@ class TestSocks5(unittest.TestCase):
self._check_inout() self._check_inout()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -15,7 +15,6 @@ from gajim.gtk.util import get_cursor
from gajim.conversation_textview import ConversationTextview from gajim.conversation_textview import ConversationTextview
from gajim.gui_interface import Interface from gajim.gui_interface import Interface
caps_cache.capscache = MagicMock() caps_cache.capscache = MagicMock()
app.plugin_manager = MagicMock() app.plugin_manager = MagicMock()
app.logger = MagicMock() app.logger = MagicMock()
@ -24,6 +23,7 @@ app.interface = Interface()
change_cursor = None change_cursor = None
htmlview = ConversationTextview(None) htmlview = ConversationTextview(None)
def on_textview_motion_notify_event(widget, event): def on_textview_motion_notify_event(widget, event):
""" """
Change the cursor to a hand when we are over a mail or an url Change the cursor to a hand when we are over a mail or an url
@ -52,7 +52,6 @@ def handler(texttag, widget, event, iter_, kind):
if event.type == Gdk.EventType.BUTTON_PRESS: if event.type == Gdk.EventType.BUTTON_PRESS:
pass pass
htmlview.tv.hyperlink_handler = htmlview.hyperlink_handler
htmlview.print_real_text(None, xhtml='<div>' htmlview.print_real_text(None, xhtml='<div>'
'<span style="color: red; text-decoration:underline">Hello</span><br/>\n' '<span style="color: red; text-decoration:underline">Hello</span><br/>\n'

View File

@ -1,8 +1,6 @@
import unittest import unittest
import time from test import lib
import lib
lib.setup_env() lib.setup_env()
from gi.repository import GLib from gi.repository import GLib
@ -14,7 +12,8 @@ JABBERCZ_TXT_NAME = '_xmppconnect.jabber.cz'
JABBERCZ_SRV_NAME = '_xmpp-client._tcp.jabber.cz' JABBERCZ_SRV_NAME = '_xmpp-client._tcp.jabber.cz'
TEST_LIST = [(NONSENSE_NAME, 'srv', False), TEST_LIST = [(NONSENSE_NAME, 'srv', False),
(JABBERCZ_SRV_NAME, 'srv', True)] (JABBERCZ_SRV_NAME, 'srv', True)]
class TestResolver(unittest.TestCase): class TestResolver(unittest.TestCase):
''' '''
@ -45,9 +44,9 @@ class TestResolver(unittest.TestCase):
def _runGR(self, name, type_): def _runGR(self, name, type_):
self.resolver.resolve( self.resolver.resolve(
host = name, host=name,
type_ = type_, type_=type_,
on_ready = self._myonready) on_ready=self._myonready)
self.main_loop.run() self.main_loop.run()

View File

@ -1,26 +1,15 @@
import sys
import os import os
import getopt
use_x = True from tempfile import gettempdir
shortargs = 'hnv:'
longargs = 'help no-x verbose='
opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split())
for o, a in opts:
if o in ('-n', '--no-x'):
use_x = False
gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')
# look for modules in the CWD, then gajim/test/lib, then gajim/gajim,
# then everywhere else
sys.path.insert(1, gajim_root)
sys.path.insert(1, gajim_root + '/test/lib')
# a temporary version of ~/.gajim for testing # a temporary version of ~/.gajim for testing
configdir = gajim_root + '/test/tmp' configdir = os.path.join(gettempdir(), 'gajim')
os.makedirs(configdir, exist_ok=True)
# plugins config dir # plugins config dir
pluginsconfigdir = configdir + '/pluginsconfig' pluginsconfigdir = configdir + '/pluginsconfig'
# theme config directory
themedir = configdir + '/theme'
# define _ for i18n # define _ for i18n
import builtins import builtins
@ -28,7 +17,7 @@ builtins._ = lambda x: x
from gajim.common.contacts import LegacyContactsAPI from gajim.common.contacts import LegacyContactsAPI
def setup_env(): def setup_env(use_x=True):
# wipe config directory # wipe config directory
if os.path.isdir(configdir): if os.path.isdir(configdir):
import shutil import shutil
@ -36,6 +25,7 @@ def setup_env():
os.mkdir(configdir) os.mkdir(configdir)
os.mkdir(pluginsconfigdir) os.mkdir(pluginsconfigdir)
os.mkdir(themedir)
from gajim.common import configpaths from gajim.common import configpaths
configpaths.set_config_root(configdir) configpaths.set_config_root(configdir)
@ -47,13 +37,10 @@ def setup_env():
import logging import logging
logging.basicConfig() logging.basicConfig()
configpaths.override_path('DATA', gajim_root + '/gajim/data')
app.use_x = use_x app.use_x = use_x
app.contacts = LegacyContactsAPI() app.contacts = LegacyContactsAPI()
app.connections = {} app.connections = {}
if use_x: if use_x:
from gajim import gtkgui_helpers
gtkgui_helpers.GUI_DIR = gajim_root + '/gajim/data/gui'
from gajim.application import GajimApplication from gajim.application import GajimApplication
app.app = GajimApplication() app.app = GajimApplication()

View File

@ -2,7 +2,7 @@
Module with dummy classes for Gajim specific unit testing Module with dummy classes for Gajim specific unit testing
''' '''
from mock import Mock from .mock import Mock
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged

0
test/no_gui/__init__.py Normal file
View File

View File

@ -0,0 +1,5 @@
'''
This package just contains plain unit tests
'''

View File

@ -3,11 +3,9 @@ Tests for Account classes
''' '''
import unittest import unittest
import lib
lib.setup_env()
from gajim.common.account import Account from gajim.common.account import Account
class Test(unittest.TestCase): class Test(unittest.TestCase):
def testInstantiate(self): def testInstantiate(self):

View File

@ -3,9 +3,6 @@ Tests for capabilities and the capabilities cache
''' '''
import unittest import unittest
import lib
lib.setup_env()
from unittest.mock import MagicMock, Mock from unittest.mock import MagicMock, Mock
from nbxmpp import NS_MUC, NS_PING, NS_XHTML_IM, Iq from nbxmpp import NS_MUC, NS_PING, NS_XHTML_IM, Iq
from gajim.common import caps_cache as caps from gajim.common import caps_cache as caps

View File

@ -2,12 +2,9 @@
Test for Contact, GC_Contact and Contacts Test for Contact, GC_Contact and Contacts
''' '''
import unittest import unittest
from nbxmpp import NS_MUC
import lib
lib.setup_env()
from gajim.common.contacts import CommonContact, Contact, GC_Contact, LegacyContactsAPI from gajim.common.contacts import CommonContact, Contact, GC_Contact, LegacyContactsAPI
from nbxmpp import NS_MUC
from gajim.common import caps_cache from gajim.common import caps_cache

View File

@ -7,9 +7,6 @@ from unittest.mock import MagicMock
import nbxmpp import nbxmpp
import lib
lib.setup_env()
from gajim.common import app from gajim.common import app
from gajim.common import nec from gajim.common import nec
from gajim.common import ged from gajim.common import ged

View File

@ -1,71 +0,0 @@
#!/usr/bin/env python3
'''
Runs Gajim's Test Suite
Unit tests tests will be run on each commit.
'''
import sys
import unittest
import getopt
use_x = True
verbose = 1
try:
shortargs = 'hnv:'
longargs = 'help no-x verbose='
opts, args = getopt.getopt(sys.argv[1:], shortargs, longargs.split())
except getopt.error as msg:
print(msg)
print('for help use --help')
sys.exit(2)
for o, a in opts:
if o in ('-h', '--help'):
print('runtests [--help] [--no-x] [--verbose level]')
sys.exit()
elif o in ('-n', '--no-x'):
use_x = False
elif o in ('-v', '--verbose'):
try:
verbose = int(a)
except Exception:
print('verbose must be a number >= 0')
sys.exit(2)
# new test modules need to be added manually
modules = ( 'unit.test_protocol_caps',
'unit.test_caps_cache',
'unit.test_contacts',
'unit.test_account',
)
if use_x:
modules += ( 'unit.test_sessions',
#'integration.test_gui_event_integration',
'integration.test_roster',
'integration.test_resolver',
'unit.test_gui_interface',
)
nb_errors = 0
nb_failures = 0
for mod in modules:
print("Now running: %s" % mod)
suite = unittest.defaultTestLoader.loadTestsFromName(mod)
result = unittest.TextTestRunner(verbosity=verbose).run(suite)
if use_x:
# Wait 500ms to be sure all timeout_add will be called before we cleanup main loop
import time
time.sleep(0.5)
# Clean main loop
from gi.repository import GLib
mc = GLib.main_context_default()
while mc.pending():
mc.iteration()
nb_errors += len(result.errors)
nb_failures += len(result.failures)
sys.exit(nb_errors + nb_failures)

View File

@ -3,7 +3,7 @@ Some diverse tests covering functionality in the GUI Interface class.
''' '''
import unittest import unittest
import lib from test import lib
lib.setup_env() lib.setup_env()
from gajim.common import logging_helpers from gajim.common import logging_helpers