diff options
-rw-r--r-- | alot/commands/__init__.py | 12 | ||||
-rw-r--r-- | alot/db/envelope.py | 5 | ||||
-rw-r--r-- | alot/helper.py | 32 | ||||
-rw-r--r-- | alot/settings/checks.py | 5 | ||||
-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 |
10 files changed, 138 insertions, 52 deletions
diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py index 05ce3424..47315fc3 100644 --- a/alot/commands/__init__.py +++ b/alot/commands/__init__.py @@ -53,10 +53,6 @@ def lookup_command(cmdname, mode): :type mode: str :rtype: (:class:`Command`, :class:`~argparse.ArgumentParser`, dict(str->dict)) - - >>> (cmd, parser, kwargs) = lookup_command('save', 'thread') - >>> cmd - <class 'alot.commands.thread.SaveAttachmentCommand'> """ if cmdname in COMMANDS[mode]: return COMMANDS[mode][cmdname] @@ -155,14 +151,6 @@ def commandfactory(cmdline, mode='global'): :type cmdline: str :param mode: mode identifier :type mode: str - - >>> cmd = alot.commands.commandfactory('save --all /foo', mode='thread') - >>> cmd - <alot.commands.thread.SaveAttachmentCommand object at 0x272cf10 - >>> cmd.all - True - >>> cmd.path - u'/foo' """ # split commandname and parameters if not cmdline: diff --git a/alot/db/envelope.py b/alot/db/envelope.py index f5515740..a2463e9c 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -87,9 +87,8 @@ class Envelope(object): return "Envelope (%s)\n%s" % (self.headers, self.body) def __setitem__(self, name, val): - """setter for header values. this allows adding header like so: - - >>> envelope['Subject'] = u'sm\xf8rebr\xf8d' + """setter for header values. This allows adding header like so: + envelope['Subject'] = u'sm\xf8rebr\xf8d' """ if name not in self.headers: self.headers[name] = [] diff --git a/alot/helper.py b/alot/helper.py index a354d7a0..b33c0125 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -140,20 +140,6 @@ def shorten_author_string(authors_string, maxlength): - If it is finally necessary to hide any author, an ellipsis between first and next authors is added. - - >>> authors = u'King Kong, Mucho Muchacho, Jaime Huerta, Flash Gordon' - >>> print shorten_author_string(authors, 60) - King Kong, Mucho Muchacho, Jaime Huerta, Flash Gordon - >>> print shorten_author_string(authors, 40) - King, Mucho, Jaime, Flash - >>> print shorten_author_string(authors, 20) - King, …, Jai…, Flash - >>> print shorten_author_string(authors, 10) - King, … - >>> print shorten_author_string(authors, 2) - K… - >>> print shorten_author_string(authors, 1) - K """ # I will create a list of authors by parsing author_string. I use @@ -484,12 +470,6 @@ def mimewrap(path, filename=None, ctype=None): def shell_quote(text): - r''' - >>> print(shell_quote("hello")) - 'hello' - >>> print(shell_quote("hello'there")) - 'hello'"'"'there' - ''' return "'%s'" % text.replace("'", """'"'"'""") @@ -505,18 +485,6 @@ def tag_cmp(a, b): def humanize_size(size): - r''' - >>> humanize_size(1) - '1' - >>> humanize_size(123) - '123' - >>> humanize_size(1234) - '1K' - >>> humanize_size(1234 * 1024) - '1.2M' - >>> humanize_size(1234 * 1024 * 1024) - '1234.0M' - ''' for factor, format_string in ((1, '%i'), (1024, '%iK'), (1024 * 1024, '%.1fM')): diff --git a/alot/settings/checks.py b/alot/settings/checks.py index bef91a77..6f909524 100644 --- a/alot/settings/checks.py +++ b/alot/settings/checks.py @@ -121,11 +121,6 @@ def force_list(value, min=None, max=None): The difference to :func:`validate.force_list` is that this test will return an empty list instead of `['']` if the config value matches `r'\s*,?\s*'`. - - >>> vtor.check('force_list', 'hello') - ['hello'] - >>> vtor.check('force_list', '') - [] """ if not isinstance(value, (list, tuple)): value = [value] 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, []) |