1
# Copyright (C) 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for saving and restoring recent history of locations"""
21
from bzrlib.plugins.explorer import tests
22
from bzrlib.plugins.explorer.lib import history_manager
23
from bzrlib.plugins.explorer.lib.extensions import accessories
26
class TestHistoryManager(tests.TestCaseInTempDir):
27
"""Tests for the HistoryManager class"""
30
super(TestHistoryManager, self).setUp()
31
directory = accessories.wallet_dir()
32
os.makedirs(directory)
33
self.history_filename = os.path.join(directory, "history.dat")
35
# TODO: add tests for correct basic operation here
37
def test_no_history_file(self):
38
history = history_manager.HistoryManager()
39
self.assertLength(0, history.recent_locations())
40
# Not having history.dat yet is normal so there should be no log spam
41
self.assertNotContainsRe(self.get_log(), "history.dat")
43
def test_broken_history_empty_file(self):
44
open(self.history_filename, "wb").close()
45
history = history_manager.HistoryManager()
46
self.assertLength(0, history.recent_locations())
47
self.assertContainsRe(self.get_log(), "explorer history.*history.dat")
49
def test_broken_history_zeroed_file(self):
50
f = open(self.history_filename, "wb")
55
history = history_manager.HistoryManager()
56
self.assertLength(0, history.recent_locations())
57
self.assertContainsRe(self.get_log(), "explorer history.*history.dat")