Esempio n. 1
0
    def testState(self):
        history = History(self.notebook)
        for page in self.pages:
            history.append(page)
        self.assertHistoryEquals(history, self.pages)

        path = history.get_current()
        self.assertEqual(history.get_state(path), (None, None))
        path.cursor = 42
        self.assertEqual(history.get_state(path), (42, None))
Esempio n. 2
0
	def testState(self):
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)
		self.assertHistoryEquals(history, self.pages)

		path = history.get_current()
		self.assertEqual(history.get_state(path), (None, None))
		path.cursor = 42
		self.assertEqual(history.get_state(path), (42, None))
Esempio n. 3
0
    def testSerialize(self):
        '''Test parsing the history from the state file'''
        uistate = INIConfigFile(VirtualFile([]))
        history = History(self.notebook, uistate)

        for page in self.pages:
            history.append(page)
        self.assertHistoryEquals(history, self.pages)
        self.assertCurrentEquals(history, self.pages[-1])

        # rewind 2
        for i in range(2):
            prev = history.get_previous()
            history.set_current(prev)

        # check state
        #~ import pprint
        #~ pprint.pprint(uistate)
        self.assertHistoryEquals(history, uistate['History']['list'])
        self.assertRecentEquals(history, uistate['History']['recent'])
        self.assertEqual(uistate['History']['current'], len(self.pages) - 3)

        # clone uistate by text
        lines = uistate.dump()
        newuistate = INIConfigFile(VirtualFile(lines))
        newuistate['History'].setdefault('list', [])
        newuistate['History'].setdefault('recent', [])
        newuistate['History'].setdefault('current', 0)

        # check new state
        self.assertHistoryEquals(
            history, [Path(t[0]) for t in newuistate['History']['list']])
        self.assertRecentEquals(
            history, [Path(t[0]) for t in newuistate['History']['recent']])
        self.assertEqual(newuistate['History']['current'], len(self.pages) - 3)

        # and compare resulting history object
        newhistory = History(self.notebook, newuistate)
        self.assertEqual(list(newhistory.get_history()),
                         list(history.get_history()))
        self.assertEqual(list(newhistory.get_recent()),
                         list(history.get_recent()))
        self.assertEqual(newhistory.get_current(), history.get_current())

        # Check recent is initialized if needed
        newuistate = INIConfigFile(VirtualFile(lines))
        newuistate['History'].setdefault('recent', [])
        newuistate['History'].pop('recent')
        newhistory = History(self.notebook, newuistate)

        self.assertEqual(list(newhistory.get_history()),
                         list(history.get_history()))
        self.assertEqual(list(newhistory.get_recent()),
                         list(history.get_recent()))
        self.assertEqual(newhistory.get_current(), history.get_current())
Esempio n. 4
0
	def testSerialize(self):
		'''Test parsing the history from the state file'''
		uistate = INIConfigFile(VirtualFile([]))
		history = History(self.notebook, uistate)

		for page in self.pages:
			history.append(page)
		self.assertHistoryEquals(history, self.pages)
		self.assertCurrentEquals(history, self.pages[-1])

		# rewind 2
		for i in range(2):
			prev = history.get_previous()
			history.set_current(prev)

		# check state
		#~ import pprint
		#~ pprint.pprint(uistate)
		self.assertHistoryEquals(history, uistate['History']['list'])
		self.assertRecentEquals(history, uistate['History']['recent'])
		self.assertEqual(uistate['History']['current'], len(self.pages) - 3)

		# clone uistate by text
		lines = uistate.dump()
		newuistate = INIConfigFile(VirtualFile(lines))
		newuistate['History'].setdefault('list', [])
		newuistate['History'].setdefault('recent', [])
		newuistate['History'].setdefault('current', 0)

		# check new state
		self.assertHistoryEquals(history, [Path(t[0]) for t in newuistate['History']['list']])
		self.assertRecentEquals(history, [Path(t[0]) for t in newuistate['History']['recent']])
		self.assertEqual(newuistate['History']['current'], len(self.pages) - 3)

		# and compare resulting history object
		newhistory = History(self.notebook, newuistate)
		self.assertEqual(list(newhistory.get_history()), list(history.get_history()))
		self.assertEqual(list(newhistory.get_recent()), list(history.get_recent()))
		self.assertEqual(newhistory.get_current(), history.get_current())

		# Check recent is initialized if needed
		newuistate = INIConfigFile(VirtualFile(lines))
		newuistate['History'].setdefault('recent', [])
		newuistate['History'].pop('recent')
		newhistory = History(self.notebook, newuistate)

		self.assertEqual(list(newhistory.get_history()), list(history.get_history()))
		self.assertEqual(list(newhistory.get_recent()), list(history.get_recent()))
		self.assertEqual(newhistory.get_current(), history.get_current())
