diff --git a/dkim/tests/__init__.py b/dkim/tests/__init__.py index fad9629..7fb38ab 100644 --- a/dkim/tests/__init__.py +++ b/dkim/tests/__init__.py @@ -22,9 +22,11 @@ import unittest def test_suite(): from dkim.tests import ( test_dkim, + test_util, ) modules = [ test_dkim, + test_util, ] suites = map(lambda x: x.test_suite(), modules) return unittest.TestSuite(suites) diff --git a/dkim/tests/test_dkim.py b/dkim/tests/test_dkim.py index f4ca775..f499104 100644 --- a/dkim/tests/test_dkim.py +++ b/dkim/tests/test_dkim.py @@ -20,11 +20,6 @@ import os.path import unittest import dkim -from dkim.util import ( - DuplicateTag, - InvalidTagSpec, - parse_tag_value, - ) def read_test_data(filename): @@ -73,45 +68,6 @@ class TestSignAndVerify(unittest.TestCase): self.assertFalse(res) -class TestParseTagValue(unittest.TestCase): - """Tag=Value parsing tests.""" - - def test_single(self): - self.assertEqual( - {'foo': 'bar'}, - parse_tag_value('foo=bar')) - - def test_trailing_separator_ignored(self): - self.assertEqual( - {'foo': 'bar'}, - parse_tag_value('foo=bar;')) - - def test_multiple(self): - self.assertEqual( - {'foo': 'bar', 'baz': 'foo'}, - parse_tag_value('foo=bar;baz=foo')) - - def test_value_with_equals(self): - self.assertEqual( - {'foo': 'bar', 'baz': 'foo=bar'}, - parse_tag_value('foo=bar;baz=foo=bar')) - - def test_whitespace_is_stripped(self): - self.assertEqual( - {'foo': 'bar', 'baz': 'f oo=bar'}, - parse_tag_value(' foo \t= bar;\tbaz= f oo=bar ')) - - def test_missing_value_is_an_error(self): - self.assertRaisesRegexp( - InvalidTagSpec, 'baz', - parse_tag_value, 'foo=bar;baz') - - def test_duplicate_tag_is_an_error(self): - self.assertRaisesRegexp( - DuplicateTag, 'foo', - parse_tag_value, 'foo=bar;foo=baz') - - def test_suite(): from unittest import TestLoader return TestLoader().loadTestsFromName(__name__) diff --git a/dkim/tests/test_util.py b/dkim/tests/test_util.py new file mode 100644 index 0000000..1ee6ccc --- /dev/null +++ b/dkim/tests/test_util.py @@ -0,0 +1,69 @@ +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the author be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# 2. Altered source versions must be plainly marked as such, and must not be +# misrepresented as being the original software. +# 3. This notice may not be removed or altered from any source distribution. +# +# Copyright (c) 2011 William Grant + +import unittest + +from dkim.util import ( + DuplicateTag, + InvalidTagSpec, + parse_tag_value, + ) + + +class TestParseTagValue(unittest.TestCase): + """Tag=Value parsing tests.""" + + def test_single(self): + self.assertEqual( + {'foo': 'bar'}, + parse_tag_value('foo=bar')) + + def test_trailing_separator_ignored(self): + self.assertEqual( + {'foo': 'bar'}, + parse_tag_value('foo=bar;')) + + def test_multiple(self): + self.assertEqual( + {'foo': 'bar', 'baz': 'foo'}, + parse_tag_value('foo=bar;baz=foo')) + + def test_value_with_equals(self): + self.assertEqual( + {'foo': 'bar', 'baz': 'foo=bar'}, + parse_tag_value('foo=bar;baz=foo=bar')) + + def test_whitespace_is_stripped(self): + self.assertEqual( + {'foo': 'bar', 'baz': 'f oo=bar'}, + parse_tag_value(' foo \t= bar;\tbaz= f oo=bar ')) + + def test_missing_value_is_an_error(self): + self.assertRaisesRegexp( + InvalidTagSpec, 'baz', + parse_tag_value, 'foo=bar;baz') + + def test_duplicate_tag_is_an_error(self): + self.assertRaisesRegexp( + DuplicateTag, 'foo', + parse_tag_value, 'foo=bar;foo=baz') + + +def test_suite(): + from unittest import TestLoader + return TestLoader().loadTestsFromName(__name__)