示例#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
	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 项目: 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())
示例#4
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))
示例#5
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)
示例#6
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))
示例#7
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)
示例#8
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())
示例#9
0
	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())
示例#10
0
	def assertRecentEquals(self, history, pages):
		self._checkPaths(history.get_recent(), pages, RecentPath)
示例#11
0
文件: history.py 项目: thorhans/zimt
 def assertRecentEquals(self, history, pages):
     self._checkPaths(history.get_recent(), pages, RecentPath)