Esempio n. 5
0
	def testChildren(self):
		'''Test getting namespace from history'''
		history = History(self.notebook)
		for name in ('Test:wiki', 'Test:foo:bar', 'Test:foo', 'TODOList:bar'):
			page = self.notebook.get_page(Path(name))
			history.append(page)

		self.assertEqual(history.get_child(Path('Test')), Path('Test:foo'))
		self.assertEqual(history.get_grandchild(Path('Test')), Path('Test:foo:bar'))
		self.assertEqual(history.get_child(Path('NonExistent')), None)
		self.assertEqual(history.get_grandchild(Path('NonExistent')), None)

		history.append(self.notebook.get_page(Path('Test:wiki')))
		self.assertEqual(history.get_child(Path('Test')), Path('Test:wiki'))
		self.assertEqual(history.get_grandchild(Path('Test')), Path('Test:wiki'))
Esempio n. 6
0
	def testMovePage(self):
		'''Test history is updated for moved pages'''
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)

		self.assertIn(Path('Test:wiki'), list(history.get_history()))

		history._on_page_moved(self.notebook, Path('Test'), Path('New'), False)
		self.assertNotIn(Path('Test:wiki'), list(history.get_history()))
		self.assertIn(Path('New:wiki'), list(history.get_history()))

		history._on_page_moved(self.notebook, Path('New'), Path('Test'), False)
		self.assertNotIn(Path('New:wiki'), list(history.get_history()))
		self.assertIn(Path('Test:wiki'), list(history.get_history()))

		self.assertHistoryEquals(history, self.pages)
Esempio n. 7
0
    def testMovePage(self):
        '''Test history is updated for moved pages'''
        history = History(self.notebook)
        for page in self.pages:
            history.append(page)

        self.assertIn(Path('Test:wiki'), list(history.get_history()))

        history._on_page_moved(self.notebook, Path('Test'), Path('New'))
        self.assertNotIn(Path('Test:wiki'), list(history.get_history()))
        self.assertIn(Path('New:wiki'), list(history.get_history()))

        history._on_page_moved(self.notebook, Path('New'), Path('Test'))
        self.assertNotIn(Path('New:wiki'), list(history.get_history()))
        self.assertIn(Path('Test:wiki'), list(history.get_history()))

        self.assertHistoryEquals(history, self.pages)
Esempio n. 8
0
	def testUnique(self):
		'''Get recent pages from history'''
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)
		self.assertEqual(len(history.history), len(self.pages))

		unique = list(history.get_unique())
		self.assertEqual(unique[0], history.get_current())
		self.assertEqual(len(unique), len(self.pages))

		for page in self.pages:
			history.append(page)
		self.assertEqual(len(history.history), 2*len(self.pages))

		unique = list(history.get_unique())
		self.assertEqual(unique[0], history.get_current())
		self.assertEqual(len(unique), len(self.pages))

		unique = set([page.name for page in unique]) # collapse doubles
		self.assertEqual(len(unique), len(self.pages))
Esempio n. 9
0
	def testDeletedNotInUnique(self):
		'''Test if deleted pages and their children show up in unique history list'''
		zim.history.MAX_RECENT = len(self.pages) + 1
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)
		for page in self.pages:
			history.append(page)

		self.assertHistoryEquals(history, 2 * self.pages)

		uniques = list(history.get_recent())
		self.assertEqual(len(uniques), len(self.pages))

		page = history.get_current()
		history._on_page_deleted(self.notebook, page)
		uniques = list(history.get_recent())
		self.assertTrue(len(uniques) < len(self.pages))
		i = len(uniques)

		history.set_current(page)
		uniques = list(history.get_recent())
		self.assertEqual(len(uniques), i + 1)
			# Not same as len(self.pages) because of deleted children

		for page in self.pages:
			history._on_page_deleted(self.notebook, page)
		uniques = list(history.get_recent())
		self.assertEqual(len(uniques), 0)

		self.assertEqual(
			len(list(history.get_history())),
			2 * len(self.pages)  )

		for page in history.get_history():
			history.set_current(page)
		uniques = list(history.get_recent())
		self.assertEqual(len(uniques), len(self.pages))
