Ejemplo n.º 1
0
 def test_load_yaml_file(self):
     resource_loader.init_yaml_loader()
     data = resource_loader.load_resource(
         os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.yml"),
         "settings")
     self.assertIn("foo", data)
     self.assertEqual("bar", data['foo'])
Ejemplo n.º 2
0
 def test_memoization_with_file(self):
     '''This test creates a temporary file with the help of the
     tempfile library and writes a simple key: value dictionary in it.
     It will then use that file to load the translations and, after having
     enabled memoization, try to access it, causing the file to be (hopefully)
     memoized. It will then _remove_ the temporary file and try to access again,
     asserting that an error is not raised, thus making sure the data is
     actually loaded from memory and not from disk access.'''
     memoization_file_name = 'memoize.en.yml'
     # create the file and write the data in it
     try:
         d = tempfile.TemporaryDirectory()
         tmp_dir_name = d.name
     except AttributeError:
         # we are running python2, use mkdtemp
         tmp_dir_name = tempfile.mkdtemp()
     fd = open('{}/{}'.format(tmp_dir_name, memoization_file_name), 'w')
     fd.write('en:\n  key: value')
     fd.close()
     # create the loader and pass the file to it
     resource_loader.init_yaml_loader()
     resource_loader.load_translation_file(memoization_file_name,
                                           tmp_dir_name)
     # try loading the value to make sure it's working
     self.assertEqual(t('memoize.key'), 'value')
     # now delete the file and directory
     # we are running python2, delete manually
     import shutil
     shutil.rmtree(tmp_dir_name)
     # test the translation again to make sure it's loaded from memory
     self.assertEqual(t('memoize.key'), 'value')
Ejemplo n.º 3
0
    def test_load_translation_file(self):
        resource_loader.init_yaml_loader()
        resource_loader.load_translation_file(
            "foo.en.yml", os.path.join(RESOURCE_FOLDER, "translations"))

        self.assertTrue(translations.has("foo.normal_key"))
        self.assertTrue(translations.has("foo.parent.nested_key"))
Ejemplo n.º 4
0
 def test_load_plural(self):
     resource_loader.init_yaml_loader()
     resource_loader.load_translation_file("foo.en.yml", os.path.join(RESOURCE_FOLDER, "translations"))
     self.assertTrue(translations.has("foo.mail_number"))
     translated_plural = translations.get("foo.mail_number")
     self.assertIsInstance(translated_plural, dict)
     self.assertEqual(translated_plural["zero"], "You do not have any mail.")
     self.assertEqual(translated_plural["one"], "You have a new mail.")
     self.assertEqual(translated_plural["many"], "You have %{count} new mails.")
Ejemplo n.º 5
0
 def test_register_yaml_loader(self):
     resource_loader.init_yaml_loader()
     with self.assertRaisesRegexp(I18nFileLoadError,
                                  "error loading file .*"):
         resource_loader.load_resource("foo.yml", "bar")
Ejemplo n.º 6
0
 def test_search_translation_yaml(self):
     resource_loader.init_yaml_loader()
     config.set('file_format', 'yml')
     resource_loader.search_translation('foo.normal_key')
     self.assertTrue(translations.has("foo.normal_key"))
Ejemplo n.º 7
0
    def test_load_translation_file(self):
        resource_loader.init_yaml_loader()
        resource_loader.load_translation_file("foo.en.yml", os.path.join(RESOURCE_FOLDER, "translations"))

        self.assertTrue(translations.has("foo.normal_key"))
        self.assertTrue(translations.has("foo.parent.nested_key"))
Ejemplo n.º 8
0
 def test_load_yaml_file(self):
     resource_loader.init_yaml_loader()
     data = resource_loader.load_resource(os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.yml"), "settings")
     self.assertIn("foo", data)
     self.assertEqual("bar", data['foo'])
Ejemplo n.º 9
0
 def test_register_yaml_loader(self):
     resource_loader.init_yaml_loader()
     with self.assertRaisesRegexp(I18nFileLoadError, "error loading file .*"):
         resource_loader.load_resource("foo.yml", "bar")
Ejemplo n.º 10
0
 def test_search_translation_yaml(self):
     resource_loader.init_yaml_loader()
     config.set('file_format', 'yml')
     resource_loader.search_translation('foo.normal_key')
     self.assertTrue(translations.has("foo.normal_key"))