PageRenderTime 118ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/src/jmc/tests/lang.py

https://github.com/dax/jmc
Python | 219 lines | 146 code | 33 blank | 40 comment | 1 complexity | f9269baf630d4801ae11ff38aec8985c MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- coding: utf-8 -*-
  2. ##
  3. ## test_lang.py
  4. ## Login : David Rousselie <david.rousselie@happycoders.org>
  5. ## Started on Fri May 20 10:46:58 2005
  6. ## $Id: test_lang.py,v 1.1 2005/07/11 20:39:31 dax Exp $
  7. ##
  8. ## Copyright (C) 2005
  9. ## This program is free software; you can redistribute it and/or modify
  10. ## it under the terms of the GNU General Public License as published by
  11. ## the Free Software Foundation; either version 2 of the License, or
  12. ## (at your option) any later version.
  13. ##
  14. ## This program is distributed in the hope that it will be useful,
  15. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ## GNU General Public License for more details.
  18. ##
  19. ## You should have received a copy of the GNU General Public License
  20. ## along with this program; if not, write to the Free Software
  21. ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. ##
  23. import unittest
  24. import jcl.tests.lang
  25. import jmc.lang
  26. from jmc.lang import Lang
  27. from pyxmpp.iq import Iq
  28. class Lang_TestCase(unittest.TestCase):
  29. def setUp(self):
  30. self.lang = Lang()
  31. def tearDown(self):
  32. self.lang = None
  33. def test_get_lang_class_exist(self):
  34. lang_class = self.lang.get_lang_class("fr")
  35. self.assertEquals(lang_class, Lang.fr)
  36. def test_get_lang_class_not_exist(self):
  37. lang_class = self.lang.get_lang_class("not_exist")
  38. self.assertEquals(lang_class, Lang.en)
  39. def test_get_lang_class_long_code(self):
  40. lang_class = self.lang.get_lang_class("fr_FR")
  41. self.assertEquals(lang_class, Lang.fr)
  42. def test_get_lang_from_node(self):
  43. iq = Iq(from_jid = "test@test.com", \
  44. to_jid = "test2@test.com", \
  45. stanza_type = "get")
  46. iq_node = iq.get_node()
  47. iq_node.setLang("fr")
  48. lang = self.lang.get_lang_from_node(iq_node)
  49. self.assertEquals(lang, "fr")
  50. def test_get_lang_class_from_node(self):
  51. iq = Iq(from_jid = "test@test.com", \
  52. to_jid = "test2@test.com", \
  53. stanza_type = "get")
  54. iq_node = iq.get_node()
  55. iq_node.setLang("fr")
  56. lang = self.lang.get_lang_class_from_node(iq_node)
  57. self.assertEquals(lang, Lang.fr)
  58. class Language_TestCase(jcl.tests.lang.Language_TestCase):
  59. """Test language classes"""
  60. def setUp(self):
  61. """must define self.lang_class. Lang.en is default"""
  62. self.lang_class = Lang.en
  63. def test_strings(self):
  64. jcl.tests.lang.Language_TestCase.test_strings(self)
  65. self.assertNotEquals(self.lang_class.field_login, None)
  66. self.assertNotEquals(self.lang_class.field_host, None)
  67. self.assertNotEquals(self.lang_class.field_port, None)
  68. self.assertNotEquals(self.lang_class.field_ssl, None)
  69. self.assertNotEquals(self.lang_class.field_tls, None)
  70. self.assertNotEquals(self.lang_class.field_store_password, None)
  71. self.assertNotEquals(self.lang_class.field_live_email_only, None)
  72. self.assertNotEquals(self.lang_class.field_interval, None)
  73. self.assertNotEquals(self.lang_class.field_mailbox, None)
  74. self.assertNotEquals(self.lang_class.field_action_1, None)
  75. self.assertNotEquals(self.lang_class.field_chat_action_1, None)
  76. self.assertNotEquals(self.lang_class.field_online_action_1, None)
  77. self.assertNotEquals(self.lang_class.field_away_action_1, None)
  78. self.assertNotEquals(self.lang_class.field_xa_action_1, None)
  79. self.assertNotEquals(self.lang_class.field_dnd_action_1, None)
  80. self.assertNotEquals(self.lang_class.field_offline_action_1, None)
  81. self.assertNotEquals(self.lang_class.field_action_2, None)
  82. self.assertNotEquals(self.lang_class.field_chat_action_2, None)
  83. self.assertNotEquals(self.lang_class.field_online_action_2, None)
  84. self.assertNotEquals(self.lang_class.field_away_action_2, None)
  85. self.assertNotEquals(self.lang_class.field_xa_action_2, None)
  86. self.assertNotEquals(self.lang_class.field_dnd_action_2, None)
  87. self.assertNotEquals(self.lang_class.field_offline_action_2, None)
  88. self.assertNotEquals(self.lang_class.field_default_from, None)
  89. self.assertNotEquals(self.lang_class.field_default_account, None)
  90. self.assertNotEquals(self.lang_class.new_mail_subject, None)
  91. self.assertNotEquals(self.lang_class.new_digest_subject, None)
  92. self.assertNotEquals(self.lang_class.type_imap_name, None)
  93. self.assertNotEquals(self.lang_class.type_pop3_name, None)
  94. self.assertNotEquals(self.lang_class.type_smtp_name, None)
  95. self.assertNotEquals(self.lang_class.send_mail_error_no_to_header_subject,
  96. None)
  97. self.assertNotEquals(self.lang_class.send_mail_error_no_to_header_body,
  98. None)
  99. self.assertNotEquals(self.lang_class.send_mail_ok_subject, None)
  100. self.assertNotEquals(self.lang_class.send_mail_ok_body, None)
  101. self.assertNotEquals(self.lang_class.help_message_body, None)
  102. self.assertNotEquals(self.lang_class.command_force_check, None)
  103. self.assertNotEquals(self.lang_class.command_force_check_1_description, None)
  104. self.assertNotEquals(self.lang_class.command_get_email, None)
  105. self.assertNotEquals(self.lang_class.command_get_email_1_description, None)
  106. self.assertNotEquals(self.lang_class.command_get_email_2_description, None)
  107. self.assertNotEquals(self.lang_class.field_email_subject, None)
  108. self.assertNotEquals(self.lang_class.mail_subject, None)
  109. self.assertNotEquals(self.lang_class.field_select_more_emails, None)
  110. class SubLanguage_TestCase(Language_TestCase):
  111. """
  112. Test translation fallback mecanism :
  113. jmc.lang.Lang.{translation class} -> jmc.lang.Lang.en -> jcl.lang.Lang.{translation class} -> jcl.lang.Lang.en
  114. """
  115. def test_fallback_jmc_en(self):
  116. """
  117. if a translation does not exist in JMC. It falls back to the English
  118. translation.
  119. """
  120. value = self.lang_class.register_title
  121. del self.lang_class.register_title
  122. self.assertEquals(self.lang_class.register_title,
  123. jmc.lang.Lang.en.register_title)
  124. self.lang_class.register_title = value
  125. def test_fallback_jcl_current(self):
  126. """
  127. if an attribut does not exist in JMC translation class nor in JMC
  128. English class, it falls back to the current language in JCL.
  129. """
  130. lang_class_value = self.lang_class.register_title
  131. jmc_lang_en_value = jmc.lang.Lang.en.register_title
  132. del self.lang_class.register_title
  133. del jmc.lang.Lang.en.register_title
  134. self.assertEquals(\
  135. self.lang_class.register_title,
  136. jcl.lang.Lang.__dict__[self.lang_class.__name__].register_title)
  137. jmc.lang.Lang.en.register_title = jmc_lang_en_value
  138. self.lang_class.register_title = lang_class_value
  139. def test_fallback_jcl_en(self):
  140. """
  141. if an attribut does not exist in JMC and is not translated in JCL,
  142. it falls back to English in JCL
  143. """
  144. lang_class_value = self.lang_class.register_title
  145. jmc_lang_en_value = jmc.lang.Lang.en.register_title
  146. jcl_lang_class_value = jcl.lang.Lang.__dict__[self.lang_class.__name__].register_title
  147. del self.lang_class.register_title
  148. del jmc.lang.Lang.en.register_title
  149. del jcl.lang.Lang.__dict__[self.lang_class.__name__].register_title
  150. self.assertEquals(\
  151. self.lang_class.register_title,
  152. jcl.lang.Lang.en.register_title)
  153. jcl.lang.Lang.__dict__[self.lang_class.__name__].register_title = jcl_lang_class_value
  154. jmc.lang.Lang.en.register_title = jmc_lang_en_value
  155. self.lang_class.register_title = lang_class_value
  156. class Language_fr_TestCase(SubLanguage_TestCase):
  157. def setUp(self):
  158. self.lang_class = Lang.fr
  159. class Language_nl_TestCase(Language_TestCase):
  160. def setUp(self):
  161. self.lang_class = Lang.nl
  162. class Language_es_TestCase(Language_TestCase):
  163. def setUp(self):
  164. self.lang_class = Lang.es
  165. class Language_pl_TestCase(Language_TestCase):
  166. def setUp(self):
  167. self.lang_class = Lang.pl
  168. class Language_cs_TestCase(Language_TestCase):
  169. def setUp(self):
  170. self.lang_class = Lang.cs
  171. class Language_ru_TestCase(Language_TestCase):
  172. def setUp(self):
  173. self.lang_class = Lang.ru
  174. def suite():
  175. suite = unittest.TestSuite()
  176. suite.addTest(unittest.makeSuite(Lang_TestCase, 'test'))
  177. suite.addTest(unittest.makeSuite(Language_TestCase, 'test'))
  178. suite.addTest(unittest.makeSuite(Language_fr_TestCase, 'test'))
  179. suite.addTest(unittest.makeSuite(Language_nl_TestCase, 'test'))
  180. suite.addTest(unittest.makeSuite(Language_es_TestCase, 'test'))
  181. suite.addTest(unittest.makeSuite(Language_pl_TestCase, 'test'))
  182. suite.addTest(unittest.makeSuite(Language_cs_TestCase, 'test'))
  183. suite.addTest(unittest.makeSuite(Language_ru_TestCase, 'test'))
  184. return suite
  185. if __name__ == '__main__':
  186. unittest.main(defaultTest='suite')