test_conversion.py 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8; -*-
  2. from __future__ import unicode_literals
  3. from unittest import TestCase
  4. from emojipy import Emoji
  5. class ConversionTests(TestCase):
  6. """
  7. Test possible conversions from different kinds of input with
  8. unicode or shortname at different places
  9. """
  10. def setUp(self):
  11. self.emoji = Emoji
  12. self.emoji.sprites = False
  13. self.cache_bust_param = Emoji.cache_bust_param
  14. def test_single_unicode_char(self):
  15. unicode = '🐌'
  16. shortcode = ':snail:'
  17. image = '<img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>'
  18. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  19. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  20. def test_emoji_inside_sentence(self):
  21. unicode = 'The 🐌 is Emoji One\'s official mascot.'
  22. shortcode = 'The :snail: is Emoji One\'s official mascot.'
  23. image = 'The <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/> is Emoji One\'s official mascot.'
  24. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  25. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  26. def test_emoji_inside_sentence_with_comma(self):
  27. unicode = 'The 🐌, is Emoji One\'s official mascot.'
  28. shortcode = 'The :snail:, is Emoji One\'s official mascot.'
  29. image = 'The <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>, is Emoji One\'s official mascot.'
  30. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  31. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  32. def test_emoji_at_start_of_sentence(self):
  33. unicode = '🐌 mail.'
  34. shortcode = ':snail: mail.'
  35. image = '<img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/> mail.'
  36. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  37. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  38. def test_emoji_at_start_of_sentence_with_apostrophe(self):
  39. unicode = '🐌\'s are cool!'
  40. shortcode = ':snail:\'s are cool!'
  41. image = '<img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>\'s are cool!'
  42. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  43. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  44. def test_emoji_at_end_of_sentence(self):
  45. unicode = 'Emoji One\'s official mascot is 🐌.'
  46. shortcode = 'Emoji One\'s official mascot is :snail:.'
  47. image = 'Emoji One\'s official mascot is <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>.'
  48. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  49. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  50. def test_emoji_at_end_of_sentence_with_alternate_punctuation(self):
  51. unicode = 'Emoji One\'s official mascot is 🐌!'
  52. shortcode = 'Emoji One\'s official mascot is :snail:!'
  53. image = 'Emoji One\'s official mascot is <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>!'
  54. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  55. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  56. def test_emoji_at_end_of_sentence_with_preceeding_colon(self):
  57. unicode = 'Emoji One\'s official mascot: 🐌'
  58. shortcode = 'Emoji One\'s official mascot: :snail:'
  59. image = 'Emoji One\'s official mascot: <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png'+self.cache_bust_param+'"/>'
  60. self.assertEqual(Emoji.unicode_to_image(unicode), image)
  61. self.assertEqual(Emoji.shortcode_to_image(shortcode), image)
  62. def test_emoji_inside_img_tag(self):
  63. unicode = 'The <img class="emojione" alt="🐌" src="https://cdn.jsdelivr.net/emojione/assets/png/1f40c.png" /> is Emoji One\'s official mascot.';
  64. self.assertEqual(Emoji.unicode_to_image(unicode), unicode)
  65. self.assertEqual(Emoji.shortcode_to_image(unicode), unicode)
  66. def test_emoji_inside_object_tag(self):
  67. unicode = 'The <object class="emojione" data="//cdn.jsdelivr.net/emojione/assets/svg/1f40c.svg" type="image/svg+xml" standby="🐌">🐌</object> is Emoji One\'s official mascot'
  68. self.assertEqual(Emoji.unicode_to_image(unicode), unicode)
  69. self.assertEqual(Emoji.shortcode_to_image(unicode), unicode)