Esempio n. 10
0
	def testLinear(self):
		'''Walk back and forth through the history'''
		history = History(self.notebook)
		self.assertTrue(history.get_current() is None)
		for page in self.pages:
			history.append(page)
		self.assertEqual(len(history.history), len(self.pages))

		self._assertCurrent(history, self.pages[-1])

		pages = list(history.get_history())
		self.assertEqual(pages[0], history.get_current())
		self.assertEqual(len(pages), len(self.pages))

		# walk backwards
		for i in range(2, len(self.pages)+1):
			prev = history.get_previous()
			self.assertFalse(prev is None)
			self.assertEqual(prev.name, self.pages[-i].name)
			self.assertFalse(prev.is_last)
			history.set_current(prev)

		self._assertCurrent(history, self.pages[0])
		self.assertTrue(history.get_previous() is None)
		self.assertTrue(prev.is_first)

		# walk forward
		for i in range(1, len(self.pages)):
			next = history.get_next()
			self.assertFalse(next is None)
			self.assertEqual(next.name, self.pages[i].name)
			self.assertFalse(next.is_first)
			history.set_current(next)

		self._assertCurrent(history, self.pages[-1])
		self.assertTrue(history.get_next() is None)
		self.assertTrue(history.get_current().is_last)
Esempio n. 11
0
	def testSerialize(self):
		'''Test parsing the history from the state file'''
		uistate = ConfigDict()
		history = History(self.notebook, uistate)

		for page in self.pages:
			history.append(page)
		self.assertEqual(len(history.history), len(self.pages))
		self._assertCurrent(history, self.pages[-1])

		# rewind 2
		for i in range(2):
			prev = history.get_previous()
			history.set_current(prev)

		# check state
		#~ import pprint
		#~ pprint.pprint(uistate)
		self.assertEqual(len(uistate['History']['history']), len(history.history))
		#~ self.assertEqual(len(uistate['History']['pages']), len(history.history))
		self.assertEqual(uistate['History']['current'], len(history.history)-3)

		# clone uistate by text
		lines = uistate.dump()
		newuistate = ConfigDict()
		newuistate.parse(lines)

		# check new state
		self.assertEqual(len(uistate['History']['history']), len(history.history))
		#~ self.assertEqual(len(newuistate['History']['pages']), len(history.history))
		self.assertEqual(newuistate['History']['current'], len(history.history)-3)

		# and compare resulting history object
		newhistory = History(self.notebook, newuistate)
		self.assertEqual(newhistory.history, history.history)
		self.assertEqual(newhistory.current, history.current)
Esempio n. 12
0
    def testDeletedNotInUnique(self):
        '''Test if deleted pages and their children show up in unique history list'''
        zim.history.MAX_RECENT = len(self.pages) + 1
        history = History(self.notebook)
        for page in self.pages:
            history.append(page)
        for page in self.pages:
            history.append(page)

        self.assertHistoryEquals(history, 2 * self.pages)

        uniques = list(history.get_recent())
        self.assertEqual(len(uniques), len(self.pages))

        page = history.get_current()
        history._on_page_deleted(self.notebook, page)
        uniques = list(history.get_recent())
        self.assertTrue(len(uniques) < len(self.pages))
        i = len(uniques)

        history.set_current(page)
        uniques = list(history.get_recent())
        self.assertEqual(len(uniques), i + 1)
        # Not same as len(self.pages) because of deleted children

        for page in self.pages:
            history._on_page_deleted(self.notebook, page)
        uniques = list(history.get_recent())
        self.assertEqual(len(uniques), 0)

        self.assertEqual(len(list(history.get_history())), 2 * len(self.pages))

        for page in history.get_history():
            history.set_current(page)
        uniques = list(history.get_recent())
        self.assertEqual(len(uniques), len(self.pages))
