File: test_dict.py

package info (click to toggle)
python-emoji 2.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,664 kB
  • sloc: python: 3,120; javascript: 262; makefile: 14
file content (62 lines) | stat: -rw-r--r-- 1,957 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Unittests for the big dict of dicts containing all emoji"""

from typing import Set, Dict
import re
import emoji

from testutils import load_all_languages as load_all_languages


def test_all_languages_list(load_all_languages):  # type:ignore
    """Compare all language keys in EMOJI_DATA with the emoji.LANGUAGES list"""

    langs: Set[str] = set()
    for item in emoji.EMOJI_DATA.values():
        langs.update(item.keys())
    all_languages = {lang for lang in langs if len(lang) == 2 and lang.lower() == lang}

    assert set(emoji.LANGUAGES) == all_languages


def test_emoji_versions():
    """Check that every emoji has a valid version"""
    for item in emoji.EMOJI_DATA.values():
        assert 'E' in item
        v = item['E']
        assert isinstance(v, (int, float))
        assert v >= 0.6


def check_duplicate_names(lang: str):
    """Check that there are no duplicate names in the fully_qualified except for different variants"""
    seen: Dict[str, int] = {}
    for item in emoji.EMOJI_DATA.values():
        if item['status'] > emoji.STATUS['fully_qualified']:
            continue

        if lang not in item:
            continue

        name = item[lang]
        if name in seen and 'variant' in item:
            seen[name] += 1
        else:
            assert name not in seen
            seen[name] = 0


def test_duplicate_names(load_all_languages):  # type:ignore
    """Check that there are no duplicate names in the fully_qualified except for different variants"""
    for lang in emoji.LANGUAGES:
        check_duplicate_names(lang)


def test_name_valid(load_all_languages):  # type:ignore
    """Check that every name starts with colons and does not contain other colons or whitespace"""

    pattern = re.compile(r':[^:\s]+:')
    for item in emoji.EMOJI_DATA.values():
        for lang in emoji.LANGUAGES:
            if lang in item:
                name = item[lang]
                assert pattern.match(name)