1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# Copyright (C) 2007 Jelmer Venrooij <jelmer@samba.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from bzrlib.tests import TestCase
from bzrlib.plugins.gtk.olive import Preferences
# FIXME: need to make sure that this also tests writing/reading.
class TestPreferences(TestCase):
def test_create(self):
Preferences()
def test_add_bookmark(self):
"""make sure a bookmark can be added. This function is only supposed
to store the location, not try to access it. """
x = Preferences()
self.assertTrue(x.add_bookmark("file://foobar"))
self.assertTrue("file://foobar" in x.get_bookmarks())
def test_add_bookmark_twice(self):
"""Adding an already present bookmark will result in False being
returned."""
x = Preferences()
self.assertTrue(x.add_bookmark("file://foobar"))
self.assertFalse(x.add_bookmark("file://foobar"))
def test_set_bookmark_title(self):
"""Test setting a title for an existing bookmark."""
x = Preferences()
x.add_bookmark("file://foobar")
x.set_bookmark_title("file://foobar", "My Bookmark")
def test_remove_bookmark(self):
"""Test removing a bookmark."""
x = Preferences()
x.add_bookmark("http://example.com/branch")
x.remove_bookmark("http://example.com/branch")
self.assertFalse("http://example.com/branch" in x.get_bookmarks())
def test_get_bookmarks_empty(self):
"""Test whether a new Preferences() object has an empty bookmarks
list."""
x = Preferences()
self.assertEqual([], x.get_bookmarks())
def test_get_bookmark_title_set(self):
"""Test getting a title for an existing bookmark."""
x = Preferences()
x.add_bookmark("file://foobar")
x.set_bookmark_title("file://foobar", "My Bookmark")
self.assertEqual("My Bookmark", x.get_bookmark_title("file://foobar"))
def test_get_bookmark_title_implicit(self):
"""Test getting a bookmark title for a bookmark that doesn't
have a title set."""
x = Preferences()
x.add_bookmark("file://bla")
self.assertEqual("file://bla", x.get_bookmark_title("file://bla"))
def test_set_preference(self):
"""Check whether setting preferences works."""
x = Preferences()
x.set_preference("foo", True)
x.set_preference("foo", False)
x.set_preference("foo", "bloe")
def test_get_preference_bool(self):
"""Check whether a preference can be retrieved."""
x = Preferences()
x.set_preference("foo", True)
self.assertEqual(True, x.get_preference("foo", "bool"))
def test_get_preference_str(self):
"""Check whether a string preference can be retrieved."""
x = Preferences()
x.set_preference("bla", "bloe")
self.assertEqual("bloe", x.get_preference("bla"))
def test_get_preference_nonexistant(self):
"""Check whether get_preference returns None for nonexisting
options."""
x = Preferences()
self.assertEqual(None, x.get_preference("foo"))
|