Esempio n. 1
0
    def testReadJsonComesFromCache(self):
        """
        Do an initial read from JSON file, delete the file and verify that property reads still work because
        they are served from the cache
        """
        tmp_json = tempfile.NamedTemporaryFile(mode='w', prefix='example', suffix='_en.json', delete=False)
        fullname = tmp_json.name
        tmp_json.close()
        tmppath = os.path.dirname(fullname)
        name = os.path.basename(fullname)
        prefix = name.replace('_en.json', '')

        # make a copy of a properties file
        copyFile(os.path.join(self.resources_path, 'json_example_en.json'), fullname)

        # read a value from the properties file
        options = i18n.read_text_options(tmppath, prefix, "en", "attractAttention", "/")
        self.assertTrue(options, "attractAttention should be found")
        self.assertTrue(len(options) > 0, "attractAttention should have at least one option")

        # delete the temp file
        os.remove(fullname)

        # check read of different property from same file still works
        options = i18n.read_text_options(tmppath, prefix, "en", "goodbye", "/")
        self.assertTrue(options, "goodbye should be found")
        self.assertTrue(len(options) > 0, "goodbye should have at least one option")
Esempio n. 2
0
 def testLoadOptionsTextFileFrench(self):
     options = i18n.read_text_options(self.resources_path, "example", "fr")
     self.assertEqual(5, len(options))
Esempio n. 3
0
 def testLoadOptionsPropertyFileChinese(self):
     options = i18n.read_text_options(self.resources_path, "defaults", "zh", "attractAttention", "/")
     self.assertEqual(5, len(options))
Esempio n. 4
0
 def testLoadOptionsJsonFileFrench(self):
     options = i18n.read_text_options(self.resources_path, "json_example", "fr", "attractAttention", "/")
     self.assertEqual(5, len(options))
Esempio n. 5
0
 def testLoadOptionsTextFileChinese(self):
     options = i18n.read_text_options(self.resources_path, "example", "zh")
     self.assertEqual(5, len(options))