Skip to content

Commit

Permalink
Fixed obvious failures in test suite - still 2 fail and 9 error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap-karssenberg committed Sep 7, 2013
1 parent d29bac2 commit beb221e
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 198 deletions.
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2008 Jaap Karssenberg <jaap.karssenberg@gmail.com>
# Copyright 2008-2013 Jaap Karssenberg <jaap.karssenberg@gmail.com>

'''Zim test suite'''

Expand Down
30 changes: 8 additions & 22 deletions tests/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ def testDateRangeFromPath(self):
class TestCalendarPlugin(tests.TestCase):

def testNamespace(self):
ui = StubUI()
pluginklass = zim.plugins.get_plugin('calendar')
plugin = pluginklass(ui)
pluginklass = zim.plugins.get_plugin_class('calendar')
plugin = pluginklass()
today = dateclass.today()
for namespace in (Path('Calendar'), Path(':')):
plugin.preferences['namespace'] = namespace.name
Expand Down Expand Up @@ -138,11 +137,10 @@ def testNamespace(self):
self.assertEqual(path.name, 'Calendar:2012:04')

def testTemplate(self):
ui = StubUI()
pluginklass = zim.plugins.get_plugin('calendar')
plugin = pluginklass(ui)
plugin.initialize_ui(ui)
# plugin should register with TemplateManager
pluginklass = zim.plugins.get_plugin_class('calendar')
plugin = pluginklass()

notebook = tests.new_notebook()

template = get_template('wiki', 'Journal')
zim.datetimetz.FIRST_DAY_OF_WEEK = \
Expand All @@ -155,23 +153,11 @@ def testTemplate(self):
'Calendar:2012:Week 17',
'Calendar:2012:04',
):
page = ui.notebook.get_page(Path(path))
lines = template.process(ui.notebook, page)
page = notebook.get_page(Path(path))
lines = template.process(notebook, page)
text = ''.join(lines)
#~ print text
self.assertTrue(not 'Created' in text) # No fall back
if 'Week' in path:
days = [l for l in lines if l.startswith('=== ')]
self.assertEqual(len(days), 7)


class StubUI(tests.MockObject):

ui_type = 'gtk'

def __init__(self):
tests.MockObject.__init__(self)
self.notebook = tests.new_notebook()
self.page = self.notebook.get_page(Path('Test:foo'))
self.preferences = ConfigDict()
self.uistate = ConfigDict()
71 changes: 17 additions & 54 deletions tests/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def setupGtkInterface(test, klass=None):
path = Path('Test:foo:bar')
ui = klass(notebook=notebook, page=path)

# finalize plugins
for plugin in ui.plugins:
plugin.finalize_ui(ui)

ui.mainwindow.init_uistate()

return ui
Expand Down Expand Up @@ -336,9 +332,6 @@ def testPreferencesDialog(self):
gui = zim.gui.GtkInterface()
gui.register_preferences('GtkInterface', zim.gui.ui_preferences)
gui.register_preferences('PageView', zim.gui.pageview.ui_preferences)
with FilterFailedToLoadPlugin():
# may miss dependencies for e.g. versioncontrol
gui.load_plugins()
self.ui.preferences_register = gui.preferences_register
self.ui.preferences = gui.preferences
self.ui.plugins = gui.plugins
Expand Down Expand Up @@ -372,10 +365,10 @@ def testPreferencesDialog(self):
self.assertFalse(any(['use_custom_font' in d for d in self.ui.preferences.values()]))

## Plugin Config dialog
from zim.plugins import get_plugin
klass = get_plugin('calendar')
from zim.plugins.calendar import CalendarPlugin
plugin = CalendarPlugin()
pref_dialog = PreferencesDialog(self.ui)
dialog = PluginConfigureDialog(pref_dialog, klass)
dialog = PluginConfigureDialog(pref_dialog, plugin)
dialog.assert_response_ok()

def testTemplateEditorDialog(self):
Expand All @@ -395,70 +388,42 @@ class FilterNoSuchImageWarning(tests.LoggingFilter):
message = 'No such image:'


class FilterFailedToLoadPlugin(tests.LoggingFilter):

logger = 'zim'
message = 'Failed to load plugin'


@tests.slowTest
class TestGtkInterface(tests.TestCase):

