def test_getTagByKeyName(self): tags = localizr.getTagsFromTree(self.tree) # verify that non-existent key returns None result = localizr.getTagByKeyName(tags, 'doesnotexist') self.assertIsNone(result) # verify that returns correct key result = localizr.getTagByKeyName(tags, ('string', 'test_1')) self.assertEqual(result.attrib['name'], 'test_1') # verify that returns correct key when keys with same name tagsPlurals = localizr.getTagsFromTree(self.treePlurals) result = localizr.getTagByKeyName(tagsPlurals, ('string', 'same_key')) self.assertEqual(result.text, 'same key string') result = localizr.getTagByKeyName(tagsPlurals, ('plurals', 'same_key')) self.assertEqual(result.text, 'same key plurals')
def test_writeOutMissingStrings(self): # get tags from default tree so we know what to write out tags = localizr.getTagsFromTree(self.tree) # get the missing keys for each lang keys = localizr.getKeysFromTree(self.tree) missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path) # write out the files localizr.createOutputDir('./test/to_translate') localizr.writeMissingKeysToFiles(self.LANGS, tags, missing, './test/to_translate') # verify that no German strings exist os.chdir(self.cwd) self.assertFalse( os.path.exists('./test/to_translate/strings_to_trans-de.xml')) # verify that spanish strings seem correct os.chdir(self.cwd) self.assertTrue( os.path.exists('./test/to_translate/strings_to_trans-es.xml')) self.assertTrue( filecmp.cmp('./test/test_to_translate/strings_to_trans-es.xml', './test/to_translate/strings_to_trans-es.xml')) # verify that french strings seem correct os.chdir(self.cwd) self.assertTrue( os.path.exists('./test/to_translate/strings_to_trans-fr.xml')) self.assertTrue( filecmp.cmp('./test/test_to_translate/strings_to_trans-fr.xml', './test/to_translate/strings_to_trans-fr.xml')) # verify that traditional chinese strings seem correct os.chdir(self.cwd) self.assertTrue( os.path.exists('./test/to_translate/strings_to_trans-zh-rTW.xml')) self.assertTrue( filecmp.cmp('./test/test_to_translate/strings_to_trans-zh-rTW.xml', './test/to_translate/strings_to_trans-zh-rTW.xml'))
def test_writeOutMissingStrings(self): # get tags from default tree so we know what to write out tags = localizr.getTagsFromTree(self.tree) # get the missing keys for each lang keys = localizr.getKeysFromTree(self.tree) missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path) # write out the files localizr.createOutputDir('./test/to_translate') localizr.writeMissingKeysToFiles(self.LANGS, tags, missing, './test/to_translate') # verify that no German strings exist os.chdir(self.cwd) self.assertFalse(os.path.exists( './test/to_translate/strings_to_trans-de.xml')) # verify that spanish strings seem correct os.chdir(self.cwd) self.assertTrue(os.path.exists( './test/to_translate/strings_to_trans-es.xml')) self.assertTrue(filecmp.cmp( './test/test_to_translate/strings_to_trans-es.xml', './test/to_translate/strings_to_trans-es.xml')) # verify that french strings seem correct os.chdir(self.cwd) self.assertTrue(os.path.exists( './test/to_translate/strings_to_trans-fr.xml')) self.assertTrue(filecmp.cmp( './test/test_to_translate/strings_to_trans-fr.xml', './test/to_translate/strings_to_trans-fr.xml')) # verify that traditional chinese strings seem correct os.chdir(self.cwd) self.assertTrue(os.path.exists( './test/to_translate/strings_to_trans-zh-rTW.xml')) self.assertTrue(filecmp.cmp( './test/test_to_translate/strings_to_trans-zh-rTW.xml', './test/to_translate/strings_to_trans-zh-rTW.xml'))
def test_getTagsFromTree(self): tags = localizr.getTagsFromTree(self.tree) # should return all seven tags self.assertEqual(len(tags), 8)