Ejemplo n.º 1
0
 def test_get_phrase_speed(self):
     import time as t
     localePhrases = phrase.set_locale()
     NUM_CALLS = 1000
     start = t.time()
     for _ in range(NUM_CALLS):
         phrase.get_phrase(*(localePhrases.phrases.keys()))
     elapsed = t.time()-start
     avg = elapsed/NUM_CALLS
     # Shouldn't hang for more than a millisecond on average
     self.assertTrue(avg*1000 < 1, 
         "Average phrase.get_phrase speed should be less than a millisecond")  
Ejemplo n.º 2
0
 def test_phrases_composition(self):
     localePhrases = phrase.set_locale("en_us")
     for phraseType, phraseList in localePhrases.phrases.items():
         self.assertIsInstance(phraseType, str, 
             "Phrase dicts must have strings as keys")
         self.assertIsInstance(phraseList, list, 
             "Phrase dicts must have lists of strings as values")
         for item in phraseList:
             self.assertIsInstance(item, str, 
                 "Phrase dicts must have lists of strings as values")
             self.assertEqual(item.strip(), item, 
                 "Phrases should not contain leading or trailing spaces")
Ejemplo n.º 3
0
 def test_get_phrase_with_invalid_input(self):
     _ = phrase.set_locale()
     self.assertEqual(phrase.get_phrase('test invalid input'), 
         "test invalid input", "phrase.get_phrase() should print invalid keys")
Ejemplo n.º 4
0
 def test_get_phrase_with_multiple_invalid_inputs(self):
     _ = phrase.set_locale()
     self.assertEqual(phrase.get_phrase('mult!ple', 'inv@lid', '!nputs'), "mult!ple inv@lid !nputs", 
         "phrase.get_phrase() should join invalid string keys with spaces")
Ejemplo n.º 5
0
 def test_get_phrase_with_multiple_inputs(self):
     _ = phrase.set_locale()
     self.assertNotEqual(phrase.get_phrase('hello', 'bye'), "")
Ejemplo n.º 6
0
 def test_get_phrase(self):
     _ = phrase.set_locale()
     self.assertNotEqual(phrase.get_phrase('hello'), "")
Ejemplo n.º 7
0
 def test_set_locale_to_unsupported_locale(self):
     localeModule = phrase.set_locale("na_NA")
     self.assertIsInstance(localeModule, ModuleType, 
         "phrase.set_locale() should set locale to default locale if unsupported locale is given")
     self.assertIsNotNone(localeModule.phrases, 
         "Locale module should have a phrases dict")
Ejemplo n.º 8
0
 def test_set_locale_to_supported_locale(self):
     localeModule = phrase.set_locale("en_gb")
     self.assertIsInstance(localeModule, ModuleType)
     self.assertIsNotNone(localeModule.phrases, 
         "Locale module should have a phrases dict")
Ejemplo n.º 9
0
 def test_set_locale_to_default_locale(self):
     localeModule = phrase.set_locale()
     self.assertIsInstance(localeModule, ModuleType, 
         "phrase.set_locale() should have a default locale")
     self.assertIsNotNone(localeModule.phrases, 
         "Locale module should have a phrases dict")