summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email/test_headerregistry.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-05-31 01:53:40 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-05-31 01:53:40 (GMT)
commit56517e5cb91c896024934a520d365d6e275eb1ad (patch)
tree21eb85c9393663238a595cf25d30744150745d02 /Lib/test/test_email/test_headerregistry.py
parent01d7058d6acaf30441bf211580ba9c8d03b3c3c5 (diff)
downloadcpython-56517e5cb91c896024934a520d365d6e275eb1ad.zip
cpython-56517e5cb91c896024934a520d365d6e275eb1ad.tar.gz
cpython-56517e5cb91c896024934a520d365d6e275eb1ad.tar.bz2
Make parameterized tests in email less hackish.
Or perhaps more hackish, depending on your perspective. But at least this way it is now possible to run the individual tests using the unittest CLI.
Diffstat (limited to 'Lib/test/test_email/test_headerregistry.py')
-rw-r--r--Lib/test/test_email/test_headerregistry.py26
1 files changed, 8 insertions, 18 deletions
diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py
index e6fe29b..4a57ff1 100644
--- a/Lib/test/test_email/test_headerregistry.py
+++ b/Lib/test/test_email/test_headerregistry.py
@@ -4,7 +4,7 @@ import unittest
from email import errors
from email import policy
from email.message import Message
-from test.test_email import TestEmailBase
+from test.test_email import TestEmailBase, Parameterized
from email import headerregistry
from email.headerregistry import Address, Group
@@ -175,9 +175,9 @@ class TestDateHeader(TestHeaderBase):
self.assertEqual(m['Date'].datetime, self.dt)
-class TestAddressHeader(TestHeaderBase):
+class TestAddressHeader(TestHeaderBase, metaclass=Parameterized):
- examples = {
+ example_params = {
'empty':
('<>',
@@ -305,8 +305,8 @@ class TestAddressHeader(TestHeaderBase):
# trailing comments, which aren't currently handled. comments in
# general are not handled yet.
- def _test_single_addr(self, source, defects, decoded, display_name,
- addr_spec, username, domain, comment):
+ def example_as_address(self, source, defects, decoded, display_name,
+ addr_spec, username, domain, comment):
h = self.make_header('sender', source)
self.assertEqual(h, decoded)
self.assertDefectsEqual(h.defects, defects)
@@ -322,13 +322,8 @@ class TestAddressHeader(TestHeaderBase):
# XXX: we have no comment support yet.
#self.assertEqual(a.comment, comment)
- for name in examples:
- locals()['test_'+name] = (
- lambda self, name=name:
- self._test_single_addr(*self.examples[name]))
-
- def _test_group_single_addr(self, source, defects, decoded, display_name,
- addr_spec, username, domain, comment):
+ def example_as_group(self, source, defects, decoded, display_name,
+ addr_spec, username, domain, comment):
source = 'foo: {};'.format(source)
gdecoded = 'foo: {};'.format(decoded) if decoded else 'foo:;'
h = self.make_header('to', source)
@@ -344,11 +339,6 @@ class TestAddressHeader(TestHeaderBase):
self.assertEqual(a.username, username)
self.assertEqual(a.domain, domain)
- for name in examples:
- locals()['test_group_'+name] = (
- lambda self, name=name:
- self._test_group_single_addr(*self.examples[name]))
-
def test_simple_address_list(self):
value = ('Fred <dinsdale@python.org>, foo@example.com, '
'"Harry W. Hastings" <hasty@example.com>')
@@ -366,7 +356,7 @@ class TestAddressHeader(TestHeaderBase):
'Harry W. Hastings')
def test_complex_address_list(self):
- examples = list(self.examples.values())
+ examples = list(self.example_params.values())
source = ('dummy list:;, another: (empty);,' +
', '.join([x[0] for x in examples[:4]]) + ', ' +
r'"A \"list\"": ' +