[d-feet/fix-bugs-in-mr-7: 1/5] settings: fix regexp syntax, add a test
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet/fix-bugs-in-mr-7: 1/5] settings: fix regexp syntax, add a test
- Date: Wed, 19 Sep 2018 19:41:36 +0000 (UTC)
commit 539bcc128bc8a60affa00cca009561790506622a
Author: Will Thompson <will willthompson co uk>
Date: Wed Sep 19 20:38:47 2018 +0100
settings: fix regexp syntax, add a test
Trying to compile this regexp fails with:
re.error: unbalanced parenthesis at position 5
I introduced this bug in 45a1146e1122b376ddac312687e8e27d4e0a8076. Fix
it, and add a small test case that would have caught it.
src/dfeet/settings.py | 2 +-
src/tests/tests.py.in | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
---
diff --git a/src/dfeet/settings.py b/src/dfeet/settings.py
index ca61bbd..c7c2f10 100644
--- a/src/dfeet/settings.py
+++ b/src/dfeet/settings.py
@@ -27,7 +27,7 @@ class ConfigTokenizer():
class Match():
ENDWHITESPACE = re.compile(r'\s$')
- UNESCAPE = re.compile(r'\\\(.)')
+ UNESCAPE = re.compile(r'\\(.)')
def __init__(self, match, regex):
self.match = match
diff --git a/src/tests/tests.py.in b/src/tests/tests.py.in
index 152bef3..93cef12 100755
--- a/src/tests/tests.py.in
+++ b/src/tests/tests.py.in
@@ -2,11 +2,13 @@
# -*- coding: utf-8 -*-
import sys
import os
+import tempfile
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../")))
from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import GLib
+from dfeet.settings import Settings
from dfeet.introspection import AddressInfo
from dfeet.introspection_helper import DBusNode
from dfeet.introspection_helper import DBusInterface
@@ -104,6 +106,41 @@ class AddressInfoTest(unittest.TestCase):
pass
+class SettingsTest(unittest.TestCase):
+ """Tests for the Settings class.
+
+ Why does it reimplement list values around ConfigParser rather than using
+ GKeyFile which supports list values directly? Nobody knows.
+ """
+
+ def setUp(self):
+ self.tempfile = tempfile.NamedTemporaryFile()
+
+ def tearDown(self):
+ self.tempfile.close()
+
+ def test_read_empty(self):
+ settings = Settings(self.tempfile.name)
+
+ self.assertIn('windowwidth', settings.general)
+ self.assertIn('windowheight', settings.general)
+ self.assertEqual([], settings.general['addbus_list'])
+
+ def test_write(self):
+ settings = Settings(self.tempfile.name)
+ settings.general['windowwidth'] = 800
+ settings.general['windowheight'] = 600
+ settings.general['addbus_list'] = ['a', 'b']
+ settings.write()
+
+ # Reload with a new instance
+ settings = Settings(self.tempfile.name)
+ # FIXME: yes, these come back out as strings
+ self.assertEqual('800', settings.general['windowwidth'])
+ self.assertEqual('600', settings.general['windowheight'])
+ self.assertEqual(['a', 'b'], settings.general['addbus_list'])
+
+
if __name__ == "__main__":
# run tests
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]