summaryrefslogtreecommitdiff
path: root/tests/settings/test_utils.py
diff options
context:
space:
mode:
authorLucas Hoffmann <lucc@posteo.de>2018-12-21 00:33:19 +0100
committerLucas Hoffmann <lucc@posteo.de>2019-01-29 00:31:03 +0100
commit7f0a1b8cdd492917f84f90cade28cefa0a37c3e0 (patch)
tree84fc17675a16fba219d56c0c17b5c0183086e64a /tests/settings/test_utils.py
parentfd1348329b8697d9bb014e7d61560f3421d29e46 (diff)
Rename test files
The two main reasons are - to run `python3 -m unittest discover` without specifying a custom `--pattern *_test.py` - to include the test files automatically when generating the MANIFEST file.
Diffstat (limited to 'tests/settings/test_utils.py')
-rw-r--r--tests/settings/test_utils.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/settings/test_utils.py b/tests/settings/test_utils.py
new file mode 100644
index 00000000..869054ce
--- /dev/null
+++ b/tests/settings/test_utils.py
@@ -0,0 +1,74 @@
+# 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."""
+
+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)