Esempio n. 13
0
    def testChildren(self):
        '''Test getting namespace from history'''
        history = History(self.notebook)
        for name in ('Test:wiki', 'Test:foo:bar', 'Test:foo', 'TaskList:bar'):
            page = self.notebook.get_page(Path(name))
            history.append(page)

        self.assertEqual(history.get_child(Path('Test')), Path('Test:foo'))
        self.assertEqual(history.get_grandchild(Path('Test')),
                         Path('Test:foo:bar'))
        self.assertEqual(history.get_child(Path('NonExistent')), None)
        self.assertEqual(history.get_grandchild(Path('NonExistent')), None)

        history.append(self.notebook.get_page(Path('Test:wiki')))
        self.assertEqual(history.get_child(Path('Test')), Path('Test:wiki'))
        self.assertEqual(history.get_grandchild(Path('Test')),
                         Path('Test:wiki'))

        page = self.notebook.get_page(Path('Some:deep:nested:page'))
        history.append(page)
        self.assertEqual(history.get_child(Path('Some')), Path('Some:deep'))
        self.assertEqual(history.get_grandchild(Path('Some')),
                         Path('Some:deep:nested:page'))
Esempio n. 14
0
	def testUnique(self):
		'''Get recent pages from history'''
		default_max_recent = zim.history.MAX_RECENT

		zim.history.MAX_RECENT = len(self.pages) + 1
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)
		self.assertHistoryEquals(history, self.pages)

		unique = list(history.get_recent())
		self.assertEqual(unique[0], history.get_current())
		self.assertEqual(len(unique), len(self.pages))

		for page in self.pages:
			history.append(page)
		self.assertHistoryEquals(history, 2 * self.pages)

		unique = list(history.get_recent())
		self.assertEqual(unique[0], history.get_current())
		self.assertEqual(len(unique), len(self.pages))

		unique = set([page.name for page in unique]) # collapse doubles
		self.assertEqual(len(unique), len(self.pages))

		zim.history.MAX_RECENT = 3
		history = History(self.notebook)
		for page in self.pages:
			history.append(page)
		zim.history.MAX_RECENT = default_max_recent

		self.assertHistoryEquals(history, self.pages)

		unique = list(history.get_recent())
		self.assertEqual(unique[0], history.get_current())
		self.assertEqual(len(unique), 3)
Esempio n. 15
0
    def testUnique(self):
        '''Get recent pages from history'''
        default_max_recent = zim.history.MAX_RECENT

        zim.history.MAX_RECENT = len(self.pages) + 1
        history = History(self.notebook)
        for page in self.pages:
            history.append(page)
        self.assertHistoryEquals(history, self.pages)

        unique = list(history.get_recent())
        self.assertEqual(unique[0], history.get_current())
        self.assertEqual(len(unique), len(self.pages))

        for page in self.pages:
            history.append(page)
        self.assertHistoryEquals(history, 2 * self.pages)

        unique = list(history.get_recent())
        self.assertEqual(unique[0], history.get_current())
        self.assertEqual(len(unique), len(self.pages))

        unique = {page.name for page in unique}  # collapse doubles
        self.assertEqual(len(unique), len(self.pages))

        zim.history.MAX_RECENT = 3
        history = History(self.notebook)
        for page in self.pages:
            history.append(page)
        zim.history.MAX_RECENT = default_max_recent

        self.assertHistoryEquals(history, self.pages)

        unique = list(history.get_recent())
        self.assertEqual(unique[0], history.get_current())
        self.assertEqual(len(unique), 3)
