diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2017-07-17 15:06:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-17 15:06:51 -0700 |
commit | 9da1345a977ba7061a357d072ead632cfe1625f4 (patch) | |
tree | 7e78d6677311364b68297dd1ea60781b5c9d1a32 | |
parent | f5515d742fe2938e5fb4453914c4cabb6ecd9197 (diff) | |
parent | 5a11fe60dce7a71a5b98e45f8363c3651a70a2e8 (diff) |
Merge pull request #1075 from lucc/test/misc
Some misc tests
-rw-r--r-- | alot/addressbook/__init__.py | 2 | ||||
-rw-r--r-- | alot/addressbook/external.py | 2 | ||||
-rw-r--r-- | tests/addressbook/external_test.py | 8 | ||||
-rw-r--r-- | tests/settings/theme_test.py | 86 | ||||
-rw-r--r-- | tests/settings/utils_test.py | 76 |
5 files changed, 172 insertions, 2 deletions
diff --git a/alot/addressbook/__init__.py b/alot/addressbook/__init__.py index f30c7274..17800b33 100644 --- a/alot/addressbook/__init__.py +++ b/alot/addressbook/__init__.py @@ -27,7 +27,7 @@ class AddressBook(object): self.reflags = re.IGNORECASE if ignorecase else 0 @abc.abstractmethod - def get_contacts(self): + def get_contacts(self): # pragma no cover """list all contacts tuples in this abook as (name, email) tuples""" return [] diff --git a/alot/addressbook/external.py b/alot/addressbook/external.py index 9de86f36..53f1e464 100644 --- a/alot/addressbook/external.py +++ b/alot/addressbook/external.py @@ -44,7 +44,7 @@ class ExternalAddressbook(AddressBook): def get_contacts(self): return self._call_and_parse(self.commandline) - def lookup(self, prefix): + def lookup(self, prefix): # pragma: no cover if self.external_filtering: return self._call_and_parse(self.commandline + " " + prefix) else: diff --git a/tests/addressbook/external_test.py b/tests/addressbook/external_test.py index 2211769e..99aacfd3 100644 --- a/tests/addressbook/external_test.py +++ b/tests/addressbook/external_test.py @@ -30,6 +30,14 @@ class TestExternalAddressbookGetContacts(unittest.TestCase): expected = u'abook command "foobar" returned with return code 42' self.assertEqual(contextmgr.exception.args[0], expected) + def test_stderr_of_failing_command_is_part_of_exception_message(self): + stderr = 'some text printed on stderr of external command' + abook = external.ExternalAddressbook('foobar', '') + with self._patch_call_cmd(('', stderr, 42)): + with self.assertRaises(external.AddressbookError) as contextmgr: + abook.get_contacts() + self.assertIn(stderr, contextmgr.exception.args[0]) + def test_returns_empty_list_when_command_returns_no_output(self): abook = external.ExternalAddressbook('foobar', self.regex) with self._patch_call_cmd(('', '', 0)) as call_cmd: diff --git a/tests/settings/theme_test.py b/tests/settings/theme_test.py new file mode 100644 index 00000000..abc541e3 --- /dev/null +++ b/tests/settings/theme_test.py @@ -0,0 +1,86 @@ +# Copyright (C) 2017 Lucas Hoffmann +# This file is released under the GNU GPL, version 3 or a later revision. +# For further details see the COPYING file + +from __future__ import absolute_import + +import unittest + +from alot.settings import theme + + +DUMMY_THEME = """\ +[bufferlist] + line = '', '', '', '', '', '' + line_even = '', '', '', '', '', '' + line_focus = '', '', '', '', '', '' + line_odd = '', '', '', '', '', '' +[envelope] + body = '', '', '', '', '', '' + header = '', '', '', '', '', '' + header_key = '', '', '', '', '', '' + header_value = '', '', '', '', '', '' +[global] + body = '', '', '', '', '', '' + footer = '', '', '', '', '', '' + notify_error = '', '', '', '', '', '' + notify_normal = '', '', '', '', '', '' + prompt = '', '', '', '', '', '' + tag = '', '', '', '', '', '' + tag_focus = '', '', '', '', '', '' +[help] + section = '', '', '', '', '', '' + text = '', '', '', '', '', '' + title = '', '', '', '', '', '' +[taglist] + line_even = '', '', '', '', '', '' + line_focus = '', '', '', '', '', '' + line_odd = '', '', '', '', '', '' +[search] + focus = '', '', '', '', '', '' + normal = '', '', '', '', '', '' + [[threadline]] + focus = '', '', '', '', '', '' + normal = '', '', '', '', '', '' +[thread] + arrow_bars = '', '', '', '', '', '' + arrow_heads = '', '', '', '', '', '' + attachment = '', '', '', '', '', '' + attachment_focus = '', '', '', '', '', '' + body = '', '', '', '', '', '' + header = '', '', '', '', '', '' + header_key = '', '', '', '', '', '' + header_value = '', '', '', '', '', '' + [[summary]] + even = '', '', '', '', '', '' + focus = '', '', '', '', '', '' + odd = '', '', '', '', '', '' +""" + + +class TestThemeGetAttribute(unittest.TestCase): + + @classmethod + def setUpClass(cls): + # We use a list of strings instead of a file path to pass in the config + # file. This is possible because the argument is handed to + # configobj.ConfigObj directly and that accepts eigher: + # http://configobj.rtfd.io/en/latest/configobj.html#reading-a-config-file + cls.theme = theme.Theme(DUMMY_THEME.splitlines()) + + def test_invalid_mode_raises_key_error(self): + with self.assertRaises(KeyError) as cm: + self.theme.get_attribute(0, 'mode does not exist', + 'name does not exist') + self.assertTupleEqual(cm.exception.args, ('mode does not exist',)) + + def test_invalid_name_raises_key_error(self): + with self.assertRaises(KeyError) as cm: + self.theme.get_attribute(0, 'global', 'name does not exist') + self.assertTupleEqual(cm.exception.args, ('name does not exist',)) + + # TODO tests for invalid part arguments. + + def test_invalid_colorindex_raises_value_error(self): + with self.assertRaises(ValueError): + self.theme.get_attribute(0, 'global', 'body') diff --git a/tests/settings/utils_test.py b/tests/settings/utils_test.py new file mode 100644 index 00000000..d88ed55f --- /dev/null +++ b/tests/settings/utils_test.py @@ -0,0 +1,76 @@ +# Copyright (C) 2017 Lucas Hoffmann +# This file is released under the GNU GPL, version 3 or a later revision. +# For further details see the COPYING file + +"""Tests for the alot.setting.utils module.""" + +from __future__ import absolute_import + +import unittest + +import mock + +from alot.settings import utils + + +class TestResolveAtt(unittest.TestCase): + + __patchers = [] + fallback = mock.Mock() + fallback.foreground = 'some fallback foreground value' + fallback.background = 'some fallback background value' + + @classmethod + def setUpClass(cls): + cls.__patchers.append(mock.patch( + 'alot.settings.utils.AttrSpec', + mock.Mock(side_effect=lambda *args: args))) + for p in cls.__patchers: + p.start() + + @classmethod + def tearDownClass(cls): + for p in cls.__patchers: + p.stop() + + @staticmethod + def _mock(foreground, background): + """Create a mock object that is needed very often.""" + m = mock.Mock() + m.foreground = foreground + m.background = background + return m + + def test_passing_none_returns_fallback(self): + actual = utils.resolve_att(None, self.fallback) + self.assertEqual(actual, self.fallback) + + def test_empty_string_in_background_picks_up_background_from_fallback(self): + attr = self._mock('valid foreground', '') + expected = (attr.foreground, self.fallback.background) + actual = utils.resolve_att(attr, self.fallback) + self.assertTupleEqual(actual, expected) + + def test_default_in_background_picks_up_background_from_fallback(self): + attr = self._mock('valid foreground', 'default') + expected = attr.foreground, self.fallback.background + actual = utils.resolve_att(attr, self.fallback) + self.assertTupleEqual(actual, expected) + + def test_empty_string_in_foreground_picks_up_foreground_from_fallback(self): + attr = self._mock('', 'valid background') + expected = self.fallback.foreground, attr.background + actual = utils.resolve_att(attr, self.fallback) + self.assertTupleEqual(actual, expected) + + def test_default_in_foreground_picks_up_foreground_from_fallback(self): + attr = self._mock('default', 'valid background') + expected = self.fallback.foreground, attr.background + actual = utils.resolve_att(attr, self.fallback) + self.assertTupleEqual(actual, expected) + + def test_other_values_are_used(self): + attr = self._mock('valid foreground', 'valid background') + expected = attr.foreground, attr.background + actual = utils.resolve_att(attr, self.fallback) + self.assertTupleEqual(actual, expected) |