/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: Jelmer Vernooij
  • Date: 2007-02-03 15:24:48 UTC
  • Revision ID: jelmer@samba.org-20070203152448-65ovluij1jetb71l
Fix a couple of smaller bugs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2007 Jelmer Venrooij <jelmer@samba.org>
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
from bzrlib.tests import TestCase, TestCaseInTempDir
 
17
from bzrlib.tests import TestCase
18
18
from bzrlib.plugins.gtk.olive import Preferences
19
19
 
20
 
import os
21
 
 
22
20
# FIXME: need to make sure that this also tests writing/reading.
23
 
class TestPreferences(TestCaseInTempDir):
24
 
    def setUp(self):
25
 
        super(TestPreferences, self).setUp()
26
 
        self.prefs = Preferences(os.path.join(self.test_dir, 'prefs'))
27
 
 
 
21
class TestPreferences(TestCase):
28
22
    def test_create(self):
29
23
        Preferences()
30
24
 
31
25
    def test_add_bookmark(self):
32
26
        """make sure a bookmark can be added. This function is only supposed 
33
27
        to store the location, not try to access it. """
34
 
        self.assertTrue(self.prefs.add_bookmark("file://foobar"))
35
 
        self.assertTrue("file://foobar" in self.prefs.get_bookmarks())
 
28
        x = Preferences()
 
29
        self.assertTrue(x.add_bookmark("file://foobar"))
 
30
        self.assertTrue("file://foobar" in x.get_bookmarks())
36
31
 
37
32
    def test_add_bookmark_twice(self):
38
33
        """Adding an already present bookmark will result in False being 
39
34
        returned."""
40
 
        self.assertTrue(self.prefs.add_bookmark("file://foobar"))
41
 
        self.assertFalse(self.prefs.add_bookmark("file://foobar"))
 
35
        x = Preferences()
 
36
        self.assertTrue(x.add_bookmark("file://foobar"))
 
37
        self.assertFalse(x.add_bookmark("file://foobar"))
42
38
 
43
39
    def test_set_bookmark_title(self):
44
40
        """Test setting a title for an existing bookmark."""
45
 
        self.prefs.add_bookmark("file://foobar")
46
 
        self.prefs.set_bookmark_title("file://foobar", "My Bookmark")
 
41
        x = Preferences()
 
42
        x.add_bookmark("file://foobar")
 
43
        x.set_bookmark_title("file://foobar", "My Bookmark")
47
44
 
48
45
    def test_remove_bookmark(self):
49
46
        """Test removing a bookmark."""
50
 
        self.prefs.add_bookmark("http://example.com/branch")
51
 
        self.prefs.remove_bookmark("http://example.com/branch")
52
 
        self.assertFalse("http://example.com/branch" in self.prefs.get_bookmarks())
 
47
        x = Preferences()
 
48
        x.add_bookmark("http://example.com/branch")
 
49
        x.remove_bookmark("http://example.com/branch")
 
50
        self.assertFalse("http://example.com/branch" in x.get_bookmarks())
53
51
 
54
52
    def test_get_bookmarks_empty(self):
55
53
        """Test whether a new Preferences() object has an empty bookmarks 
56
54
        list."""
57
 
        self.assertEqual([], self.prefs.get_bookmarks())
 
55
        x = Preferences()
 
56
        self.assertEqual([], x.get_bookmarks())
58
57
 
59
58
    def test_get_bookmark_title_set(self):
60
59
        """Test getting a title for an existing bookmark."""
61
 
        self.prefs.add_bookmark("file://foobar")
62
 
        self.prefs.set_bookmark_title("file://foobar", "My Bookmark")
63
 
        self.assertEqual("My Bookmark", self.prefs.get_bookmark_title("file://foobar"))
 
60
        x = Preferences()
 
61
        x.add_bookmark("file://foobar")
 
62
        x.set_bookmark_title("file://foobar", "My Bookmark")
 
63
        self.assertEqual("My Bookmark", x.get_bookmark_title("file://foobar"))
64
64
 
65
65
    def test_get_bookmark_title_implicit(self):
66
66
        """Test getting a bookmark title for a bookmark that doesn't
67
67
        have a title set."""
68
 
        self.prefs.add_bookmark("file://bla")
69
 
        self.assertEqual("file://bla", self.prefs.get_bookmark_title("file://bla"))
 
68
        x = Preferences()
 
69
        x.add_bookmark("file://bla")
 
70
        self.assertEqual("file://bla", x.get_bookmark_title("file://bla"))
70
71
 
71
72
    def test_set_preference(self):
72
73
        """Check whether setting preferences works."""
73
 
        self.prefs.set_preference("foo", True)
74
 
        self.prefs.set_preference("foo", False)
75
 
        self.prefs.set_preference("foo", "bloe")
 
74
        x = Preferences()
 
75
        x.set_preference("foo", True)
 
76
        x.set_preference("foo", False)
 
77
        x.set_preference("foo", "bloe")
76
78
 
77
79
    def test_get_preference_bool(self):
78
80
        """Check whether a preference can be retrieved."""
79
 
        self.prefs.set_preference("foo", True)
80
 
        self.assertEqual(True, self.prefs.get_preference("foo", "bool"))
 
81
        x = Preferences()
 
82
        x.set_preference("foo", True)
 
83
        self.assertEqual(True, x.get_preference("foo", "bool"))
81
84
 
82
85
    def test_get_preference_str(self):
83
86
        """Check whether a string preference can be retrieved."""
84
 
        self.prefs.set_preference("bla", "bloe")
85
 
        self.assertEqual("bloe", self.prefs.get_preference("bla"))
 
87
        x = Preferences()
 
88
        x.set_preference("bla", "bloe")
 
89
        self.assertEqual("bloe", x.get_preference("bla"))
86
90
 
87
91
    def test_get_preference_nonexistant(self):
88
92
        """Check whether get_preference returns None for nonexisting 
89
93
        options."""
90
 
        self.assertEqual(None, self.prefs.get_preference("foo"))
 
94
        x = Preferences()
 
95
        self.assertEqual(None, x.get_preference("foo"))
91
96