Esempio n. 16
0
	def testLinear(self):
		'''Walk back and forth through the history'''
		history = History(self.notebook)
		self.assertTrue(history.get_current() is None)
		for page in self.pages:
			history.append(page)
		self.assertHistoryEquals(history, self.pages)
		self.assertCurrentEquals(history, self.pages[-1])

		pages = list(history.get_history())
		self.assertEqual(pages[0], history.get_current())
		self.assertEqual(len(pages), len(self.pages))

		self.assertEqual(pages[0].cursor, None)
			# Newly appended pages should not have the cursor
			# set - pageview has logic to do the right thing when
			# no cursor is set. Setting default e.g. 0 will
			# overrule this logic.

		# walk backwards
		for i in range(2, len(self.pages)+1):
			prev = history.get_previous()
			self.assertFalse(prev is None)
			self.assertEqual(prev.name, self.pages[-i].name)
			self.assertFalse(prev.is_last)
			history.set_current(prev)

		self.assertCurrentEquals(history, self.pages[0])
		self.assertTrue(history.get_previous() is None)
		self.assertTrue(prev.is_first)
		self.assertHistoryEquals(history, self.pages)

		# walk forward
		for i in range(1, len(self.pages)):
			next = history.get_next()
			self.assertFalse(next is None)
			self.assertEqual(next.name, self.pages[i].name)
			self.assertFalse(next.is_first)
			history.set_current(next)

		self.assertCurrentEquals(history, self.pages[-1])
		self.assertTrue(history.get_next() is None)
		self.assertTrue(history.get_current().is_last)
		self.assertHistoryEquals(history, self.pages)

		# Add page multiple times
		current = history.get_current()
		path = Path(current.name)
		for j in range(5):
			history.append(path)
		self.assertHistoryEquals(history, self.pages) # history does not store duplicates
		self.assertEquals(history.get_current(), current)

		# Test dropping forward stack
		historylist = list(history.get_history())
		path1 = historylist[10]
		path2 = historylist[0]
		history.set_current(path1)
		self.assertEquals(history.get_current(), path1) # rewind
		self.assertHistoryEquals(history, self.pages) # no change

		history.append(path2) # new path - drop forward stack
		i = len(pages) - 10
		wanted = self.pages[:i] + [path2]
		self.assertHistoryEquals(history, wanted)

		# Test max entries
		default_max_history = zim.history.MAX_HISTORY
		zim.history.MAX_HISTORY = 3
		for page in self.pages:
			history.append(page)
		zim.history.MAX_HISTORY = default_max_history

		self.assertHistoryEquals(history, self.pages[-3:])
Esempio n. 17
0
    def testLinear(self):
        '''Walk back and forth through the history'''
        history = History(self.notebook)
        self.assertTrue(history.get_current() is None)
        for page in self.pages:
            history.append(page)
        self.assertHistoryEquals(history, self.pages)
        self.assertCurrentEquals(history, self.pages[-1])

        pages = list(history.get_history())
        self.assertEqual(pages[0], history.get_current())
        self.assertEqual(len(pages), len(self.pages))

        self.assertEqual(pages[0].cursor, None)
        # Newly appended pages should not have the cursor
        # set - pageview has logic to do the right thing when
        # no cursor is set. Setting default e.g. 0 will
        # overrule this logic.

        # walk backwards
        for i in range(2, len(self.pages) + 1):
            prev = history.get_previous()
            self.assertFalse(prev is None)
            self.assertEqual(prev.name, self.pages[-i].name)
            self.assertFalse(prev.is_last)
            history.set_current(prev)

        self.assertCurrentEquals(history, self.pages[0])
        self.assertTrue(history.get_previous() is None)
        self.assertTrue(prev.is_first)
        self.assertHistoryEquals(history, self.pages)

        # walk forward
        for i in range(1, len(self.pages)):
            next = history.get_next()
            self.assertFalse(next is None)
            self.assertEqual(next.name, self.pages[i].name)
            self.assertFalse(next.is_first)
            history.set_current(next)

        self.assertCurrentEquals(history, self.pages[-1])
        self.assertTrue(history.get_next() is None)
        self.assertTrue(history.get_current().is_last)
        self.assertHistoryEquals(history, self.pages)

        # Add page multiple times
        current = history.get_current()
        path = Path(current.name)
        for j in range(5):
            history.append(path)
        self.assertHistoryEquals(
            history, self.pages)  # history does not store duplicates
        self.assertEqual(history.get_current(), current)

        # Test dropping forward stack
        historylist = list(history.get_history())
        path1 = historylist[10]
        path2 = historylist[0]
        history.set_current(path1)
        self.assertEqual(history.get_current(), path1)  # rewind
        self.assertHistoryEquals(history, self.pages)  # no change

        history.append(path2)  # new path - drop forward stack
        i = len(pages) - 10
        wanted = self.pages[:i] + [path2]
        self.assertHistoryEquals(history, wanted)

        # Test max entries
        default_max_history = zim.history.MAX_HISTORY
        zim.history.MAX_HISTORY = 3
        for page in self.pages:
            history.append(page)
        zim.history.MAX_HISTORY = default_max_history

        self.assertHistoryEquals(history, self.pages[-3:])