Skip to content

Commit

Permalink
Ported all plugins to new framework - still number open issues + test…
Browse files Browse the repository at this point in the history
… cases to do
  • Loading branch information
jaap-karssenberg committed Aug 17, 2013
1 parent c2b5155 commit d29bac2
Show file tree
Hide file tree
Showing 44 changed files with 1,956 additions and 2,281 deletions.
2 changes: 1 addition & 1 deletion tests/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def testRenamePageDialogWithHeadingChanges(self):
tree.set_heading("different")
dialog = zim.gui.RenamePageDialog(self.ui, path=Path("Test:foo:bar"))
self.assertFalse(dialog.form['head'])

def testDeletePageDialog(self):
'''Test DeletePageDialog'''
# just check inputs are OK - skip output
Expand Down
72 changes: 41 additions & 31 deletions tests/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@

import os

import zim.plugins
import zim
import zim.config

from zim.plugins import *
from zim.fs import File


assert len(zim.plugins.__path__) > 1 # test __path__ magic
zim.plugins.__path__ = [os.path.abspath('./zim/plugins')] # set back default search path


class testPlugins(tests.TestCase):
class TestPlugins(tests.TestCase):

def testListAll(self):
'''Test loading plugins and meta data'''
plugins = zim.plugins.list_plugins()
def runTest(self):
plugins = list_plugins()
self.assertTrue(len(plugins) > 10)
self.assertTrue('spell' in plugins)
self.assertTrue('linkmap' in plugins)
Expand All @@ -37,26 +34,26 @@ def testListAll(self):
}
for name in plugins:
#~ print '>>', name
plugin = zim.plugins.get_plugin(name)
klass = get_plugin_klass(name)

# test plugin info
for key in ('name', 'description', 'author'):
self.assertTrue(
plugin.plugin_info.get(key),
klass.plugin_info.get(key),
'Plugin %s misses info field \'%s\'' % (name, key)
)

for key in ('name', 'description', 'help'):
self.assertIn(key, plugin.plugin_info, 'Plugin %s missing "%s"' % (name, key))
value = plugin.plugin_info[key]
self.assertIn(key, klass.plugin_info, 'Plugin %s missing "%s"' % (name, key))
value = klass.plugin_info[key]
self.assertFalse(
value in seen[key],
'Value for \'%s\' in %s seen before - copy-paste error ?' % (key, name)
)
seen[key].add(value)

# test manual page present and at least documents preferences
page = plugin.plugin_info['help']
page = klass.plugin_info['help']
self.assertTrue(page.startswith('Plugins:'), 'Help page for %s not valid' % name)

rellink = "+%s" % page[8:]
Expand All @@ -66,15 +63,15 @@ def testListAll(self):
self.assertTrue(file.exists(), 'Missing file: %s' % file)

manual = file.read()
for pref in plugin.plugin_preferences:
for pref in klass.plugin_preferences:
label = pref[2]
if '\n' in label:
label, x = label.split('\n', 1)
label = label.rstrip(',')
self.assertIn(label, manual, 'Preference "%s" for %s plugin not documented in manual page' % (label, name))

# test dependencies data
dep = plugin.check_dependencies()
dep = klass.check_dependencies()
self.assertTrue(isinstance(dep,tuple))
check, dep = dep
self.assertTrue(isinstance(check,bool))
Expand All @@ -86,21 +83,34 @@ def testListAll(self):
self.assertTrue(isinstance(dep[i][2],bool))

# test is_profile_independent
self.assertTrue(isinstance(plugin.is_profile_independent,bool))
self.assertTrue(isinstance(klass.is_profile_independent,bool))
if name in profile_independent:
self.assertTrue(plugin.is_profile_independent)
self.assertTrue(klass.is_profile_independent)
else:
self.assertFalse(plugin.is_profile_independent)

def testDefaulPlugins(self):
'''Test loading default plugins'''
# Note that we use parent interface class here, so plugins
# will not really attach - just testing loading and prereq
# checks are OK.
notebook = tests.new_notebook()
interface = zim.NotebookInterface(notebook)
interface.uistate = zim.config.ConfigDict()
interface.load_plugins()
self.assertTrue(len(interface.plugins) > 3)

# TODO: create a full GtkUI object and load & unload each plugin in turn
self.assertFalse(klass.is_profile_independent)


class TestPluginManager(tests.TestCase):

def runTest(self):
manager = PluginManager()
for name in list_plugins():
klass = get_plugin_klass(name)
if klass.check_dependencies_ok():
manager.load_plugin(name)
self.assertIn(name, manager)

self.assertTrue(len(manager) > 3)

for name in manager:
manager[name].emit('preferences-changed')
# just checking for exceptions

for name in manager:
self.assertIsInstance(manager[name], PluginClass)
manager.remove_plugin(name)
self.assertNotIn(name, manager)

self.assertTrue(len(manager) == 0)

# TODO test extending some objects
4 changes: 2 additions & 2 deletions zim.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
argv = [arg.decode(encoding) for arg in sys.argv]
#~ zim.set_executable(argv[0])
zim.__main__.main(*argv[1:])
except zim.GetoptError, err:
except zim.__main__.GetoptError, err:
print >>sys.stderr, sys.argv[0]+':', err
sys.exit(1)
except zim.UsageError, err:
except zim.__main__.UsageError, err:
print >>sys.stderr, err.msg
sys.exit(1)
except KeyboardInterrupt: # e.g. <Ctrl>C while --server
Expand Down
Loading

0 comments on commit d29bac2

Please sign in to comment.