コード例 #1
0
ファイル: history.py プロジェクト: thorhans/zimt
    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())
コード例 #2
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	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())
コード例 #3
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	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))
コード例 #4
0
ファイル: history.py プロジェクト: thorhans/zimt
    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))
コード例 #5
0
ファイル: history.py プロジェクト: Jam71/Zim-QDA
	def testRobustness(self):
		'''Test history can deal with garbage data'''
		uistate = ConfigDict()
		uistate['list'] = 'FOOOO'
		uistate['recent'] = [["BARRRR", 0]]
		uistate['cursor'] = 'Not an integer'
		history = History(self.notebook, uistate)
		self.assertEqual(list(history.get_history()), [])
		self.assertEqual(list(history.get_recent()), [])
		self.assertIsNone(history.get_current())
コード例 #6
0
ファイル: history.py プロジェクト: damiansimanuk/texslide
	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))
コード例 #7
0
ファイル: history.py プロジェクト: damiansimanuk/texslide
	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)
コード例 #8
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	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)
コード例 #9
0
ファイル: history.py プロジェクト: thorhans/zimt
    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)
コード例 #10
0
ファイル: history.py プロジェクト: thorhans/zimt
    def testRobustness(self):
        '''Test history can deal with garbage data'''
        uistate = INIConfigFile(VirtualFile([]))
        uistate['History'].input({
            'list': 'FOOOO',
            'recent': [["BARRRR", 0]],
            'cursor': 'Not an integer',
        })

        with tests.LoggingFilter(logger='zim.config',
                                 message='Invalid config'):
            with tests.LoggingFilter(logger='zim.history',
                                     message='Could not parse'):
                history = History(self.notebook, uistate)
        self.assertEqual(list(history.get_history()), [])
        self.assertEqual(list(history.get_recent()), [])
        self.assertIsNone(history.get_current())
コード例 #11
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	def testRobustness(self):
		'''Test history can deal with garbage data'''
		uistate = INIConfigFile(VirtualFile([]))
		uistate['History'].input({
			'list': 'FOOOO',
			'recent': [["BARRRR", 0]],
			'cursor': 'Not an integer',
		})

		with tests.LoggingFilter(
			logger='zim.config',
			message='Invalid config'
		):
			with tests.LoggingFilter(
				logger='zim.history',
				message='Could not parse'
			):
				history = History(self.notebook, uistate)
		self.assertEqual(list(history.get_history()), [])
		self.assertEqual(list(history.get_recent()), [])
		self.assertIsNone(history.get_current())
コード例 #12
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	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))
コード例 #13
0
ファイル: history.py プロジェクト: thorhans/zimt
    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))
コード例 #14
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	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:])
コード例 #15
0
ファイル: history.py プロジェクト: fabricehong/zim-desktop
	def assertCurrentEquals(self, history, path):
		current = history.get_current()
		self.assertTrue(isinstance(current, HistoryPath))
		self.assertEqual(current.name, path.name)
コード例 #16
0
ファイル: history.py プロジェクト: thorhans/zimt
 def assertCurrentEquals(self, history, path):
     current = history.get_current()
     self.assertTrue(isinstance(current, HistoryPath))
     self.assertEqual(current.name, path.name)
コード例 #17
0
ファイル: history.py プロジェクト: damiansimanuk/texslide
	def _assertCurrent(self, history, page):
		current = history.get_current()
		self.assertTrue(isinstance(current, HistoryRecord))
		self.assertEqual(current.name, page.name)
コード例 #18
0
ファイル: history.py プロジェクト: thorhans/zimt
    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:])