forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_chars_tests.py
executable file
·48 lines (37 loc) · 1.36 KB
/
tools_chars_tests.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""Test tools.chars package."""
#
# (C) Pywikibot team, 2015-2023
#
# Distributed under the terms of the MIT license.
from __future__ import annotations
import unicodedata
import unittest
from contextlib import suppress
from pywikibot.tools import chars
from tests.aspects import TestCase
class CharsTestCase(TestCase):
"""General test case testing the module."""
net = False
def test_replace(self):
"""Test replace_invisible."""
self.assertEqual(
chars.replace_invisible('Hello world!'), 'Hello world!')
self.assertEqual(
chars.replace_invisible('\u200eRTL\u200f'), '<200e>RTL<200f>')
def test_contains(self):
"""Test contains_invisible."""
self.assertFalse(chars.contains_invisible('Hello world!'))
self.assertTrue(chars.contains_invisible('\u200eRTL\u200f'))
def test_category_cf(self):
"""Test that all characters in _category_cf are actually in Cf."""
invalid = {}
# Cn are undefined characters (and were defined later in Unicode)
for char in chars._category_cf:
cat = unicodedata.category(char)
if cat not in ('Cf', 'Cn'):
invalid[char] = cat # pragma: no cover
self.assertIsEmpty(invalid.items())
if __name__ == '__main__':
with suppress(SystemExit):
unittest.main()