/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-15 16:23:15 UTC
  • mfrom: (170 trunk)
  • mto: (170.1.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 172.
  • Revision ID: szilveszter.farkas@gmail.com-20070315162315-rs1sbxjh31n314zc
MergeĀ fromĀ trunk.

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