diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-01-18 09:57:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 09:57:35 +0000 |
commit | 70cae61d4fa80e2090169f8cb83e69081a04f890 (patch) | |
tree | 781bc1f7f12676fd1dc155512357e8a325e836a7 /tests | |
parent | 370988cb63afbc81b661ffcd733b9951b2f6b677 (diff) | |
parent | aba3e5c26b409008ed3dcf585770b8e41e34a8bf (diff) |
Merge pull request #975 from lucc/tests/doctests
Porting old doctests to unittest
Diffstat (limited to 'tests')
-rw-r--r-- | tests/commands/__init__.py | 0 | ||||
-rw-r--r-- | tests/commands/init_test.py | 28 | ||||
-rw-r--r-- | tests/db/envelop_test.py | 14 | ||||
-rw-r--r-- | tests/helper_test.py | 78 | ||||
-rw-r--r-- | tests/settings/__init__.py | 0 | ||||
-rw-r--r-- | tests/settings/checks_test.py | 16 |
6 files changed, 136 insertions, 0 deletions
diff --git a/tests/commands/__init__.py b/tests/commands/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/commands/__init__.py diff --git a/tests/commands/init_test.py b/tests/commands/init_test.py new file mode 100644 index 00000000..189ffc8e --- /dev/null +++ b/tests/commands/init_test.py @@ -0,0 +1,28 @@ +# encoding=utf-8 + +"""Test suite for alot.commands.__init__ module.""" + +import argparse +import unittest + +from alot import commands +from alot.commands import thread + + +class TestLookupCommand(unittest.TestCase): + + def test_look_up_save_attachment_command_in_thread_mode(self): + cmd, parser, kwargs = commands.lookup_command('save', 'thread') + # TODO do some more tests with these return values + self.assertEqual(cmd, thread.SaveAttachmentCommand) + self.assertIsInstance(parser, argparse.ArgumentParser) + self.assertDictEqual(kwargs, {}) + + +class TestCommandFactory(unittest.TestCase): + + def test_create_save_attachment_command_with_arguments(self): + cmd = commands.commandfactory('save --all /foo', mode='thread') + self.assertIsInstance(cmd, thread.SaveAttachmentCommand) + self.assertTrue(cmd.all) + self.assertEqual(cmd.path, u'/foo') diff --git a/tests/db/envelop_test.py b/tests/db/envelop_test.py new file mode 100644 index 00000000..1895d827 --- /dev/null +++ b/tests/db/envelop_test.py @@ -0,0 +1,14 @@ +# encoding=utf-8 + +import unittest + +from alot.db import envelope + + +class TestEnvelopeMethods(unittest.TestCase): + + def test_setitem_stores_text_unchanged(self): + "Just ensure that the value is set and unchanged" + e = envelope.Envelope() + e['Subject'] = u'sm\xf8rebr\xf8d' + self.assertEqual(e['Subject'], u'sm\xf8rebr\xf8d') diff --git a/tests/helper_test.py b/tests/helper_test.py new file mode 100644 index 00000000..e333c2f9 --- /dev/null +++ b/tests/helper_test.py @@ -0,0 +1,78 @@ +# encoding=utf-8 + +"""Test suite for alot.helper module.""" + +import unittest + +from alot import helper + + +class TestHelperShortenAuthorString(unittest.TestCase): + + authors = u'King Kong, Mucho Muchacho, Jaime Huerta, Flash Gordon' + + def test_high_maxlength_keeps_string_intact(self): + short = helper.shorten_author_string(self.authors, 60) + self.assertEqual(short, self.authors) + + def test_shows_only_first_names_if_they_fit(self): + short = helper.shorten_author_string(self.authors, 40) + self.assertEqual(short, u"King, Mucho, Jaime, Flash") + + def test_adds_ellipses_to_long_first_names(self): + short = helper.shorten_author_string(self.authors, 20) + self.assertEqual(short, u"King, …, Jai…, Flash") + + def test_replace_all_but_first_name_with_ellipses(self): + short = helper.shorten_author_string(self.authors, 10) + self.assertEqual(short, u"King, …") + + def test_shorten_first_name_with_ellipses(self): + short = helper.shorten_author_string(self.authors, 2) + self.assertEqual(short, u"K…") + + def test_only_display_initial_letter_for_maxlength_1(self): + short = helper.shorten_author_string(self.authors, 1) + self.assertEqual(short, u"K") + + +class TestShellQuote(unittest.TestCase): + + def test_all_strings_are_sourrounded_by_single_quotes(self): + quoted = helper.shell_quote("hello") + self.assertEqual(quoted, "'hello'") + + def test_single_quotes_are_escaped_using_double_quotes(self): + quoted = helper.shell_quote("hello'there") + self.assertEqual(quoted, """'hello'"'"'there'""") + + +class TestHumanizeSize(unittest.TestCase): + + def test_small_numbers_are_converted_to_strings_directly(self): + readable = helper.humanize_size(1) + self.assertEqual(readable, "1") + readable = helper.humanize_size(123) + self.assertEqual(readable, "123") + + def test_numbers_above_1024_are_converted_to_kilobyte(self): + readable = helper.humanize_size(1023) + self.assertEqual(readable, "1023") + readable = helper.humanize_size(1024) + self.assertEqual(readable, "1K") + readable = helper.humanize_size(1234) + self.assertEqual(readable, "1K") + + def test_numbers_above_1048576_are_converted_to_megabyte(self): + readable = helper.humanize_size(1024*1024-1) + self.assertEqual(readable, "1023K") + readable = helper.humanize_size(1024*1024) + self.assertEqual(readable, "1.0M") + + def test_megabyte_numbers_are_converted_with_precision_1(self): + readable = helper.humanize_size(1234*1024) + self.assertEqual(readable, "1.2M") + + def test_numbers_are_not_converted_to_gigabyte(self): + readable = helper.humanize_size(1234*1024*1024) + self.assertEqual(readable, "1234.0M") diff --git a/tests/settings/__init__.py b/tests/settings/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/settings/__init__.py diff --git a/tests/settings/checks_test.py b/tests/settings/checks_test.py new file mode 100644 index 00000000..917e2438 --- /dev/null +++ b/tests/settings/checks_test.py @@ -0,0 +1,16 @@ +# encoding=utf-8 + +import unittest + +from alot.settings import checks + + +class TestForceList(unittest.TestCase): + + def test_strings_are_converted_to_single_item_lists(self): + forced = checks.force_list('hello') + self.assertEqual(forced, ['hello']) + + def test_empty_strings_are_converted_to_empty_lists(self): + forced = checks.force_list('') + self.assertEqual(forced, []) |