Esempio n. 1
0
	def testUIInterface(self):
		# test ui.new_page_from_text()

		name = 'foo:new page quicknote'
		text = '''\
======= New Page =======
Test 1 2 3

attachment {{./zim16.png}}
'''
		wanted = '''\
<?xml version='1.0' encoding='utf-8'?>
<zim-tree><h level="1">New Page</h>
<p>Test 1 2 3
</p>
<p>attachment <img src="./zim16.png" />
</p></zim-tree>'''

		dirname = self.create_tmp_dir(name='import_source')
		File('./icons/zim16.png').copyto(Dir(dirname))

		ui = setupGtkInterface(self)
		path = ui.new_page_from_text(text, name, attachments=dirname)
		page = ui.notebook.get_page(path)
		attachments = ui.notebook.get_attachments_dir(path)

		self.assertEqual(page.get_parsetree().tostring(), wanted)
		self.assertIn('zim16.png', attachments.list())
Esempio n. 2
0
	def runTest(self):
		plugin = VersionControlPlugin()

		dir = get_tmp_dir('versioncontrol_TestMainWindowExtension')
		notebook = tests.new_files_notebook(dir)
		ui = setupGtkInterface(self, notebook=notebook)
		plugin.extend(notebook)
		plugin.extend(ui.mainwindow)

		notebook_ext = plugin.get_extension(NotebookExtension)
		self.assertIsInstance(notebook_ext, NotebookExtension)

		window_ext = plugin.get_extension(MainWindowExtension)
		self.assertIsInstance(window_ext, MainWindowExtension)

		## init & save version
		self.assertIsNone(notebook_ext.vcs)

		def init(dialog):
			self.assertIsInstance(dialog, VersionControlInitDialog)
			choice = dialog.combobox.get_active_text()
			self.assertTrue(choice and not choice.isspace())
			dialog.emit('response', gtk.RESPONSE_YES)

		with tests.DialogContext(init, SaveVersionDialog):
			window_ext.save_version()

		self.assertIsNotNone(notebook_ext.vcs)

		window_ext._autosave_thread.join()
		self.assertFalse(notebook_ext.vcs.modified)

		## save version again
		page = notebook.get_page(Path('Foo'))
		page.parse('wiki', 'foo!')
		notebook.store_page(page)

		self.assertTrue(notebook_ext.vcs.modified)

		with tests.DialogContext(SaveVersionDialog):
			window_ext.save_version()

		window_ext._autosave_thread.join()

		self.assertFalse(notebook_ext.vcs.modified)

		## show versions
		with tests.DialogContext(VersionsDialog):
			window_ext.show_versions()

		## auto-save
		plugin.preferences['autosave'] = True

		page = notebook.get_page(Path('Fooooo'))
		page.parse('wiki', 'foo!')
		notebook.store_page(page)

		self.assertTrue(notebook_ext.vcs.modified)
		ui.emit('quit')
		self.assertFalse(notebook_ext.vcs.modified)
Esempio n. 3
0
    def runTest(self):
        manager = PluginManager()
        preferences = manager.config.get_config_dict(
            '<profile>/preferences.conf')
        self.assertFalse(preferences.modified)
        for name in list_plugins():
            klass = get_plugin_class(name)
            if klass.check_dependencies_ok():
                manager.load_plugin(name)
                self.assertIn(name, manager)

                self.assertFalse(
                    preferences.modified,
                    'Plugin "%s" modified the preferences while loading' %
                    name)

        self.assertTrue(len(manager) > 3)

        for i, name in enumerate(manager):
            manager[name].preferences.emit('changed')
            # Checking for exceptions and infinite recursion

        self.assertTrue(i > 0)
        #~ self.assertTrue(preferences.modified)
        # If "False" the check while loading the plugins is not valid
        # FIXME this detection is broken due to autosave in ConfigManager ...

        notebook = tests.new_notebook(self.get_tmp_name())
        ui = setupGtkInterface(self, notebook=notebook)
        dialog = PropertiesDialog(ui)  # random dialog
        for obj in (
                notebook,
                notebook.index,
                ui.mainwindow,
                ui.mainwindow.pageview,
                dialog,
        ):
            manager.extend(obj)

        for i, name in enumerate(manager):
            manager[name].preferences.emit('changed')
            # Checking for exceptions and infinite recursion

        for name in manager:
            #~ print "REMOVE:", name
            self.assertIsInstance(manager[name], PluginClass)
            manager.remove_plugin(name)
            self.assertNotIn(name, manager)

        self.assertTrue(len(manager) == 0)
