summaryrefslogtreecommitdiff
path: root/tests/settings
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-06-16 15:44:59 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-07-10 17:04:06 -0700
commit86186a242c11fcbc501e7afc791a50187e0dd574 (patch)
tree59a26b3c6237a236f7d5f9c58aa4b70305f502a4 /tests/settings
parent3056cc47bd2ea377ee5599b3f218ecff96fbb833 (diff)
settings: Add a reload method
This patch does a bit of refactoring to the Settings class for it's setup, and adds a reload method. The refactoring encapsulates the handling of NoneType for the read_*config methods, and reworks the constructor just a bit so that it doesn't rely on calling methods to create instance variables. The end result is slightly cleaner, and will be useful for adding a reload command to alot itself.
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/manager_test.py52
1 files changed, 40 insertions, 12 deletions
diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py
index 937c24d7..17a228a2 100644
--- a/tests/settings/manager_test.py
+++ b/tests/settings/manager_test.py
@@ -6,6 +6,9 @@
from __future__ import absolute_import
+import os
+import tempfile
+import textwrap
import unittest
from alot.settings.manager import SettingsManager
@@ -15,20 +18,45 @@ from alot.settings.errors import ConfigError
class TestSettingsManager(unittest.TestCase):
def test_reading_synchronize_flags_from_notmuch_config(self):
- config = [
- '[maildir]',
- 'synchronize_flags = true',
- ]
- manager = SettingsManager()
- manager.read_notmuch_config(config)
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(textwrap.dedent("""\
+ [maildir]
+ synchronize_flags = true
+ """))
+ self.addCleanup(os.unlink, f.name)
+
+ manager = SettingsManager(notmuch_rc=f.name)
actual = manager.get_notmuch_setting('maildir', 'synchronize_flags')
self.assertTrue(actual)
def test_parsing_notmuch_config_with_non_bool_synchronize_flag_fails(self):
- config = [
- '[maildir]',
- 'synchronize_flags = not bool'
- ]
- manager = SettingsManager()
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(textwrap.dedent("""\
+ [maildir]
+ synchronize_flags = not bool
+ """))
+ self.addCleanup(os.unlink, f.name)
+
with self.assertRaises(ConfigError):
- manager.read_notmuch_config(config)
+ SettingsManager(notmuch_rc=f.name)
+
+ def test_reload_notmuch_config(self):
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(textwrap.dedent("""\
+ [maildir]
+ synchronize_flags = false
+ """))
+ self.addCleanup(os.unlink, f.name)
+ manager = SettingsManager(notmuch_rc=f.name)
+
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(textwrap.dedent("""\
+ [maildir]
+ synchronize_flags = true
+ """))
+ self.addCleanup(os.unlink, f.name)
+
+ manager.notmuch_rc_path = f.name
+ manager.reload()
+ actual = manager.get_notmuch_setting('maildir', 'synchronize_flags')
+ self.assertTrue(actual)