diff options
author | André Apitzsch <git@apitzsch.eu> | 2018-11-22 02:16:55 +0300 |
---|---|---|
committer | André Apitzsch <git@apitzsch.eu> | 2018-11-22 02:22:20 +0300 |
commit | 441e53ccc0fc29893d6a6c69ce716bc516ef8b14 (patch) | |
tree | 489058cbd8665bd808a1ebfa9399f35480f1f644 /test | |
parent | 7cefcdd5a2221cf279547ff98c037882c0ee13ed (diff) |
Use setup.py to run tests
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/__init__.py | 13 | ||||
-rw-r--r-- | test/lib/xmpp_mocks.py | 2 | ||||
-rwxr-xr-x | test/runtests.py | 53 | ||||
-rw-r--r-- | test/unit/test_xmpp_client_nb.py | 38 | ||||
-rw-r--r-- | test/unit/test_xmpp_dispatcher_nb.py | 5 | ||||
-rw-r--r-- | test/unit/test_xmpp_smacks.py | 5 | ||||
-rw-r--r-- | test/unit/test_xmpp_transports_nb.py | 3 | ||||
-rw-r--r-- | test/unit/test_xmpp_transports_nb2.py | 5 |
8 files changed, 23 insertions, 101 deletions
diff --git a/test/lib/__init__.py b/test/lib/__init__.py index 9a29dc5..8d45171 100644 --- a/test/lib/__init__.py +++ b/test/lib/__init__.py @@ -1,14 +1,3 @@ -import sys -import os -import getopt - -root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..') - -# look for modules in the CWD, then gajim/test/lib, then gajim/src, -# then everywhere else -sys.path.insert(1, root) -sys.path.insert(1, root + '/test/lib') - def xml2str_sorted(data): s = "<" + data.name if data.namespace: @@ -38,5 +27,3 @@ def xml2str_sorted(data): s += "</" + data.name + ">" return s -def setup_env(): - pass diff --git a/test/lib/xmpp_mocks.py b/test/lib/xmpp_mocks.py index 2bfe7cb..e461d10 100644 --- a/test/lib/xmpp_mocks.py +++ b/test/lib/xmpp_mocks.py @@ -4,7 +4,7 @@ Module with dummy classes for unit testing of XMPP and related code. import threading, time -from mock import Mock +from test.lib.mock import Mock from nbxmpp import idlequeue diff --git a/test/runtests.py b/test/runtests.py deleted file mode 100755 index 7a6a6a0..0000000 --- a/test/runtests.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python3 - - -''' -Runs python-nbxmpp's Test Suite - -Unit tests tests will be run on each commit. -''' -from __future__ import print_function - -import sys -import unittest -import getopt -verbose = 1 - -try: - shortargs = 'hv:' - longargs = 'help 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] [--verbose level]') - sys.exit() - 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_xmpp_dispatcher_nb', - 'unit.test_xmpp_transports_nb', - 'unit.test_xmpp_smacks', - #'unit.test_xmpp_client_nb', gajim.org only supports TLS/SSL connections - 'unit.test_xmpp_transports_nb2', - 'unit.test_xml_vulnerability', - ) - -nb_errors = 0 -nb_failures = 0 - -for mod in modules: - suite = unittest.defaultTestLoader.loadTestsFromName(mod) - result = unittest.TextTestRunner(verbosity=verbose).run(suite) - nb_errors += len(result.errors) - nb_failures += len(result.failures) - -sys.exit(nb_errors + nb_failures) diff --git a/test/unit/test_xmpp_client_nb.py b/test/unit/test_xmpp_client_nb.py index 8ccac5b..478cf07 100644 --- a/test/unit/test_xmpp_client_nb.py +++ b/test/unit/test_xmpp_client_nb.py @@ -6,11 +6,8 @@ It actually connects to a xmpp server. import unittest -import lib -lib.setup_env() - -from xmpp_mocks import MockConnection, IdleQueueThread -from mock import Mock +from test.lib.xmpp_mocks import MockConnection, IdleQueueThread +from test.lib.mock import Mock from nbxmpp import client_nb # (XMPP server hostname, c2s port). Script will connect to the machine. @@ -19,6 +16,7 @@ xmpp_server_port = ('gajim.org', 5222) # [username, password, resource]. Script will authenticate to server above credentials = ['unittest', 'testtest', 'res'] +@unittest.skip("gajim.org only supports TLS/SSL connections") class TestNonBlockingClient(unittest.TestCase): ''' Test Cases class for NonBlockingClient. @@ -67,14 +65,14 @@ class TestNonBlockingClient(unittest.TestCase): on_connect_failure=lambda *args: self.connection.on_connect( False, *args)) - self.assert_(self.connection.wait(), + self.assertTrue(self.connection.wait(), msg='waiting for callback from client constructor') # if on_connect was called, client has to be connected and vice versa if self.connection.connect_succeeded: - self.assert_(self.client.get_connect_type()) + self.assertTrue(self.client.get_connect_type()) else: - self.assert_(not self.client.get_connect_type()) + self.assertTrue(not self.client.get_connect_type()) def client_auth(self, username, password, resource, sasl): ''' @@ -88,7 +86,7 @@ class TestNonBlockingClient(unittest.TestCase): self.client.auth(username, password, resource, sasl, on_auth=self.connection.on_auth) - self.assert_(self.connection.wait(), msg='waiting for authentication') + self.assertTrue(self.connection.wait(), msg='waiting for authentication') def do_disconnect(self): ''' @@ -108,13 +106,13 @@ class TestNonBlockingClient(unittest.TestCase): self.open_stream(xmpp_server_port) # if client is not connected, lets raise the AssertionError - self.assert_(self.client.get_connect_type()) + self.assertTrue(self.client.get_connect_type()) # client.disconnect() is already called from NBClient via # _on_connected_failure, no need to call it here self.client_auth(credentials[0], credentials[1], credentials[2], sasl=1) - self.assert_(self.connection.con) - self.assert_(self.connection.auth=='sasl', msg='Unable to auth via SASL') + self.assertTrue(self.connection.con) + self.assertTrue(self.connection.auth=='sasl', msg='Unable to auth via SASL') self.do_disconnect() @@ -124,14 +122,14 @@ class TestNonBlockingClient(unittest.TestCase): then disconnected. ''' self.open_stream(xmpp_server_port) - self.assert_(self.client.get_connect_type()) + self.assertTrue(self.client.get_connect_type()) self.client_auth(credentials[0], credentials[1], credentials[2], sasl=0) - self.assert_(self.connection.con) + self.assertTrue(self.connection.con) features = self.client.Dispatcher.Stream.features if not features.getTag('auth'): - print "Server doesn't support old authentication type, ignoring test" + print("Server doesn't support old authentication type, ignoring test") else: - self.assert_(self.connection.auth=='old_auth', + self.assertTrue(self.connection.auth=='old_auth', msg='Unable to auth via old_auth') self.do_disconnect() @@ -141,7 +139,7 @@ class TestNonBlockingClient(unittest.TestCase): nothing. ''' self.open_stream(('fdsfsdf.fdsf.fss', 5222)) - self.assert_(not self.client.get_connect_type()) + self.assertTrue(not self.client.get_connect_type()) def test_connect_to_wrong_port(self): ''' @@ -149,15 +147,15 @@ class TestNonBlockingClient(unittest.TestCase): IP but there shouldn't be XMPP server running on specified port. ''' self.open_stream((xmpp_server_port[0], 31337)) - self.assert_(not self.client.get_connect_type()) + self.assertTrue(not self.client.get_connect_type()) def test_connect_with_wrong_creds(self): ''' Connecting with invalid password. ''' self.open_stream(xmpp_server_port, wrong_pass=True) - self.assert_(self.client.get_connect_type()) + self.assertTrue(self.client.get_connect_type()) self.client_auth(credentials[0], 'wrong pass', credentials[2], sasl=1) - self.assert_(self.connection.auth is None) + self.assertTrue(self.connection.auth is None) self.do_disconnect() diff --git a/test/unit/test_xmpp_dispatcher_nb.py b/test/unit/test_xmpp_dispatcher_nb.py index 8882884..d730cc5 100644 --- a/test/unit/test_xmpp_dispatcher_nb.py +++ b/test/unit/test_xmpp_dispatcher_nb.py @@ -3,10 +3,9 @@ Tests for dispatcher_nb.py ''' import unittest -import lib -lib.setup_env() +from test import lib -from mock import Mock +from test.lib.mock import Mock from nbxmpp import dispatcher_nb from nbxmpp import protocol diff --git a/test/unit/test_xmpp_smacks.py b/test/unit/test_xmpp_smacks.py index 4747be4..51810e9 100644 --- a/test/unit/test_xmpp_smacks.py +++ b/test/unit/test_xmpp_smacks.py @@ -3,10 +3,7 @@ Tests for smacks.py Stream Management ''' import unittest -import lib -lib.setup_env() - -from mock import Mock +from test.lib.mock import Mock from nbxmpp import dispatcher_nb from nbxmpp import protocol diff --git a/test/unit/test_xmpp_transports_nb.py b/test/unit/test_xmpp_transports_nb.py index 3bc68f4..0f60737 100644 --- a/test/unit/test_xmpp_transports_nb.py +++ b/test/unit/test_xmpp_transports_nb.py @@ -4,9 +4,6 @@ Unit test for tranports classes. import unittest -import lib -lib.setup_env() - from nbxmpp import transports_nb diff --git a/test/unit/test_xmpp_transports_nb2.py b/test/unit/test_xmpp_transports_nb2.py index ec02063..ce521a0 100644 --- a/test/unit/test_xmpp_transports_nb2.py +++ b/test/unit/test_xmpp_transports_nb2.py @@ -6,10 +6,7 @@ unit tests of this module. import unittest import socket -import lib -lib.setup_env() - -from xmpp_mocks import IdleQueueThread, IdleMock +from test.lib.xmpp_mocks import IdleQueueThread, IdleMock from nbxmpp import transports_nb |