def setUp(self):
with FilterFailedToLoadPlugin():
# may miss dependencies for e.g. versioncontrol
self.ui = setupGtkInterface(self)
self.ui = setupGtkInterface(self)

def tearDown(self):
self.ui.close()

def testInitialization(self):
'''Test Gtk interface initialization'''

# start without notebook should not complain
ui = zim.gui.GtkInterface()

# now take ui with notebook
ui = self.ui

# test read only (starts readonly because notebook has no dir or file)
self.assertTrue(ui.readonly)
ui.set_readonly(False)
self.assertFalse(ui.readonly)
ui.set_readonly(True)
self.assertTrue(ui.readonly)
self.assertTrue(self.ui.readonly)
self.ui.set_readonly(False)
self.assertFalse(self.ui.readonly)
self.ui.set_readonly(True)
self.assertTrue(self.ui.readonly)

# TODO more tests for readonly pages etc.

# test populating menus
menu = gtk.Menu()
ui.populate_popup('page_popup', menu)
self.ui.populate_popup('page_popup', menu)
items = menu.get_children()
self.assertGreater(len(items), 3)

# open notebook (so the default plugins are loaded)
nb = ui.notebook
ui.notebook = None
ui.open_notebook(nb)

# remove plugins
self.assertGreaterEqual(len(ui.plugins), 3) # default plugins without dependencies
plugins = [p.plugin_key for p in ui.plugins]
for name in plugins:
ui.unload_plugin(name)
self.assertEqual(len(ui.plugins), 0)

# and add them again
for name in plugins:
ui.load_plugin(name)
self.assertGreaterEqual(len(ui.plugins), 3) # default plugins without dependencies

# check registering an URL handler
func = tests.Counter(True)
ui.register_url_handler('foo', func)
ui.open_url('foo://bar')
self.ui.register_url_handler('foo', func)
self.ui.open_url('foo://bar')
self.assertTrue(func.count == 1)
ui.unregister_url_handler(func)
self.ui.unregister_url_handler(func)

# check default plugins are loaded
self.assertGreaterEqual(len(self.ui.plugins), 3)

def testMainWindow(self):
'''Test main window'''
Expand Down Expand Up @@ -645,9 +610,7 @@ def __init__(self, *arg, **kwarg):
):
self.mock_method(method, None)

with FilterFailedToLoadPlugin():
# may miss dependencies for e.g. versioncontrol
self.ui = setupGtkInterface(self, klass=MyMock)
self.ui = setupGtkInterface(self, klass=MyMock)

def tearDown(self):
self.ui.close()
Expand Down
22 changes: 13 additions & 9 deletions tests/imagegenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import tests

import gtk

from zim.fs import Dir

from zim.plugins.base.imagegenerator import ImageGeneratorDialog

from zim.plugins.equationeditor import *
from zim.plugins.diagrameditor import *
from zim.plugins.gnu_r_ploteditor import *
Expand All @@ -17,14 +21,18 @@
@tests.slowTest
class TestGenerator(tests.TestCase):

dialogklass = ImageGeneratorDialog

def _test_generator(self):
plugin = tests.MockObject()

# Check properties
self.assertIsNotNone(self.generatorklass.type)
self.assertIsNotNone(self.generatorklass.object_type)
self.assertIsNotNone(self.generatorklass.scriptname)
self.assertIsNotNone(self.generatorklass.imagename)

# Input OK
generator = self.generatorklass()
generator = self.generatorklass(plugin)
generator.cleanup() # ensure files did not yet exist
imagefile, logfile = generator.generate_image(self.validinput)
self.assertTrue(imagefile.exists())
Expand All @@ -40,7 +48,7 @@ def _test_generator(self):
self.assertFalse(logfile.exists())

# Input NOK
generator = self.generatorklass()
generator = self.generatorklass(plugin)
imagefile, logfile = generator.generate_image(self.invalidinput)
self.assertIsNone(imagefile)
if generator.uses_log_file:
Expand All @@ -50,7 +58,7 @@ def _test_generator(self):

# Dialog OK
attachment_dir = Dir(self.create_tmp_dir())
dialog = self.dialogklass(MockUI(attachment_dir))
dialog = self.dialogklass(MockUI(attachment_dir), '<title>', generator)
dialog.set_text(self.validinput)
dialog.assert_response_ok()

