From 8ceb87c911fbfa010e4a9bf1ad098f4b632724d1 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Aug 2017 11:05:06 -0700 Subject: tests/settings/manager: Add tests for Null config files Which fail, per #1094 --- tests/settings/manager_test.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py index 3201ad41..04f35504 100644 --- a/tests/settings/manager_test.py +++ b/tests/settings/manager_test.py @@ -63,6 +63,39 @@ class TestSettingsManager(unittest.TestCase): actual = manager.get_notmuch_setting('maildir', 'synchronize_flags') self.assertTrue(actual) + @unittest.expectedFailure + 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') + + @unittest.expectedFailure + 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.""" -- cgit v1.2.3 From 6d20c4ae8f1130bd29b14ea52014b394e0a1c4a4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Aug 2017 11:07:52 -0700 Subject: settings: Load spec file even if config file is undefined. This is necessary even if the config file is None to ensure that the spec file is loaded Also mock out the setting.const module in the docs, otherwise they'll fail to generate. Fixes #1094 --- alot/settings/manager.py | 8 ++------ docs/source/conf.py | 3 ++- tests/settings/manager_test.py | 2 -- 3 files changed, 4 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 0d926ae4..55f7a30b 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -67,15 +67,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 04f35504..81604882 100644 --- a/tests/settings/manager_test.py +++ b/tests/settings/manager_test.py @@ -63,7 +63,6 @@ class TestSettingsManager(unittest.TestCase): actual = manager.get_notmuch_setting('maildir', 'synchronize_flags') self.assertTrue(actual) - @unittest.expectedFailure def test_read_config_doesnt_exist(self): """If there is not an alot config things don't break. @@ -81,7 +80,6 @@ class TestSettingsManager(unittest.TestCase): manager.get_theming_attribute('global', 'body') - @unittest.expectedFailure def test_read_notmuch_config_doesnt_exist(self): with tempfile.NamedTemporaryFile(delete=False) as f: f.write(textwrap.dedent("""\ -- cgit v1.2.3