14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from tempfile import gettempdir
17
20
from bzrlib.tests import TestCase
18
21
from bzrlib.plugins.gtk.olive import Preferences
20
23
# FIXME: need to make sure that this also tests writing/reading.
21
24
class TestPreferences(TestCase):
22
25
def test_create(self):
26
Preferences(gettempdir() + os.sep + 'bzrgtktest.conf')
25
28
def test_add_bookmark(self):
26
29
"""make sure a bookmark can be added. This function is only supposed
27
30
to store the location, not try to access it. """
31
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_add_bookmark.conf')
29
32
self.assertTrue(x.add_bookmark("file://foobar"))
30
33
self.assertTrue("file://foobar" in x.get_bookmarks())
32
35
def test_add_bookmark_twice(self):
33
36
"""Adding an already present bookmark will result in False being
38
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_add_bookmark_twice.conf')
36
39
self.assertTrue(x.add_bookmark("file://foobar"))
37
40
self.assertFalse(x.add_bookmark("file://foobar"))
39
42
def test_set_bookmark_title(self):
40
43
"""Test setting a title for an existing bookmark."""
44
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_set_bookmark_title.conf')
42
45
x.add_bookmark("file://foobar")
43
46
x.set_bookmark_title("file://foobar", "My Bookmark")
45
48
def test_remove_bookmark(self):
46
49
"""Test removing a bookmark."""
50
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_remove_bookmark.conf')
48
51
x.add_bookmark("http://example.com/branch")
49
52
x.remove_bookmark("http://example.com/branch")
50
53
self.assertFalse("http://example.com/branch" in x.get_bookmarks())
52
55
def test_get_bookmarks_empty(self):
53
56
"""Test whether a new Preferences() object has an empty bookmarks
58
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_bookmarks_empty.conf')
56
59
self.assertEqual([], x.get_bookmarks())
58
61
def test_get_bookmark_title_set(self):
59
62
"""Test getting a title for an existing bookmark."""
63
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_bookmark_title_set.conf')
61
64
x.add_bookmark("file://foobar")
62
65
x.set_bookmark_title("file://foobar", "My Bookmark")
63
66
self.assertEqual("My Bookmark", x.get_bookmark_title("file://foobar"))
65
68
def test_get_bookmark_title_implicit(self):
66
69
"""Test getting a bookmark title for a bookmark that doesn't
67
70
have a title set."""
71
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_bookmark_title_implicit.conf')
69
72
x.add_bookmark("file://bla")
70
73
self.assertEqual("file://bla", x.get_bookmark_title("file://bla"))
72
75
def test_set_preference(self):
73
76
"""Check whether setting preferences works."""
77
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_set_preference.conf')
75
78
x.set_preference("foo", True)
76
79
x.set_preference("foo", False)
77
80
x.set_preference("foo", "bloe")
79
82
def test_get_preference_bool(self):
80
83
"""Check whether a preference can be retrieved."""
84
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_preference_bool.conf')
82
85
x.set_preference("foo", True)
83
86
self.assertEqual(True, x.get_preference("foo", "bool"))
85
88
def test_get_preference_str(self):
86
89
"""Check whether a string preference can be retrieved."""
90
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_preference_str.conf')
88
91
x.set_preference("bla", "bloe")
89
92
self.assertEqual("bloe", x.get_preference("bla"))
91
94
def test_get_preference_nonexistant(self):
92
95
"""Check whether get_preference returns None for nonexisting
97
x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_preference_nonexistant.conf')
95
98
self.assertEqual(None, x.get_preference("foo"))