Skip to content

Commit 2126038

Browse files
committed
Fix tests with newer emoji package
1 parent 61549c6 commit 2126038

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tests/test_emoji.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io
55
from itertools import starmap
66
from textwrap import dedent
7-
from typing import Callable, Dict
7+
from typing import Any, Callable, Dict
88

99
# 3rd party
1010
import pytest
@@ -13,14 +13,23 @@
1313
# 3rd party
1414
from emoji.unicode_codes.en import EMOJI_UNICODE_ENGLISH # type: ignore[import]
1515
except ImportError:
16-
try:
17-
# 3rd party
18-
from emoji.unicode_codes import get_emoji_unicode_dict
19-
EMOJI_UNICODE_ENGLISH = get_emoji_unicode_dict("en")
20-
except ImportError:
21-
# 3rd party
22-
from emoji.unicode_codes import get_unicode_dict # type: ignore[attr-defined]
23-
EMOJI_UNICODE_ENGLISH = get_unicode_dict("en")
16+
# 3rd party
17+
from emoji.unicode_codes import EMOJI_DATA, LANGUAGES, STATUS
18+
19+
_EMOJI_UNICODE: Dict[str, Any] = {lang: None for lang in LANGUAGES}
20+
21+
def get_emoji_unicode_dict(lang: str) -> Dict:
22+
if _EMOJI_UNICODE[lang] is None:
23+
_EMOJI_UNICODE[lang] = {
24+
data[lang]: emj
25+
for emj,
26+
data in EMOJI_DATA.items()
27+
if lang in data and data["status"] <= STATUS["fully_qualified"]
28+
}
29+
30+
return _EMOJI_UNICODE[lang]
31+
32+
EMOJI_UNICODE_ENGLISH = get_emoji_unicode_dict("en")
2433

2534
# this package
2635
from emoji_strings import StreamReader, decode

0 commit comments

Comments
 (0)