| 15 | return defaults |
| 16 | |
| 17 | class PolicyAPITests(unittest.TestCase): |
| 18 | |
| 19 | longMessage = True |
| 20 | |
| 21 | # Base default values. |
| 22 | compat32_defaults = { |
| 23 | 'max_line_length': 78, |
| 24 | 'linesep': '\n', |
| 25 | 'cte_type': '8bit', |
| 26 | 'raise_on_defect': False, |
| 27 | 'mangle_from_': True, |
| 28 | 'message_factory': None, |
| 29 | 'verify_generated_headers': True, |
| 30 | } |
| 31 | # These default values are the ones set on email.policy.default. |
| 32 | # If any of these defaults change, the docs must be updated. |
| 33 | policy_defaults = compat32_defaults.copy() |
| 34 | policy_defaults.update({ |
| 35 | 'utf8': False, |
| 36 | 'raise_on_defect': False, |
| 37 | 'header_factory': email.policy.EmailPolicy.header_factory, |
| 38 | 'refold_source': 'long', |
| 39 | 'content_manager': email.policy.EmailPolicy.content_manager, |
| 40 | 'mangle_from_': False, |
| 41 | 'message_factory': email.message.EmailMessage, |
| 42 | }) |
| 43 | |
| 44 | # For each policy under test, we give here what we expect the defaults to |
| 45 | # be for that policy. The second argument to make defaults is the |
| 46 | # difference between the base defaults and that for the particular policy. |
| 47 | new_policy = email.policy.EmailPolicy() |
| 48 | policies = { |
| 49 | email.policy.compat32: make_defaults(compat32_defaults, {}), |
| 50 | email.policy.default: make_defaults(policy_defaults, {}), |
| 51 | email.policy.SMTP: make_defaults(policy_defaults, |
| 52 | {'linesep': '\r\n'}), |
| 53 | email.policy.SMTPUTF8: make_defaults(policy_defaults, |
| 54 | {'linesep': '\r\n', |
| 55 | 'utf8': True}), |
| 56 | email.policy.HTTP: make_defaults(policy_defaults, |
| 57 | {'linesep': '\r\n', |
| 58 | 'max_line_length': None}), |
| 59 | email.policy.strict: make_defaults(policy_defaults, |
| 60 | {'raise_on_defect': True}), |
| 61 | new_policy: make_defaults(policy_defaults, {}), |
| 62 | } |
| 63 | # Creating a new policy creates a new header factory. There is a test |
| 64 | # later that proves this. |
| 65 | policies[new_policy]['header_factory'] = new_policy.header_factory |
| 66 | |
| 67 | def test_defaults(self): |
| 68 | for policy, expected in self.policies.items(): |
| 69 | for attr, value in expected.items(): |
| 70 | with self.subTest(policy=policy, attr=attr): |
| 71 | self.assertEqual(getattr(policy, attr), value, |
| 72 | ("change {} docs/docstrings if defaults have " |
| 73 | "changed").format(policy)) |
| 74 |
nothing calls this directly
no test coverage detected
searching dependent graphs…