-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_emojify
executable file
·65 lines (44 loc) · 4.89 KB
/
test_emojify
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
63
64
65
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
test_emojify.py
Test emojify.py for basic functionality
"""
import sys
import platform
import unittest
from emojify import encode_string, EMOTICONS, EMOJIS
__author__ = "Chris Rands"
__copyright__ = "Copyright (c) 2019, Chris Rands"
# Test 1
INPUT1 = "print('hello world')\n"
OUTPUT1_EMOTICON = "exec(\"\".join(map(chr,[int(\"\".join(str({':(': 4,\n ':)': 0,\n ':/': 7,\n ':D': 1,\n ':P': 2,\n ':S': 3,\n ':{': 8,\n ';)': 9,\n '=)': 5,\n '=/': 6}[i]) for i in x.split())) for x in\n\":D :D :P :D :D :( :D :) =) :D :D :) :D :D =/ :( :) :S ;) :D :) \\\n:( :D :) :D :D :) :{ :D :) :{ :D :D :D :S :P :D :D ;) :D :D :D \\\n :D :D :( :D :) :{ :D :) :) :S ;) :( :D :D :)\"\n.split(\" \")])))\n"
OUTPUT1_EMOJI = "exec(\"\".join(map(chr,[int(\"\".join(str({'😀': 0, '😁': 3, '😂': 6, '😃': 1, '😄': 2, '😅': 4, '😉': 7, '😊': 8, '😛': 9, '🤣': 5}[i]) for i in x.split())) for x in\n\"😃 😃 😄 😃 😃 😅 😃 😀 🤣 😃 😃 😀 😃 😃 😂 😅 😀 😁 😛 😃 😀 😅 😃 😀 😃 😃 😀 😊 😃 😀 \\\n😊 😃 😃 😃 😁 😄 😃 😃 😛 😃 😃 😃 😃 😃 😅 😃 😀 😊 😃 😀 😀 😁 😛 😅 😃 😃 😀\"\n.split(\" \")])))\n"
# Test 2
INPUT2 = "print('hello world')\ndef add(n1,n2):\n return n1 + n2\nprint('4 + 4 = {}'.format(add(4,4)))\n"
OUTPUT2_EMOTICON = "exec(\"\".join(map(chr,[int(\"\".join(str({':(': 4,\n ':)': 0,\n ':/': 7,\n ':D': 1,\n ':P': 2,\n ':S': 3,\n ':{': 8,\n ';)': 9,\n '=)': 5,\n '=/': 6}[i]) for i in x.split())) for x in\n\":D :D :P :D :D :( :D :) =) :D :D :) :D :D =/ :( :) :S ;) :D :) \\\n:( :D :) :D :D :) :{ :D :) :{ :D :D :D :S :P :D :D ;) :D :D :D \\\n :D :D :( :D :) :{ :D :) :) :S ;) :( :D :D :) :D :) :) :D :) :D\\\n :D :) :P :S :P ;) :/ :D :) :) :D :) :) :( :) :D :D :) :( ;) \\\n:( :( :D :D :) =) :) :( :D =) :{ :D :) :S :P :S :P :S :P :S :\\\nP :D :D :( :D :) :D :D :D =/ :D :D :/ :D :D :( :D :D :) :S :P \\\n:D :D :) :( ;) :S :P :( :S :S :P :D :D :) =) :) :D :) :D :D :P\\\n :D :D :( :D :) =) :D :D :) :D :D =/ :( :) :S ;) =) :P :S :P \\\n:( :S :S :P =) :P :S :P =/ :D :S :P :D :P :S :D :P =) :S ;) :\\\n( =/ :D :) :P :D :D :D :D :D :( :D :) ;) ;) :/ :D :D =/ :( :) \\\n;) :/ :D :) :) :D :) :) :( :) =) :P :( :( =) :P :( :D :( :D :\\\n( :D :D :)\"\n.split(\" \")])))\n"
OUTPUT2_EMOJI = "exec(\"\".join(map(chr,[int(\"\".join(str({'😀': 0, '😁': 3, '😂': 6, '😃': 1, '😄': 2, '😅': 4, '😉': 7, '😊': 8, '😛': 9, '🤣': 5}[i]) for i in x.split())) for x in\n\"😃 😃 😄 😃 😃 😅 😃 😀 🤣 😃 😃 😀 😃 😃 😂 😅 😀 😁 😛 😃 😀 😅 😃 😀 😃 😃 😀 😊 😃 😀 \\\n😊 😃 😃 😃 😁 😄 😃 😃 😛 😃 😃 😃 😃 😃 😅 😃 😀 😊 😃 😀 😀 😁 😛 😅 😃 😃 😀 😃 😀 😀\\\n 😃 😀 😃 😃 😀 😄 😁 😄 😛 😉 😃 😀 😀 😃 😀 😀 😅 😀 😃 😃 😀 😅 😛 😅 😅 😃 😃 😀 🤣\\\n 😀 😅 😃 🤣 😊 😃 😀 😁 😄 😁 😄 😁 😄 😁 😄 😃 😃 😅 😃 😀 😃 😃 😃 😂 😃 😃 😉 😃 😃\\\n 😅 😃 😃 😀 😁 😄 😃 😃 😀 😅 😛 😁 😄 😅 😁 😁 😄 😃 😃 😀 🤣 😀 😃 😀 😃 😃 😄 😃 😃\\\n 😅 😃 😀 🤣 😃 😃 😀 😃 😃 😂 😅 😀 😁 😛 🤣 😄 😁 😄 😅 😁 😁 😄 🤣 😄 😁 😄 😂 😃 \\\n😁 😄 😃 😄 😁 😃 😄 🤣 😁 😛 😅 😂 😃 😀 😄 😃 😃 😃 😃 😃 😅 😃 😀 😛 😛 😉 😃 😃 😂 😅\\\n 😀 😛 😉 😃 😀 😀 😃 😀 😀 😅 😀 🤣 😄 😅 😅 🤣 😄 😅 😃 😅 😃 😅 😃 😃 😀\"\n.split(\" \")])))\n"
class TestFunctions(unittest.TestCase):
"""Unit tests"""
# TODO: expand testing
def test_encode_string1_emoticon(self):
"""First test emoticon"""
self.assertEqual(encode_string(INPUT1, EMOTICONS), OUTPUT1_EMOTICON)
def test_encode_string1_emoji(self):
"""First test emoji"""
self.assertEqual(encode_string(INPUT1, EMOJIS), OUTPUT1_EMOJI)
def test_encode_string2_emoticon(self):
"""Second test emoticon"""
self.assertEqual(encode_string(INPUT2, EMOTICONS), OUTPUT2_EMOTICON)
def test_encode_string2_emoji(self):
"""Second test emoji"""
self.assertEqual(encode_string(INPUT2, EMOJIS), OUTPUT2_EMOJI)
def main():
"""Run unit tests"""
if sys.version_info < (3, 6):
raise SystemExit("Unit tests only implemented for Python 3.6+")
if platform.python_implementation() != "CPython":
raise SystemExit("Unit tests only implemented for CPython")
unittest.main()
if __name__ == "__main__":
main()