Rev 170: Add test argument to Preferences(). in file:///home/jelmer/bzr-gtk/trunk/
Jelmer Vernooij
jelmer at samba.org
Tue Mar 13 11:38:39 GMT 2007
At file:///home/jelmer/bzr-gtk/trunk/
------------------------------------------------------------
revno: 170
revision-id: jelmer at samba.org-20070313113834-vxkz3l62u6ubkvcc
parent: jelmer at samba.org-20070309190506-f168z6k43zk3gf4c
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Tue 2007-03-13 12:38:34 +0100
message:
Add test argument to Preferences().
modified:
olive/__init__.py __init__.py-20060925014013-13wdvwl8vi8gfqi1-2
tests/test_preferences.py test_preferences.py-20070203104345-ztgnupeolrh4sbey-1
=== modified file 'olive/__init__.py'
--- a/olive/__init__.py 2007-02-15 18:55:47 +0000
+++ b/olive/__init__.py 2007-03-13 11:38:34 +0000
@@ -931,7 +931,7 @@
class Preferences:
""" A class which handles Olive's preferences. """
- def __init__(self):
+ def __init__(self, path=None):
""" Initialize the Preferences class. """
# Some default options
self.defaults = { 'strict_commit' : False,
@@ -944,6 +944,16 @@
# Create a config parser object
self.config = ConfigParser.RawConfigParser()
+
+ # Set filename
+ if path is None:
+ if sys.platform == 'win32':
+ # Windows - no dotted files
+ self._filename = os.path.expanduser('~/olive.conf')
+ else:
+ self._filename = os.path.expanduser('~/.olive.conf')
+ else:
+ self._filename = path
# Load the configuration
self.read()
@@ -968,23 +978,13 @@
""" Just read the configuration. """
# Re-initialize the config parser object to avoid some bugs
self.config = ConfigParser.RawConfigParser()
- if sys.platform == 'win32':
- # Windows - no dotted files
- self.config.read([os.path.expanduser('~/olive.conf')])
- else:
- self.config.read([os.path.expanduser('~/.olive.conf')])
+ self.config.read([self._filename])
def write(self):
""" Write the configuration to the appropriate files. """
- if sys.platform == 'win32':
- # Windows - no dotted files
- fp = open(os.path.expanduser('~/olive.conf'), 'w')
- self.config.write(fp)
- fp.close()
- else:
- fp = open(os.path.expanduser('~/.olive.conf'), 'w')
- self.config.write(fp)
- fp.close()
+ fp = open(self._filename, 'w')
+ self.config.write(fp)
+ fp.close()
def get_bookmarks(self):
""" Return the list of bookmarks. """
=== modified file 'tests/test_preferences.py'
--- a/tests/test_preferences.py 2007-03-09 19:05:06 +0000
+++ b/tests/test_preferences.py 2007-03-13 11:38:34 +0000
@@ -14,83 +14,78 @@
# 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.tests import TestCase, TestCaseInTempDir
from bzrlib.plugins.gtk.olive import Preferences
+import os
+
# FIXME: need to make sure that this also tests writing/reading.
-class TestPreferences(TestCase):
+class TestPreferences(TestCaseInTempDir):
+ def setUp(self):
+ super(TestPreferences, self).setUp()
+ self.prefs = Preferences(os.path.join(self.test_dir, 'prefs'))
+
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())
+ self.assertTrue(self.prefs.add_bookmark("file://foobar"))
+ self.assertTrue("file://foobar" in self.prefs.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"))
+ self.assertTrue(self.prefs.add_bookmark("file://foobar"))
+ self.assertFalse(self.prefs.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")
+ self.prefs.add_bookmark("file://foobar")
+ self.prefs.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())
+ self.prefs.add_bookmark("http://example.com/branch")
+ self.prefs.remove_bookmark("http://example.com/branch")
+ self.assertFalse("http://example.com/branch" in self.prefs.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())
+ self.assertEqual([], self.prefs.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"))
+ self.prefs.add_bookmark("file://foobar")
+ self.prefs.set_bookmark_title("file://foobar", "My Bookmark")
+ self.assertEqual("My Bookmark", self.prefs.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"))
+ self.prefs.add_bookmark("file://bla")
+ self.assertEqual("file://bla", self.prefs.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")
+ self.prefs.set_preference("foo", True)
+ self.prefs.set_preference("foo", False)
+ self.prefs.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"))
+ self.prefs.set_preference("foo", True)
+ self.assertEqual(True, self.prefs.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"))
+ self.prefs.set_preference("bla", "bloe")
+ self.assertEqual("bloe", self.prefs.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"))
+ self.assertEqual(None, self.prefs.get_preference("foo"))
More information about the bazaar-commits
mailing list