Expand All @@ -60,7 +68,7 @@ def ok_store(dialog):
dialog.do_response(gtk.RESPONSE_YES)

with tests.DialogContext(ok_store):
dialog = self.dialogklass(MockUI(attachment_dir))
dialog = self.dialogklass(MockUI(attachment_dir), '<title>', generator)
dialog.set_text(self.invalidinput)
dialog.assert_response_ok()

Expand All @@ -75,7 +83,6 @@ class TestEquationEditor(TestGenerator):

def setUp(self):
self.generatorklass = EquationGenerator
self.dialogklass = InsertEquationDialog
self.validinput = r'''
c = \sqrt{ a^2 + b^2 }
Expand All @@ -99,7 +106,6 @@ class TestDiagramEditor(TestGenerator):

def setUp(self):
self.generatorklass = DiagramGenerator
self.dialogklass = InsertDiagramDialog
self.validinput = r'''
digraph G {
foo -> bar
Expand All @@ -119,7 +125,6 @@ class TestGNURPlotEditor(TestGenerator):

def setUp(self):
self.generatorklass = GNURPlotGenerator
self.dialogklass = InsertGNURPlotDialog
self.validinput = r'''
x = seq(-4,4,by=0.01)
y = sin(x) + 1
Expand All @@ -137,7 +142,6 @@ class TestGnuplotEditor(TestGenerator):

def setUp(self):
self.generatorklass = GnuplotGenerator
self.dialogklass = InsertGnuplotDialog
self.validinput = r'plot sin(x), cos(x)'
self.invalidinput = r'sdf sdfsdf sdf'

Expand Down
18 changes: 2 additions & 16 deletions tests/inlinecalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class TestPrintToBrowser(tests.TestCase):

def runTest(self):
'Test InlineCalculator plugin'
ui = StubUI()
pluginklass = zim.plugins.get_plugin('inlinecalculator')
plugin = pluginklass(ui)
pluginklass = zim.plugins.get_plugin_class('inlinecalculator')
plugin = pluginklass()

for text, wanted in (
('3 + 4 =', '3 + 4 = 7'),
Expand Down Expand Up @@ -81,16 +80,3 @@ def runTest(self):
self.assertRaises(Exception, plugin.process_text, 'open("/etc/passwd")') # global
self.assertRaises(Exception, plugin.process_text, 'self') # local


class StubUI(object):

ui_type = 'stub'

def __init__(self):
self.notebook = tests.new_notebook()
self.preferences = ConfigDict()
self.uistate = ConfigDict()

def connect(*a): pass

def connect_after(*a): pass
30 changes: 12 additions & 18 deletions tests/insertsymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@
class TestInsertSymbolPlugin(tests.TestCase):

def runTest(self):
ui = MockUI()
plugin = InsertSymbolPlugin(ui)
plugin.finalize_ui(ui)
plugin = InsertSymbolPlugin()

pageview = ui.mainwindow.pageview
pageview = setUpPageView()
textview = pageview.view
buffer = textview.get_buffer()
pageview.undostack = UndoStackManager(buffer)

mainwindow = tests.MockObject()
mainwindow.pageview = pageview
mainwindow.ui = tests.MockObject() # XXX
mainwindow.ui.uimanager = tests.MockObject() # XXX
mainwindow.ui.uistate = ConfigDict()

plugin.extend(mainwindow, 'MainWindow')

print '\n!! Two GtkWarnings expected here for gdk display !!'
# Need a window to get the widget realized
window = gtk.Window()
Expand Down Expand Up @@ -73,20 +79,8 @@ def check_dialog(dialog):
dialog.assert_response_ok()

buffer.clear()
mainwindow_ext = plugin.get_extension(MainWindowExtension)
with tests.DialogContext(check_dialog):
plugin.insert_symbol()
mainwindow_ext.insert_symbol()
text = buffer.get_text(*buffer.get_bounds())
self.assertEqual(text, EACUTE + ECIRC + EGRAVE)


class MockUI(tests.MockObject):

ui_type = 'gtk'

def __init__(self):
tests.MockObject.__init__(self)
self.preferences = ConfigDict()
self.uistate = ConfigDict()
self.mainwindow = tests.MockObject()
self.mainwindow.pageview = setUpPageView()
self.windows = []
Loading

0 comments on commit beb221e

Please sign in to comment.