summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2017-08-17 12:34:50 -0700
committerGitHub <noreply@github.com>2017-08-17 12:34:50 -0700
commit188d79a0189b480656542a09be348fcbf506f33d (patch)
treead5b1a09e19056905b020459ce50b50d65e2679b
parentadc4fbb3595b059ae98b683fe57add578c3c2b86 (diff)
parent6d20c4ae8f1130bd29b14ea52014b394e0a1c4a4 (diff)
Merge pull request #1095 from dcbaker/submit/use-default-theme-if-no-config
Load default settings even if a user config doesn't exist
-rw-r--r--alot/settings/manager.py9
-rw-r--r--docs/source/conf.py3
-rw-r--r--tests/settings/manager_test.py31
3 files changed, 35 insertions, 8 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py
index 01eec053..6f9273c2 100644
--- a/alot/settings/manager.py
+++ b/alot/settings/manager.py
@@ -41,7 +41,6 @@ class SettingsManager(object):
assert notmuch_rc is None or (isinstance(notmuch_rc, basestring) and os.path.exists(notmuch_rc))
self.hooks = None
self._mailcaps = mailcap.getcaps()
- self._config = ConfigObj()
self._notmuchconfig = None
self._theme = None
self._accounts = None
@@ -69,15 +68,11 @@ class SettingsManager(object):
def read_notmuch_config(self):
"""parse notmuch's config file from path"""
- if self.notmuch_rc_path is not None:
- spec = os.path.join(DEFAULTSPATH, 'notmuch.rc.spec')
- self._notmuchconfig = read_config(self.notmuch_rc_path, spec)
+ spec = os.path.join(DEFAULTSPATH, 'notmuch.rc.spec')
+ self._notmuchconfig = read_config(self.notmuch_rc_path, spec)
def read_config(self):
"""parse alot's config file from path"""
- if self.alot_rc_path is None:
- return
-
spec = os.path.join(DEFAULTSPATH, 'alot.rc.spec')
newconfig = read_config(
self.alot_rc_path, spec, checks={
diff --git a/docs/source/conf.py b/docs/source/conf.py
index e096cc89..6a822a7f 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -36,7 +36,8 @@ MOCK_MODULES = ['twisted', 'twisted.internet',
'gpg',
'configobj',
'validate',
- 'argparse']
+ 'argparse',
+ 'alot.settings.const']
MOCK_DIRTY = ['notmuch']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = MockModule()
diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py
index e0c48444..0ce29259 100644
--- a/tests/settings/manager_test.py
+++ b/tests/settings/manager_test.py
@@ -63,6 +63,37 @@ class TestSettingsManager(unittest.TestCase):
actual = manager.get_notmuch_setting('maildir', 'synchronize_flags')
self.assertTrue(actual)
+ def test_read_config_doesnt_exist(self):
+ """If there is not an alot config things don't break.
+
+ This specifically tests for issue #1094, which is caused by the
+ defaults not being loaded if there isn't an alot config files, and thus
+ calls like `get_theming_attribute` fail with strange exceptions.
+ """
+ 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)
+
+ manager.get_theming_attribute('global', 'body')
+
+ def test_read_notmuch_config_doesnt_exist(self):
+ with tempfile.NamedTemporaryFile(delete=False) as f:
+ f.write(textwrap.dedent("""\
+ [accounts]
+ [[default]]
+ realname = That Guy
+ address = thatguy@example.com
+ """))
+ self.addCleanup(os.unlink, f.name)
+ manager = SettingsManager(alot_rc=f.name)
+
+ setting = manager.get_notmuch_setting('foo', 'bar')
+ self.assertIsNone(setting)
+
class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup):
"""Test the get_account_by_address helper."""