Esempio n. 4
0
	def runTest(self):
		manager = PluginManager()
		preferences = manager.config.get_config_dict('<profile>/preferences.conf')
		self.assertFalse(preferences.modified)
		for name in PluginManager.list_installed_plugins():
			klass = PluginManager.get_plugin_class(name)
			if klass.check_dependencies_ok():
				manager.load_plugin(name)
				self.assertIn(name, manager)

				self.assertFalse(preferences.modified,
					'Plugin "%s" modified the preferences while loading' % name)

		self.assertTrue(len(manager) > 3)

		for i, name in enumerate(manager):
			manager[name].preferences.emit('changed')
				# Checking for exceptions and infinite recursion

		self.assertTrue(i > 0)
		#~ self.assertTrue(preferences.modified)
			# If "False" the check while loading the plugins is not valid
			# FIXME this detection is broken due to autosave in ConfigManager ...

		notebook = tests.new_notebook(self.get_tmp_name())
		ui = setupGtkInterface(self, notebook=notebook)
		dialog = PropertiesDialog(ui) # random dialog
		for obj in (
			notebook,
			notebook.index,
			ui.mainwindow,
			ui.mainwindow.pageview,
			dialog,
		):
			manager.extend(obj)

		for i, name in enumerate(manager):
			manager[name].preferences.emit('changed')
				# Checking for exceptions and infinite recursion

		for name in manager:
			#~ print "REMOVE:", name
			self.assertIsInstance(manager[name], PluginClass)
			manager.remove_plugin(name)
			self.assertNotIn(name, manager)

		self.assertTrue(len(manager) == 0)
Esempio n. 5
0
    def testMainWindowExtensions(self):
        pluginklass = PluginManager.get_plugin_class('calendar')
        plugin = pluginklass()

        notebook = tests.new_notebook(self.get_tmp_name())
        ui = setupGtkInterface(self, notebook=notebook)
        mainwindow = ui._mainwindow  # XXX

        plugin.preferences['embedded'] = True
        self.assertEqual(plugin.extension_classes['MainWindow'],
                         MainWindowExtensionEmbedded)
        plugin.extend(mainwindow)

        ext = list(plugin.extensions)
        self.assertEqual(len(ext), 1)
        self.assertIsInstance(ext[0], MainWindowExtensionEmbedded)

        plugin.preferences.changed()  # make sure no errors are triggered

        ext[0].go_page_today()
        self.assertTrue(ui.page.name.startswith('Journal:'))

        plugin.preferences['embedded'] = False
        self.assertEqual(plugin.extension_classes['MainWindow'],
                         MainWindowExtensionDialog)
        plugin.extend(
            mainwindow)  # plugin does not remember objects, manager does that

        ext = list(plugin.extensions)
        self.assertEqual(len(ext), 1)
        self.assertIsInstance(ext[0], MainWindowExtensionDialog)

        plugin.preferences.changed()  # make sure no errors are triggered

        def test_dialog(dialog):
            self.assertIsInstance(dialog, CalendarDialog)
            dialog.do_today('xxx')
            ui.open_page(Path('foo'))

        with tests.DialogContext(test_dialog):
            ext[0].show_calendar()

        plugin.preferences['embedded'] = True  # switch back
Esempio n. 6
0
	def runTest(self, adapterclass):
		with tests.LoggingFilter(logger='zim.plugins.spell'): # Hide exceptions
			ui = setupGtkInterface(self)
			plugin = ui.plugins.load_plugin('spell')
			plugin.extend(ui.mainwindow)
			ext = plugin.get_extension(zim.plugins.spell.MainWindowExtension)

			self.assertIs(ext._adapter, adapterclass) # ensure switching library worked

			ext.toggle_spellcheck()
			ext.toggle_spellcheck()
			ext.toggle_spellcheck()

			ui.open_page(Path('Foo'))
			ui.open_page(Path('Bar'))
			ext.toggle_spellcheck()

			ui.open_page(Path('Foo'))
			ui.open_page(Path('Bar'))
			ext.toggle_spellcheck()
