Fix running tests

This commit is contained in:
Yann Leboulanger 2017-08-09 15:34:58 +02:00
parent c57af6dade
commit b5c3b15c0f
7 changed files with 38 additions and 50 deletions

View File

@ -105,7 +105,8 @@ class GajimApplication(Gtk.Application):
self.rng_seed = None
GLib.set_prgname('gajim')
GLib.set_application_name('Gajim')
if GLib.get_application_name() != 'Gajim':
GLib.set_application_name('Gajim')
def do_startup(self):
Gtk.Application.do_startup(self)
@ -400,5 +401,6 @@ class GajimApplication(Gtk.Application):
self.lookup_action(account + action_name).set_enabled(True)
app = GajimApplication()
app.run(sys.argv)
if __name__ == '__main__':
app = GajimApplication()
app.run(sys.argv)

View File

@ -5,6 +5,8 @@ import time
import lib
lib.setup_env()
from gi.repository import GLib
from common import resolver
from mock import Mock, expectParams
@ -28,41 +30,38 @@ class TestResolver(unittest.TestCase):
def setUp(self):
self.idlequeue_thread = IdleQueueThread()
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._reset()
self.resolver = None
def tearDown(self):
self.main_context.pop_thread_default()
self.idlequeue_thread.stop_thread()
self.idlequeue_thread.join()
def _reset(self):
self.flag = False
self.expect_results = False
self.nslookup = False
self.resolver = None
def testLibAsyncNSResolver(self):
def testGioResolver(self):
self._reset()
if not resolver.USE_LIBASYNCNS:
print('testLibAsyncResolver: libasyncns-python not installed')
return
self.resolver = resolver.LibAsyncNSResolver()
self.resolver = resolver.GioResolver()
for name, type, expect_results in TEST_LIST:
for name, type_, expect_results in TEST_LIST:
self.expect_results = expect_results
self._runLANSR(name, type)
self.flag = False
self._runGR(name, type_)
def _runLANSR(self, name, type):
def _runGR(self, name, type_):
self.resolver.resolve(
host = name,
type = type,
type_ = type_,
on_ready = self._myonready)
while not self.flag:
time.sleep(1)
self.resolver.process()
self.main_loop.run()
def _myonready(self, name, result_set):
if __name__ == '__main__':
@ -73,28 +72,11 @@ class TestResolver(unittest.TestCase):
pprint('res.resolved_hosts: %s' % self.resolver.resolved_hosts)
pprint('')
if self.expect_results:
self.assert_(len(result_set) > 0)
self.assertTrue(len(result_set) > 0)
else:
self.assert_(result_set == [])
self.flag = True
if self.nslookup:
self._testNSLR()
self.assertTrue(result_set == [])
self.main_loop.quit()
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__':
unittest.main()

View File

@ -20,16 +20,16 @@ class TestRosterWindow(unittest.TestCase):
def setUp(self):
gajim.interface = MockInterface()
self.C_NAME = roster_window.C_NAME
self.C_TYPE = roster_window.C_TYPE
self.C_JID = roster_window.C_JID
self.C_ACCOUNT = roster_window.C_ACCOUNT
self.C_NAME = roster_window.Column.NAME
self.C_TYPE = roster_window.Column.TYPE
self.C_JID = roster_window.Column.JID
self.C_ACCOUNT = roster_window.Column.ACCOUNT
# Add after creating RosterWindow
# We want to test the filling explicitly
gajim.contacts = contacts_module.LegacyContactsAPI()
gajim.connections = {}
self.roster = roster_window.RosterWindow()
self.roster = roster_window.RosterWindow(gajim.app)
for acc in contacts:
gajim.connections[acc] = MockConnection(acc)

View File

@ -50,3 +50,5 @@ def setup_env():
if use_x:
import gtkgui_helpers
gtkgui_helpers.GUI_DIR = gajim_root + '/data/gui'
from gajim import GajimApplication
gajim.app = GajimApplication()

View File

@ -107,6 +107,8 @@ class MockInterface(Mock):
self.msg_win_mgr = Mock()
self.roster = Mock()
gajim.ged = ged.GlobalEventsDispatcher()
import plugins
gajim.plugin_manager = plugins.PluginManager()
self.remote_ctrl = None
self.instances = {}
@ -126,7 +128,8 @@ class MockInterface(Mock):
class MockLogger(Mock):
def __init__(self):
Mock.__init__(self, {'write': None, 'get_transports_type': {}})
Mock.__init__(self, {'insert_into_logs': None,
'get_transports_type': {}})
self.cur = Mock()

View File

@ -20,8 +20,7 @@ class TestInterface(unittest.TestCase):
def test_instantiation(self):
''' Test that we can proper initialize and do not fail on globals '''
interface = Interface()
interface.run()
gajim.app.run()
def test_links_regexp_entire(self):
sut = Interface()

View File

@ -153,7 +153,7 @@ class TestChatControlSession(unittest.TestCase):
sess = self.conn.sessions[jid]['123']
# message was logged
calls = gajim.logger.mockGetNamedCalls('write')
calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
self.assertEqual(1, len(calls))
# no ChatControl was open and autopopup was off
@ -171,7 +171,7 @@ class TestChatControlSession(unittest.TestCase):
jid = 'bct@necronomicorp.com'
fjid = 'bct@necronomicorp.com/Gajim'
msgtxt = 'testing two'
roster = RosterWindow()
roster = RosterWindow(gajim.app)
sess = self.conn.sessions[jid]['123']
sess.control = MockChatControl(fjid, account_name)
@ -179,7 +179,7 @@ class TestChatControlSession(unittest.TestCase):
self.receive_chat_msg(fjid, msgtxt)
# message was logged
calls = gajim.logger.mockGetNamedCalls('write')
calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
self.assertEqual(2, len(calls))
# the message does not go into the event queue
@ -207,7 +207,7 @@ class TestChatControlSession(unittest.TestCase):
#self.receive_chat_msg(fjid, msgtxt)
## message was logged
#calls = gajim.logger.mockGetNamedCalls('write')
#calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
#self.assertEqual(1, len(calls))
## the message does not go into the event queue