Fix running tests
This commit is contained in:
parent
c57af6dade
commit
b5c3b15c0f
|
@ -105,6 +105,7 @@ class GajimApplication(Gtk.Application):
|
||||||
self.rng_seed = None
|
self.rng_seed = None
|
||||||
|
|
||||||
GLib.set_prgname('gajim')
|
GLib.set_prgname('gajim')
|
||||||
|
if GLib.get_application_name() != 'Gajim':
|
||||||
GLib.set_application_name('Gajim')
|
GLib.set_application_name('Gajim')
|
||||||
|
|
||||||
def do_startup(self):
|
def do_startup(self):
|
||||||
|
@ -400,5 +401,6 @@ class GajimApplication(Gtk.Application):
|
||||||
self.lookup_action(account + action_name).set_enabled(True)
|
self.lookup_action(account + action_name).set_enabled(True)
|
||||||
|
|
||||||
|
|
||||||
app = GajimApplication()
|
if __name__ == '__main__':
|
||||||
app.run(sys.argv)
|
app = GajimApplication()
|
||||||
|
app.run(sys.argv)
|
||||||
|
|
|
@ -5,6 +5,8 @@ import time
|
||||||
import lib
|
import lib
|
||||||
lib.setup_env()
|
lib.setup_env()
|
||||||
|
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
from common import resolver
|
from common import resolver
|
||||||
|
|
||||||
from mock import Mock, expectParams
|
from mock import Mock, expectParams
|
||||||
|
@ -28,41 +30,38 @@ class TestResolver(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.idlequeue_thread = IdleQueueThread()
|
self.idlequeue_thread = IdleQueueThread()
|
||||||
self.idlequeue_thread.start()
|
self.idlequeue_thread.start()
|
||||||
|
self.main_context = GLib.MainContext()
|
||||||
|
self.main_context.push_thread_default()
|
||||||
|
self.main_loop = GLib.MainLoop(self.main_context)
|
||||||
|
|
||||||
self.iq = self.idlequeue_thread.iq
|
self.iq = self.idlequeue_thread.iq
|
||||||
self._reset()
|
self._reset()
|
||||||
self.resolver = None
|
self.resolver = None
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
self.main_context.pop_thread_default()
|
||||||
self.idlequeue_thread.stop_thread()
|
self.idlequeue_thread.stop_thread()
|
||||||
self.idlequeue_thread.join()
|
self.idlequeue_thread.join()
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
self.flag = False
|
|
||||||
self.expect_results = False
|
self.expect_results = False
|
||||||
self.nslookup = False
|
|
||||||
self.resolver = None
|
self.resolver = None
|
||||||
|
|
||||||
def testLibAsyncNSResolver(self):
|
def testGioResolver(self):
|
||||||
self._reset()
|
self._reset()
|
||||||
if not resolver.USE_LIBASYNCNS:
|
self.resolver = resolver.GioResolver()
|
||||||
print('testLibAsyncResolver: libasyncns-python not installed')
|
|
||||||
return
|
|
||||||
self.resolver = resolver.LibAsyncNSResolver()
|
|
||||||
|
|
||||||
for name, type, expect_results in TEST_LIST:
|
for name, type_, expect_results in TEST_LIST:
|
||||||
self.expect_results = expect_results
|
self.expect_results = expect_results
|
||||||
self._runLANSR(name, type)
|
self._runGR(name, type_)
|
||||||
self.flag = False
|
|
||||||
|
|
||||||
def _runLANSR(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)
|
||||||
while not self.flag:
|
|
||||||
time.sleep(1)
|
self.main_loop.run()
|
||||||
self.resolver.process()
|
|
||||||
|
|
||||||
def _myonready(self, name, result_set):
|
def _myonready(self, name, result_set):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -73,28 +72,11 @@ class TestResolver(unittest.TestCase):
|
||||||
pprint('res.resolved_hosts: %s' % self.resolver.resolved_hosts)
|
pprint('res.resolved_hosts: %s' % self.resolver.resolved_hosts)
|
||||||
pprint('')
|
pprint('')
|
||||||
if self.expect_results:
|
if self.expect_results:
|
||||||
self.assert_(len(result_set) > 0)
|
self.assertTrue(len(result_set) > 0)
|
||||||
else:
|
else:
|
||||||
self.assert_(result_set == [])
|
self.assertTrue(result_set == [])
|
||||||
self.flag = True
|
self.main_loop.quit()
|
||||||
if self.nslookup:
|
|
||||||
self._testNSLR()
|
|
||||||
|
|
||||||
def testNSLookupResolver(self):
|
|
||||||
self._reset()
|
|
||||||
self.nslookup = True
|
|
||||||
self.resolver = resolver.NSLookupResolver(self.iq)
|
|
||||||
self.test_list = TEST_LIST
|
|
||||||
self._testNSLR()
|
|
||||||
|
|
||||||
def _testNSLR(self):
|
|
||||||
if self.test_list == []:
|
|
||||||
return
|
|
||||||
name, type, self.expect_results = self.test_list.pop()
|
|
||||||
self.resolver.resolve(
|
|
||||||
host = name,
|
|
||||||
type = type,
|
|
||||||
on_ready = self._myonready)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -20,16 +20,16 @@ class TestRosterWindow(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
gajim.interface = MockInterface()
|
gajim.interface = MockInterface()
|
||||||
|
|
||||||
self.C_NAME = roster_window.C_NAME
|
self.C_NAME = roster_window.Column.NAME
|
||||||
self.C_TYPE = roster_window.C_TYPE
|
self.C_TYPE = roster_window.Column.TYPE
|
||||||
self.C_JID = roster_window.C_JID
|
self.C_JID = roster_window.Column.JID
|
||||||
self.C_ACCOUNT = roster_window.C_ACCOUNT
|
self.C_ACCOUNT = roster_window.Column.ACCOUNT
|
||||||
|
|
||||||
# Add after creating RosterWindow
|
# Add after creating RosterWindow
|
||||||
# We want to test the filling explicitly
|
# We want to test the filling explicitly
|
||||||
gajim.contacts = contacts_module.LegacyContactsAPI()
|
gajim.contacts = contacts_module.LegacyContactsAPI()
|
||||||
gajim.connections = {}
|
gajim.connections = {}
|
||||||
self.roster = roster_window.RosterWindow()
|
self.roster = roster_window.RosterWindow(gajim.app)
|
||||||
|
|
||||||
for acc in contacts:
|
for acc in contacts:
|
||||||
gajim.connections[acc] = MockConnection(acc)
|
gajim.connections[acc] = MockConnection(acc)
|
||||||
|
|
|
@ -50,3 +50,5 @@ def setup_env():
|
||||||
if use_x:
|
if use_x:
|
||||||
import gtkgui_helpers
|
import gtkgui_helpers
|
||||||
gtkgui_helpers.GUI_DIR = gajim_root + '/data/gui'
|
gtkgui_helpers.GUI_DIR = gajim_root + '/data/gui'
|
||||||
|
from gajim import GajimApplication
|
||||||
|
gajim.app = GajimApplication()
|
||||||
|
|
|
@ -107,6 +107,8 @@ class MockInterface(Mock):
|
||||||
self.msg_win_mgr = Mock()
|
self.msg_win_mgr = Mock()
|
||||||
self.roster = Mock()
|
self.roster = Mock()
|
||||||
gajim.ged = ged.GlobalEventsDispatcher()
|
gajim.ged = ged.GlobalEventsDispatcher()
|
||||||
|
import plugins
|
||||||
|
gajim.plugin_manager = plugins.PluginManager()
|
||||||
|
|
||||||
self.remote_ctrl = None
|
self.remote_ctrl = None
|
||||||
self.instances = {}
|
self.instances = {}
|
||||||
|
@ -126,7 +128,8 @@ class MockInterface(Mock):
|
||||||
|
|
||||||
class MockLogger(Mock):
|
class MockLogger(Mock):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Mock.__init__(self, {'write': None, 'get_transports_type': {}})
|
Mock.__init__(self, {'insert_into_logs': None,
|
||||||
|
'get_transports_type': {}})
|
||||||
self.cur = Mock()
|
self.cur = Mock()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ class TestInterface(unittest.TestCase):
|
||||||
|
|
||||||
def test_instantiation(self):
|
def test_instantiation(self):
|
||||||
''' Test that we can proper initialize and do not fail on globals '''
|
''' Test that we can proper initialize and do not fail on globals '''
|
||||||
interface = Interface()
|
gajim.app.run()
|
||||||
interface.run()
|
|
||||||
|
|
||||||
def test_links_regexp_entire(self):
|
def test_links_regexp_entire(self):
|
||||||
sut = Interface()
|
sut = Interface()
|
||||||
|
|
|
@ -153,7 +153,7 @@ class TestChatControlSession(unittest.TestCase):
|
||||||
sess = self.conn.sessions[jid]['123']
|
sess = self.conn.sessions[jid]['123']
|
||||||
|
|
||||||
# message was logged
|
# message was logged
|
||||||
calls = gajim.logger.mockGetNamedCalls('write')
|
calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
|
||||||
self.assertEqual(1, len(calls))
|
self.assertEqual(1, len(calls))
|
||||||
|
|
||||||
# no ChatControl was open and autopopup was off
|
# no ChatControl was open and autopopup was off
|
||||||
|
@ -171,7 +171,7 @@ class TestChatControlSession(unittest.TestCase):
|
||||||
jid = 'bct@necronomicorp.com'
|
jid = 'bct@necronomicorp.com'
|
||||||
fjid = 'bct@necronomicorp.com/Gajim'
|
fjid = 'bct@necronomicorp.com/Gajim'
|
||||||
msgtxt = 'testing two'
|
msgtxt = 'testing two'
|
||||||
roster = RosterWindow()
|
roster = RosterWindow(gajim.app)
|
||||||
|
|
||||||
sess = self.conn.sessions[jid]['123']
|
sess = self.conn.sessions[jid]['123']
|
||||||
sess.control = MockChatControl(fjid, account_name)
|
sess.control = MockChatControl(fjid, account_name)
|
||||||
|
@ -179,7 +179,7 @@ class TestChatControlSession(unittest.TestCase):
|
||||||
self.receive_chat_msg(fjid, msgtxt)
|
self.receive_chat_msg(fjid, msgtxt)
|
||||||
|
|
||||||
# message was logged
|
# message was logged
|
||||||
calls = gajim.logger.mockGetNamedCalls('write')
|
calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
|
||||||
self.assertEqual(2, len(calls))
|
self.assertEqual(2, len(calls))
|
||||||
|
|
||||||
# the message does not go into the event queue
|
# the message does not go into the event queue
|
||||||
|
@ -207,7 +207,7 @@ class TestChatControlSession(unittest.TestCase):
|
||||||
#self.receive_chat_msg(fjid, msgtxt)
|
#self.receive_chat_msg(fjid, msgtxt)
|
||||||
|
|
||||||
## message was logged
|
## message was logged
|
||||||
#calls = gajim.logger.mockGetNamedCalls('write')
|
#calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
|
||||||
#self.assertEqual(1, len(calls))
|
#self.assertEqual(1, len(calls))
|
||||||
|
|
||||||
## the message does not go into the event queue
|
## the message does not go into the event queue
|
||||||
|
|
Loading…
Reference in New Issue