File: test_idempotent.py

package info (click to toggle)
python-precis-i18n 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,836 kB
  • sloc: python: 1,825; sh: 28; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import unittest

from precis_i18n import get_profile
from precis_i18n.profile import Username
from precis_i18n.unicode import UnicodeData


class IdempotentTestCase(unittest.TestCase):
    def test_broken_profile(self):
        """Test that we can catch a profile that is not idempotent."""

        class _BrokenProfile(Username):
            def additional_mapping_rule(self, value):
                return "%s+" % value

        broken = _BrokenProfile(UnicodeData(), name="Broken")
        with self.assertRaisesRegex(ValueError, "DISALLOWED/not_idempotent"):
            broken.enforce("x")

    def test_all_codepoints(self):
        """Verify all individual code points are idempotent."""
        profiles = [
            get_profile(profile)
            for profile in ("UsernameCaseMapped", "NicknameCaseMapped")
        ]
        for cp in range(0x0110000):
            original = chr(cp)
            for profile in profiles:
                try:
                    profile.enforce(original)
                except UnicodeEncodeError as ex:
                    if "not_idempotent" in str(ex):
                        raise