Esempio n. 7
0
File: calendar.py Progetto: gdw2/zim
	def testMainWindowExtensions(self):
		pluginklass = zim.plugins.get_plugin_class('calendar')
		plugin = pluginklass()

		notebook = tests.new_notebook(self.get_tmp_name())
		ui = setupGtkInterface(self, notebook=notebook)

		plugin.preferences['embedded'] = True
		self.assertEqual(plugin.extension_classes['MainWindow'], MainWindowExtensionEmbedded)
		plugin.extend(ui.mainwindow)

		ext = list(plugin.extensions)
		self.assertEqual(len(ext), 1)
		self.assertIsInstance(ext[0], MainWindowExtensionEmbedded)

		plugin.preferences.changed() # make sure no errors are triggered

		ext[0].go_page_today()
		self.assertTrue(ui.page.name.startswith('Journal:'))

		plugin.preferences['embedded'] = False
		self.assertEqual(plugin.extension_classes['MainWindow'], MainWindowExtensionDialog)
		plugin.extend(ui.mainwindow) # plugin does not remember objects, manager does that

		ext = list(plugin.extensions)
		self.assertEqual(len(ext), 1)
		self.assertIsInstance(ext[0], MainWindowExtensionDialog)

		plugin.preferences.changed() # make sure no errors are triggered

		def test_dialog(dialog):
			self.assertIsInstance(dialog, CalendarDialog)
			dialog.do_today('xxx')
			ui.open_page(Path('foo'))

		with tests.DialogContext(test_dialog):
			ext[0].show_calendar()


		plugin.preferences['embedded'] = True # switch back
Esempio n. 8
0
    def runTest(self, adapterclass):
        with tests.LoggingFilter(
                logger='zim.plugins.spell'):  # Hide exceptions
            ui = setupGtkInterface(self)
            plugin = ui.plugins.load_plugin('spell')
            plugin.extend(ui.mainwindow)
            ext = plugin.get_extension(zim.plugins.spell.MainWindowExtension)

            self.assertIs(ext._adapter,
                          adapterclass)  # ensure switching library worked

            ext.toggle_spellcheck()
            ext.toggle_spellcheck()
            ext.toggle_spellcheck()

            ui.open_page(Path('Foo'))
            ui.open_page(Path('Bar'))
            ext.toggle_spellcheck()

            ui.open_page(Path('Foo'))
            ui.open_page(Path('Bar'))
            ext.toggle_spellcheck()
Esempio n. 9
0
    def testMainWindowExtensions(self):
        plugin = ToCPlugin()

        notebook = tests.new_notebook(self.get_tmp_name())
        ui = setupGtkInterface(self, notebook=notebook)
        mainwindow = ui._mainwindow  # XXX

        plugin.preferences['floating'] = True
        self.assertEqual(plugin.extension_classes['MainWindow'],
                         MainWindowExtensionFloating)
        plugin.extend(mainwindow)

        ext = list(plugin.extensions)
        self.assertEqual(len(ext), 1)
        self.assertIsInstance(ext[0], MainWindowExtensionFloating)

        plugin.preferences.changed()  # make sure no errors are triggered
        plugin.preferences['show_h1'] = True
        plugin.preferences['show_h1'] = False
        plugin.preferences['pane'] = RIGHT_PANE
        plugin.preferences['pane'] = LEFT_PANE

        plugin.preferences['floating'] = False
        self.assertEqual(plugin.extension_classes['MainWindow'],
                         MainWindowExtensionEmbedded)
        plugin.extend(
            mainwindow)  # plugin does not remember objects, manager does that

        ext = list(plugin.extensions)
        self.assertEqual(len(ext), 1)
        self.assertIsInstance(ext[0], MainWindowExtensionEmbedded)

        plugin.preferences.changed()  # make sure no errors are triggered
        plugin.preferences['show_h1'] = True
        plugin.preferences['show_h1'] = False
        plugin.preferences['pane'] = RIGHT_PANE
        plugin.preferences['pane'] = LEFT_PANE

        plugin.preferences['floating'] = True  # switch back
Esempio n. 10
0
	def testMainWindowExtensions(self):
		plugin = ToCPlugin()

		notebook = tests.new_notebook(self.get_tmp_name())
		ui = setupGtkInterface(self, notebook=notebook)

		plugin.preferences['floating'] = True
		self.assertEqual(plugin.extension_classes['MainWindow'], MainWindowExtensionFloating)
		plugin.extend(ui.mainwindow)

		ext = list(plugin.extensions)
		self.assertEqual(len(ext), 1)
		self.assertIsInstance(ext[0], MainWindowExtensionFloating)

		plugin.preferences.changed() # make sure no errors are triggered
		plugin.preferences['show_h1'] = True
		plugin.preferences['show_h1'] = False
		plugin.preferences['pane'] = RIGHT_PANE
		plugin.preferences['pane'] = LEFT_PANE


		plugin.preferences['floating'] = False
		self.assertEqual(plugin.extension_classes['MainWindow'], MainWindowExtensionEmbedded)
		plugin.extend(ui.mainwindow) # plugin does not remember objects, manager does that

		ext = list(plugin.extensions)
		self.assertEqual(len(ext), 1)
		self.assertIsInstance(ext[0], MainWindowExtensionEmbedded)

		plugin.preferences.changed() # make sure no errors are triggered
		plugin.preferences['show_h1'] = True
		plugin.preferences['show_h1'] = False
		plugin.preferences['pane'] = RIGHT_PANE
		plugin.preferences['pane'] = LEFT_PANE

		plugin.preferences['floating'] = True  # switch back
