Browse Source

Restructure test

v1.1.2-plural
André Apitzsch 4 years ago committed by Philipp Hörist
parent
commit
958e1390fd
  1. 2
      .gitlab-ci.yml
  2. 1
      setup.cfg
  3. 23
      setup.py
  4. 0
      test/broken/integration/test_gui_event_integration.py
  5. 0
      test/broken/integration/test_roster.py
  6. 0
      test/broken/test_pluginmanager.py
  7. 0
      test/broken/unit/test_jingle.py
  8. 0
      test/broken/unit/test_sessions.py
  9. 2
      test/broken/unit/test_socks5.py
  10. 3
      test/gtk/htmltextview.py
  11. 13
      test/integration/test_resolver.py
  12. 29
      test/lib/__init__.py
  13. 2
      test/lib/gajim_mocks.py
  14. 0
      test/no_gui/__init__.py
  15. 5
      test/no_gui/unit/__init__.py
  16. 4
      test/no_gui/unit/test_account.py
  17. 3
      test/no_gui/unit/test_caps_cache.py
  18. 5
      test/no_gui/unit/test_contacts.py
  19. 3
      test/no_gui/unit/test_protocol_caps.py
  20. 71
      test/runtests.py
  21. 2
      test/unit/test_gui_interface.py

2
.gitlab-ci.yml

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

1
setup.cfg

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

23
setup.py

@ -176,27 +176,6 @@ class install(_install): @@ -176,27 +176,6 @@ class install(_install):
_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):
description = "Update po files"
user_options = []
@ -229,8 +208,6 @@ setup( @@ -229,8 +208,6 @@ setup(
cmdclass={
'build_py': build,
'install': install,
'test': test,
'test_nogui': test_nogui,
'update_po': update_po,
},
entry_points={

0
test/integration/test_gui_event_integration.py → test/broken/integration/test_gui_event_integration.py

0
test/integration/test_roster.py → test/broken/integration/test_roster.py

0
test/test_pluginmanager.py → test/broken/test_pluginmanager.py

0
test/unit/test_jingle.py → test/broken/unit/test_jingle.py

0
test/unit/test_sessions.py → test/broken/unit/test_sessions.py

2
test/unit/test_socks5.py → test/broken/unit/test_socks5.py

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

3
test/gtk/htmltextview.py

@ -15,7 +15,6 @@ from gajim.gtk.util import get_cursor @@ -15,7 +15,6 @@ from gajim.gtk.util import get_cursor
from gajim.conversation_textview import ConversationTextview
from gajim.gui_interface import Interface
caps_cache.capscache = MagicMock()
app.plugin_manager = MagicMock()
app.logger = MagicMock()
@ -24,6 +23,7 @@ app.interface = Interface() @@ -24,6 +23,7 @@ app.interface = Interface()
change_cursor = None
htmlview = ConversationTextview(None)
def on_textview_motion_notify_event(widget, event):
"""
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): @@ -52,7 +52,6 @@ def handler(texttag, widget, event, iter_, kind):
if event.type == Gdk.EventType.BUTTON_PRESS:
pass
htmlview.tv.hyperlink_handler = htmlview.hyperlink_handler
htmlview.print_real_text(None, xhtml='<div>'
'<span style="color: red; text-decoration:underline">Hello</span><br/>\n'

13
test/integration/test_resolver.py

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

29
test/lib/__init__.py

@ -1,26 +1,15 @@ @@ -1,26 +1,15 @@
import sys
import os
import getopt
use_x = True
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')
from tempfile import gettempdir
# 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
pluginsconfigdir = configdir + '/pluginsconfig'
# theme config directory
themedir = configdir + '/theme'
# define _ for i18n
import builtins
@ -28,7 +17,7 @@ builtins._ = lambda x: x @@ -28,7 +17,7 @@ builtins._ = lambda x: x
from gajim.common.contacts import LegacyContactsAPI
def setup_env():
def setup_env(use_x=True):
# wipe config directory
if os.path.isdir(configdir):
import shutil
@ -36,6 +25,7 @@ def setup_env(): @@ -36,6 +25,7 @@ def setup_env():
os.mkdir(configdir)
os.mkdir(pluginsconfigdir)
os.mkdir(themedir)
from gajim.common import configpaths
configpaths.set_config_root(configdir)
@ -47,13 +37,10 @@ def setup_env(): @@ -47,13 +37,10 @@ def setup_env():
import logging
logging.basicConfig()
configpaths.override_path('DATA', gajim_root + '/gajim/data')
app.use_x = use_x
app.contacts = LegacyContactsAPI()
app.connections = {}
if use_x:
from gajim import gtkgui_helpers
gtkgui_helpers.GUI_DIR = gajim_root + '/gajim/data/gui'
from gajim.application import GajimApplication
app.app = GajimApplication()

2
test/lib/gajim_mocks.py

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
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 ged

0
test/no_gui/__init__.py

5
test/no_gui/unit/__init__.py

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

4
test/unit/test_account.py → test/no_gui/unit/test_account.py

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

3
test/unit/test_caps_cache.py → test/no_gui/unit/test_caps_cache.py

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

5
test/unit/test_contacts.py → test/no_gui/unit/test_contacts.py

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

3
test/unit/test_protocol_caps.py → test/no_gui/unit/test_protocol_caps.py

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

71
test/runtests.py

@ -1,71 +0,0 @@ @@ -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)

2
test/unit/test_gui_interface.py

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

Loading…
Cancel
Save