test_emojione.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8; -*-
  2. from __future__ import unicode_literals
  3. from unittest import TestCase
  4. from emojipy import Emoji
  5. class EmojipyTest(TestCase):
  6. def setUp(self):
  7. pass
  8. def test_unicode_to_image(self):
  9. txt = 'Hello world! 😄 :smile:'
  10. expected = """Hello world! <img class="emojione" alt="😄" src="https://cdn.jsdelivr.net/emojione/assets/png/1f604.png%s"/> :smile:""" %\
  11. Emoji.cache_bust_param
  12. self.assertEqual(Emoji.unicode_to_image(txt), expected)
  13. def test_shortcode_to_image(self):
  14. txt = 'Hello world! 😄 :smile:'
  15. expected = """Hello world! 😄 <img class="emojione" alt="😄" src="https://cdn.jsdelivr.net/emojione/assets/png/1f604.png%s"/>""" %\
  16. Emoji.cache_bust_param
  17. self.assertEqual(Emoji.shortcode_to_image(txt), expected)
  18. Emoji.unicode_alt = False
  19. expected = """Hello world! 😄 <img class="emojione" alt=":smile:" src="https://cdn.jsdelivr.net/emojione/assets/png/1f604.png%s"/>""" %\
  20. Emoji.cache_bust_param
  21. self.assertEqual(Emoji.shortcode_to_image(txt), expected)
  22. Emoji.unicode_alt = True
  23. def test_shortcode_to_ascii(self):
  24. txt = 'Hello world! 😄 :slight_smile:'
  25. expected = [
  26. 'Hello world! 😄 :]',
  27. 'Hello world! 😄 :-)',
  28. 'Hello world! 😄 =)',
  29. 'Hello world! 😄 :)',
  30. 'Hello world! 😄 =]'
  31. ]
  32. output = Emoji.shortcode_to_ascii(txt)
  33. self.assertIn(output, expected)