Esempio n. 11
0
	def testToCWidget(self):
		'''Test Tabel Of Contents plugin'''
		notebook = tests.new_notebook(self.get_tmp_name())
		ui = setupGtkInterface(self, notebook=notebook)
		pageview = ui._mainwindow.pageview # XXX

		widget = ToCWidget(ui, pageview, ellipsis=False)

		def get_tree():
			# Count number of rows in TreeModel
			model = widget.treeview.get_model()
			rows = []
			def c(model, path, iter):
				rows.append((len(path), model[iter][TEXT_COL]))
			model.foreach(c)
			return rows

		page = ui.notebook.get_page(Path('Test'))
		page.parse('wiki', '''\
====== Foo ======

===== bar =====

line below could be mistaken for heading of the same name..

baz

sfsfsfsd

===== baz =====

sdfsdfsd

==== A ====

==== B ====

==== C ====

===== dus =====

sdfsdf

''')
		ui.notebook.store_page(page)
		#~ print page.get_parsetree().tostring()

		with_h1 = [
			(1, 'Foo'),
			(2, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(2, 'dus'),
		]
		without_h1 = [
			(1, 'bar'),
			(1, 'baz'),
			(2, 'A'),
			(2, 'B'),
			(2, 'C'),
			(1, 'dus'),
		]

		# Test basic usage - click some headings
		ui.open_page(page)
		widget.on_open_page(ui, page, page)
		self.assertEqual(get_tree(), without_h1)
		widget.on_store_page(ui.notebook, page)
		self.assertEqual(get_tree(), without_h1)

		widget.set_show_h1(True)
		self.assertEqual(get_tree(), with_h1)
		widget.set_show_h1(False)
		self.assertEqual(get_tree(), without_h1)

		column = widget.treeview.get_column(0)
		model = widget.treeview.get_model()
		def activate_row(m, path, i):
			#~ print ">>>", path
			widget.treeview.row_activated(path, column)
				# TODO assert something here

			widget.select_section(pageview.view.get_buffer(), path)

			menu = gtk.Menu()
			widget.treeview.get_selection().select_path(path)
			widget.on_populate_popup(widget.treeview, menu)
				# TODO assert something here
			widget.treeview.get_selection().unselect_path(path)

		model.foreach(activate_row)

		# Test promote / demote
		ui.set_readonly(False)
		pageview.set_readonly(False)
		wanted = [
			(1, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(1, 'dus'),
		]

		widget.treeview.get_selection().unselect_all()
		widget.treeview.get_selection().select_path((1,)) # "baz"
		self.assertFalse(widget.on_promote())
		self.assertTrue(widget.on_demote())
		self.assertEqual(get_tree(), wanted)

		widget.treeview.get_selection().unselect_all()
		widget.treeview.get_selection().select_path((0, 0)) # "baz"
		self.assertFalse(widget.on_demote())
		self.assertTrue(widget.on_promote())
		self.assertEqual(get_tree(), without_h1)

		# Test promote / demote multiple selected
		wanted = [
			(1, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(2, 'dus'),
		]

		widget.treeview.get_selection().unselect_all()
		for path in (
			(1,), (1,0), (1,1), (1,2), (2,) # "baz" -> "dus"
		):
			widget.treeview.get_selection().select_path(path)
		self.assertFalse(widget.on_promote())
		self.assertTrue(widget.on_demote())
		self.assertEqual(get_tree(), wanted)

		widget.treeview.get_selection().unselect_all()
		for path in (
			(0,0), (0,0,0), (0,0,1), (0,0,2), (0,1) # "baz" -> "dus"
		):
			widget.treeview.get_selection().select_path(path)
		self.assertFalse(widget.on_demote())
		self.assertTrue(widget.on_promote())
		self.assertEqual(get_tree(), without_h1)

		# Test empty page
		emptypage = tests.MockObject()
		widget.on_open_page(ui, emptypage, emptypage)
		self.assertEqual(get_tree(), [])
		widget.on_store_page(ui.notebook, emptypage)
		self.assertEqual(get_tree(), [])


		# Test some more pages - any errors ?
		for path in ui.notebook.pages.walk():
			page = ui.notebook.get_page(path)
			widget.on_open_page(ui, page, page)
			widget.on_store_page(ui.notebook, page)
Esempio n. 12
0
	def testToCWidget(self):
		'''Test Tabel Of Contents plugin'''
		notebook = tests.new_notebook(self.get_tmp_name())
		ui = setupGtkInterface(self, notebook=notebook)
		pageview = ui.mainwindow.pageview

		widget = ToCWidget(ui, pageview, ellipsis=False)

		def get_tree():
			# Count number of rows in TreeModel
			model = widget.treeview.get_model()
			rows = []
			def c(model, path, iter):
				rows.append((len(path), model[iter][TEXT_COL]))
			model.foreach(c)
			return rows

		page = ui.notebook.get_page(Path('Test'))
		page.parse('wiki', '''\
====== Foo ======

===== bar =====

line below could be mistaken for heading of the same name..

baz

sfsfsfsd

===== baz =====

sdfsdfsd

==== A ====

==== B ====

==== C ====

===== dus =====

sdfsdf

''')
		ui.notebook.store_page(page)
		#~ print page.get_parsetree().tostring()

		with_h1 = [
			(1, 'Foo'),
			(2, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(2, 'dus'),
		]
		without_h1 = [
			(1, 'bar'),
			(1, 'baz'),
			(2, 'A'),
			(2, 'B'),
			(2, 'C'),
			(1, 'dus'),
		]

		# Test basic usage - click some headings
		ui.open_page(page)
		widget.on_open_page(ui, page, page)
		self.assertEqual(get_tree(), without_h1)
		widget.on_stored_page(ui.notebook, page)
		self.assertEqual(get_tree(), without_h1)

		widget.set_show_h1(True)
		self.assertEqual(get_tree(), with_h1)
		widget.set_show_h1(False)
		self.assertEqual(get_tree(), without_h1)

		column = widget.treeview.get_column(0)
		model = widget.treeview.get_model()
		def activate_row(m, path, i):
			#~ print ">>>", path
			widget.treeview.row_activated(path, column)
				# TODO assert something here

			widget.select_section(pageview.view.get_buffer(), path)

			menu = gtk.Menu()
			widget.treeview.get_selection().select_path(path)
			widget.on_populate_popup(widget.treeview, menu)
				# TODO assert something here
			widget.treeview.get_selection().unselect_path(path)

		model.foreach(activate_row)

		# Test promote / demote
		ui.set_readonly(False)
		pageview.set_readonly(False)
		wanted = [
			(1, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(1, 'dus'),
		]

		widget.treeview.get_selection().unselect_all()
		widget.treeview.get_selection().select_path((1,)) # "baz"
		self.assertFalse(widget.on_promote())
		self.assertTrue(widget.on_demote())
		self.assertEqual(get_tree(), wanted)

		widget.treeview.get_selection().unselect_all()
		widget.treeview.get_selection().select_path((0, 0)) # "baz"
		self.assertFalse(widget.on_demote())
		self.assertTrue(widget.on_promote())
		self.assertEqual(get_tree(), without_h1)

		# Test promote / demote multiple selected
		wanted = [
			(1, 'bar'),
			(2, 'baz'),
			(3, 'A'),
			(3, 'B'),
			(3, 'C'),
			(2, 'dus'),
		]

		widget.treeview.get_selection().unselect_all()
		for path in (
			(1,), (1,0), (1,1), (1,2), (2,) # "baz" -> "dus"
		):
			widget.treeview.get_selection().select_path(path)
		self.assertFalse(widget.on_promote())
		self.assertTrue(widget.on_demote())
		self.assertEqual(get_tree(), wanted)

		widget.treeview.get_selection().unselect_all()
		for path in (
			(0,0), (0,0,0), (0,0,1), (0,0,2), (0,1) # "baz" -> "dus"
		):
			widget.treeview.get_selection().select_path(path)
		self.assertFalse(widget.on_demote())
		self.assertTrue(widget.on_promote())
		self.assertEqual(get_tree(), without_h1)

		# Test empty page
		emptypage = tests.MockObject()
		widget.on_open_page(ui, emptypage, emptypage)
		self.assertEqual(get_tree(), [])
		widget.on_stored_page(ui.notebook, emptypage)
		self.assertEqual(get_tree(), [])


		# Test some more pages - any errors ?
		for page in ui.notebook.walk():
			widget.on_open_page(ui, page, page)
			widget.on_stored_page(ui.notebook, page)