diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-05-31 01:53:40 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-05-31 01:53:40 (GMT) |
commit | 56517e5cb91c896024934a520d365d6e275eb1ad (patch) | |
tree | 21eb85c9393663238a595cf25d30744150745d02 /Lib/test/test_email/test_generator.py | |
parent | 01d7058d6acaf30441bf211580ba9c8d03b3c3c5 (diff) | |
download | cpython-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_generator.py')
-rw-r--r-- | Lib/test/test_email/test_generator.py | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/Lib/test/test_email/test_generator.py b/Lib/test/test_email/test_generator.py index c1af024..7e1529b 100644 --- a/Lib/test/test_email/test_generator.py +++ b/Lib/test/test_email/test_generator.py @@ -4,10 +4,10 @@ import unittest from email import message_from_string, message_from_bytes from email.generator import Generator, BytesGenerator from email import policy -from test.test_email import TestEmailBase +from test.test_email import TestEmailBase, Parameterized -class TestGeneratorBase: +class TestGeneratorBase(metaclass=Parameterized): policy = policy.default @@ -80,31 +80,23 @@ class TestGeneratorBase: "\n" "None\n") - def _test_maxheaderlen_parameter(self, n): + length_params = [n for n in refold_long_expected] + + def length_as_maxheaderlen_parameter(self, n): msg = self.msgmaker(self.typ(self.refold_long_expected[0])) s = self.ioclass() g = self.genclass(s, maxheaderlen=n, policy=self.policy) g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[n])) - for n in refold_long_expected: - locals()['test_maxheaderlen_parameter_' + str(n)] = ( - lambda self, n=n: - self._test_maxheaderlen_parameter(n)) - - def _test_max_line_length_policy(self, n): + def length_as_max_line_length_policy(self, n): msg = self.msgmaker(self.typ(self.refold_long_expected[0])) s = self.ioclass() g = self.genclass(s, policy=self.policy.clone(max_line_length=n)) g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[n])) - for n in refold_long_expected: - locals()['test_max_line_length_policy' + str(n)] = ( - lambda self, n=n: - self._test_max_line_length_policy(n)) - - def _test_maxheaderlen_parm_overrides_policy(self, n): + def length_as_maxheaderlen_parm_overrides_policy(self, n): msg = self.msgmaker(self.typ(self.refold_long_expected[0])) s = self.ioclass() g = self.genclass(s, maxheaderlen=n, @@ -112,12 +104,7 @@ class TestGeneratorBase: g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[n])) - for n in refold_long_expected: - locals()['test_maxheaderlen_parm_overrides_policy' + str(n)] = ( - lambda self, n=n: - self._test_maxheaderlen_parm_overrides_policy(n)) - - def _test_refold_none_does_not_fold(self, n): + def length_as_max_line_length_with_refold_none_does_not_fold(self, n): msg = self.msgmaker(self.typ(self.refold_long_expected[0])) s = self.ioclass() g = self.genclass(s, policy=self.policy.clone(refold_source='none', @@ -125,12 +112,7 @@ class TestGeneratorBase: g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[0])) - for n in refold_long_expected: - locals()['test_refold_none_does_not_fold' + str(n)] = ( - lambda self, n=n: - self._test_refold_none_does_not_fold(n)) - - def _test_refold_all(self, n): + def length_as_max_line_length_with_refold_all_folds(self, n): msg = self.msgmaker(self.typ(self.refold_long_expected[0])) s = self.ioclass() g = self.genclass(s, policy=self.policy.clone(refold_source='all', @@ -138,11 +120,6 @@ class TestGeneratorBase: g.flatten(msg) self.assertEqual(s.getvalue(), self.typ(self.refold_all_expected[n])) - for n in refold_long_expected: - locals()['test_refold_all' + str(n)] = ( - lambda self, n=n: - self._test_refold_all(n)) - def test_crlf_control_via_policy(self): source = "Subject: test\r\n\r\ntest body\r\n" expected = source |