From edd6c76123c033b9ddc53d674ae396f5ac9fe305 Mon Sep 17 00:00:00 2001 From: Julian Mehne Date: Sun, 7 Jan 2018 22:28:30 +0100 Subject: Log unknown settings in configuration and theme files. --- tests/settings/manager_test.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/settings') diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py index 42bc584a..eb2f37fd 100644 --- a/tests/settings/manager_test.py +++ b/tests/settings/manager_test.py @@ -11,6 +11,8 @@ import tempfile import textwrap import unittest +import mock + from alot.settings.manager import SettingsManager from alot.settings.errors import ConfigError, NoMatchingAccount @@ -80,6 +82,40 @@ class TestSettingsManager(unittest.TestCase): manager.get_theming_attribute('global', 'body') + def test_unknown_settings_in_config_are_logged(self): + # todo: For py3, don't mock the logger, use assertLogs + unknown_settings = ['templates_dir', 'unknown_section', 'unknown_1', + 'unknown_2'] + with tempfile.NamedTemporaryFile(delete=False) as f: + f.write(textwrap.dedent("""\ + {x[0]} = /templates/dir + [{x[1]}] + # Values in unknown sections are not reported. + barfoo = barfoo + [tags] + [[foobar]] + {x[2]} = baz + translated = translation + {x[3]} = bar + """.format(x=unknown_settings))) + self.addCleanup(os.unlink, f.name) + + with mock.patch('alot.settings.utils.logging') as mock_logger: + SettingsManager(alot_rc=f.name) + success = False + for call_args in mock_logger.info.call_args_list: + msg = call_args[0][0] + if all([s in msg for s in unknown_settings]): + success = True + break + else: + print('Could not find all unknown settings in logging.info.\n' + 'Unknown settings:') + print(unknown_settings) + print('Calls to mocked logging.info:') + print(mock_logger.info.call_args_list) + self.assertTrue(success) + def test_read_notmuch_config_doesnt_exist(self): with tempfile.NamedTemporaryFile(delete=False) as f: f.write(textwrap.dedent("""\ -- cgit v1.2.3