def testStringer(self): stringer.loaddictionary(ENGLISH_TEST_PATH) _ = stringer.Stringer self.assertEqual(_("_dogs and cats blah blah blah"), "_dogs and cats blah blah blah", "Unmatched keys returned as is.") self.assertEqual(_("_hello world"), "hello world", "Direct translation works.") self.assertEqual(_("_ACTOR hits TARGET"), "{actor} hits {target}", "Formatting characters are not munged.") self.assertEqual(_("_ACTOR[NAME] hits TARGET[NAME]"), "{actor[name]} hits {target[name]}", "Formatting characters are not munged.") self.assertEqual(_("_ACTOR.NAME hits TARGET.NAME"), "{actor.name} hits {target.name}.", "Formatting characters are not munged.") self.assertEqual(_("_ACTOR hits TARGET").f(actor='chicken', target='cat'), "chicken hits cat", "Formatting is performed.")
def testMultipleDictionaries(self): stringer.loaddictionary(ENGLISH_TEST_PATH) stringer.loaddictionary(DEUTSCH_TEST_PATH) _ = stringer.Stringer self.assertEqual(_("_hello world"), "hello world", "'en' is our default language key.") stringer.setkey("de") self.assertEqual(_("_hello world"), "Hallo Welt", "Can change language keys and keep more than one dictionary in memory.")
def testLoadDictionary(self): stringer.loaddictionary(ENGLISH_TEST_PATH) self.assertEqual(len(stringer.DICTIONARIES), 1, "1 Dictionary should have been loaded.")