Debian Codegraph @

tests/test_apprise_emojis.py

raw symbols SCIP
1 # BSD 2-Clause License
2 #
3 # Apprise - Push Notification Library.
4 # Copyright (c) 2026, Chris Caron <[email protected]>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation
14 # and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27
28 # Disable logging for a cleaner testing output
29 import logging
30 import sys
31
32 from apprise import emojis
33
34 logging.disable(logging.CRITICAL)
35
36 # Ensure we don't create .pyc files for these tests
37 sys.dont_write_bytecode = True
38
39
40 def test_emojis():
41 "emojis: apply_emojis() testing"
42
43 assert emojis.apply_emojis("") == ""
44 assert emojis.apply_emojis("no change") == "no change"
45 assert emojis.apply_emojis(":smile:") == "😄"
46 assert emojis.apply_emojis(":smile::smile:") == "😄😄"
47
48 # Missing Delimiters
49 assert emojis.apply_emojis(":smile") == ":smile"
50 assert emojis.apply_emojis("smile:") == "smile:"
51
52 # Bad data
53 assert emojis.apply_emojis(None) == ""
54 assert emojis.apply_emojis(object) == ""
55 assert emojis.apply_emojis(True) == ""
56 assert emojis.apply_emojis(4.0) == ""
57
58
59 def test_emojis_alternation_aliases():
60 """emojis: apply_emojis() handles regex alternation keys correctly."""
61
62 # thumbsup / +1
63 assert emojis.apply_emojis(":thumbsup:") == "👍"
64 assert emojis.apply_emojis(":+1:") == "👍"
65
66 # thumbsdown / -1
67 assert emojis.apply_emojis(":thumbsdown:") == "👎"
68 assert emojis.apply_emojis(":-1:") == "👎"
69
70 # laughing / satisfied
71 assert emojis.apply_emojis(":laughing:") == "😆"
72 assert emojis.apply_emojis(":satisfied:") == "😆"
73
74 # poop aliases
75 assert emojis.apply_emojis(":poop:") == "💩"
76 assert emojis.apply_emojis(":hankey:") == "💩"
77 assert emojis.apply_emojis(":shit:") == "💩"
78
79 # boom / collision
80 assert emojis.apply_emojis(":boom:") == "💥"
81 assert emojis.apply_emojis(":collision:") == "💥"
82
83 # exclamation aliases
84 assert emojis.apply_emojis(":exclamation:") == "❗"
85 assert emojis.apply_emojis(":heavy_exclamation_mark:") == "❗"
86
87 # knife / hocho
88 assert emojis.apply_emojis(":knife:") == "🔪"
89 assert emojis.apply_emojis(":hocho:") == "🔪"
90
91 # memo / pencil
92 assert emojis.apply_emojis(":memo:") == "📝"
93 assert emojis.apply_emojis(":pencil:") == "📝"
94
95 # uk / gb
96 assert emojis.apply_emojis(":uk:") == "🇬🇧"
97 assert emojis.apply_emojis(":gb:") == "🇬🇧"
98
99 # aliases embedded in text
100 assert emojis.apply_emojis("hello :thumbsup: world") == "hello 👍 world"
101 assert emojis.apply_emojis(":poop::boom:") == "💩💥"
102
103 # optional-group patterns: ':hand:' and ':raised_hand:' both map to ✋
104 assert emojis.apply_emojis(":hand:") == "✋"
105 assert emojis.apply_emojis(":raised_hand:") == "✋"
106
107 # runner / running
108 assert emojis.apply_emojis(":runner:") == "🏃"
109 assert emojis.apply_emojis(":running:") == "🏃"
110
111
112 def test_emojis_lookup_no_pattern_match():
113 """emojis: _lookup() returns the raw token when _EMOJI_PATTERN_LIST is
114 empty (defensive fallback -- return text branch)."""
115
116 # Ensure the engine is initialised first.
117 emojis.apply_emojis(":smile:")
118
119 original = emojis._EMOJI_PATTERN_LIST
120 emojis._EMOJI_PATTERN_LIST = []
121 try:
122 # With no patterns to match against, _lookup falls through to
123 # "return text", so the matched token is passed back unchanged.
124 result = emojis.apply_emojis(":smile:")
125 assert result == ":smile:"
126 finally:
127 emojis._EMOJI_PATTERN_LIST = original