/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_preferences.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2007-03-03 13:34:51 UTC
  • mto: (170.1.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 172.
  • Revision ID: szilveszter.farkas@gmail.com-20070303133451-r6m6ibw55bkm29f0
Make test suite not fail if Olive was run before.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
 
17
import os
 
18
from tempfile import gettempdir
 
19
 
17
20
from bzrlib.tests import TestCase
18
21
from bzrlib.plugins.gtk.olive import Preferences
19
22
 
20
23
# FIXME: need to make sure that this also tests writing/reading.
21
24
class TestPreferences(TestCase):
22
25
    def test_create(self):
23
 
        Preferences()
 
26
        Preferences(gettempdir() + os.sep + 'bzrgtktest.conf')
24
27
 
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. """
28
 
        x = Preferences()
 
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())
31
34
 
32
35
    def test_add_bookmark_twice(self):
33
36
        """Adding an already present bookmark will result in False being 
34
37
        returned."""
35
 
        x = Preferences()
 
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"))
38
41
 
39
42
    def test_set_bookmark_title(self):
40
43
        """Test setting a title for an existing bookmark."""
41
 
        x = Preferences()
 
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")
44
47
 
45
48
    def test_remove_bookmark(self):
46
49
        """Test removing a bookmark."""
47
 
        x = Preferences()
 
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 
54
57
        list."""
55
 
        x = Preferences()
 
58
        x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_bookmarks_empty.conf')
56
59
        self.assertEqual([], x.get_bookmarks())
57
60
 
58
61
    def test_get_bookmark_title_set(self):
59
62
        """Test getting a title for an existing bookmark."""
60
 
        x = Preferences()
 
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."""
68
 
        x = Preferences()
 
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"))
71
74
 
72
75
    def test_set_preference(self):
73
76
        """Check whether setting preferences works."""
74
 
        x = Preferences()
 
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")
78
81
 
79
82
    def test_get_preference_bool(self):
80
83
        """Check whether a preference can be retrieved."""
81
 
        x = Preferences()
 
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"))
84
87
 
85
88
    def test_get_preference_str(self):
86
89
        """Check whether a string preference can be retrieved."""
87
 
        x = Preferences()
 
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"))
90
93
 
91
94
    def test_get_preference_nonexistant(self):
92
95
        """Check whether get_preference returns None for nonexisting 
93
96
        options."""
94
 
        x = Preferences()
 
97
        x = Preferences(gettempdir() + os.sep + 'bzrgtktest_get_preference_nonexistant.conf')
95
98
        self.assertEqual(None, x.get_preference("foo"))
96
99