Restructure test
This commit is contained in:
		
							parent
							
								
									8946af337a
								
							
						
					
					
						commit
						958e1390fd
					
				
					 21 changed files with 26 additions and 142 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
|  | @ -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
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -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( | |||
|     cmdclass={ | ||||
|         'build_py': build, | ||||
|         'install': install, | ||||
|         'test': test, | ||||
|         'test_nogui': test_nogui, | ||||
|         'update_po': update_po, | ||||
|     }, | ||||
|     entry_points={ | ||||
|  |  | |||
|  | @ -167,8 +167,6 @@ class TestSocks5(unittest.TestCase): | |||
|         self._check_inout() | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
| 
 | ||||
|     unittest.main() | ||||
|  | @ -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() | |||
| 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): | |||
|     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' | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| import unittest | ||||
| 
 | ||||
| import time | ||||
| 
 | ||||
| import lib | ||||
| from test import lib | ||||
| lib.setup_env() | ||||
| 
 | ||||
| from gi.repository import GLib | ||||
|  | @ -16,6 +14,7 @@ JABBERCZ_SRV_NAME = '_xmpp-client._tcp.jabber.cz' | |||
| TEST_LIST = [(NONSENSE_NAME, 'srv', False), | ||||
|              (JABBERCZ_SRV_NAME, 'srv', True)] | ||||
| 
 | ||||
| 
 | ||||
| class TestResolver(unittest.TestCase): | ||||
|     ''' | ||||
|     Test for LibAsyncNSResolver and NSLookupResolver. Requires working | ||||
|  | @ -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() | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | |||
| 
 | ||||
| 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(): | |||
| 
 | ||||
|     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(): | |||
|     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,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
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/no_gui/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										5
									
								
								test/no_gui/unit/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								test/no_gui/unit/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| ''' | ||||
| 
 | ||||
| This package just contains plain unit tests | ||||
| 
 | ||||
| ''' | ||||
|  | @ -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,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 | ||||
|  | @ -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 | ||||
| 
 | ||||
|  | @ -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 | ||||
|  | @ -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) | ||||
|  | @ -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…
	
	Add table
		
		Reference in a new issue