File: windowtitleeditor.py

package info (click to toggle)
zim 0.76.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,952 kB
  • sloc: python: 68,612; xml: 1,270; javascript: 512; sh: 101; makefile: 47
file content (68 lines) | stat: -rw-r--r-- 2,056 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

# Copyright 2022 introt <introt@koti.fimnet.fi>

# based on original work (c) Jaap Karssenberg <jaap.karssenberg@gmail.com>

import tests

from tests.mainwindow import setUpMainWindow

from zim.notebook.page import Page, Path
from zim.gui.mainwindow import PageWindow, WindowBaseMixin
from zim.plugins.windowtitleeditor import (
		WindowTitleEditorPlugin,
		WindowTitleEditorExtension,
		READONLY)

class TestWindowTitleEditorExtension(tests.TestCase):

	def setUp(self):
		""" Successful setup indicates the monkey patching was successful... """
		self.plugin = WindowTitleEditorPlugin()
		self.window = setUpMainWindow(self.setUpNotebook())
		self.extension = WindowTitleEditorExtension(self.plugin, self.window)

	def testMonkeyPatch(self):
		""" ...but we test it anyway :) """
		self.assertEqual(
				self.window._update_window_title,
				self.extension.update_window_title,
				"Patching main window failed!")
		self.assertEqual(PageWindow.set_title.__module__,
				self.window._update_window_title.__module__,
				"Patching PageWindow failed!")

	def get_title(self):
		# used twice, just think of the convenience!
		return self.window.get_title()

	def testMainWindowApi(self):
		self.window.set_title('test')
		self.assertEqual(self.get_title(), 'test', "Can't get/set title!")

	def testMakeTitleWithCustomTemplate(self):
		n = self.window.notebook
		n.readonly = True
		p = self.window.page
		self.plugin.preferences['custom_format'] = ' $path;$page;$title;$source;' + \
				'$notebook;$folder$$Zim$ro'
		self.plugin.preferences['format'] = 'custom'
		self.assertEqual(
				self.get_title(),
				f'Test;Test;Test;{p.source_file};' + \
						f'testnotebook;{n.folder}$Zim{READONLY}'.strip(),
				"Templating broke!"
		)

	def testTeardown(self):
		self.extension.teardown()
		self.assertEqual(
				PageWindow.set_title,
				WindowBaseMixin.set_title,
				"Restoring PageWindow failed!"
		)
		self.assertEqual(
				self.window._update_window_title.__func__,
				self.window.__class__._update_window_title,
				"Restoring main window failed!"
		)